1
0
mirror of synced 2026-10-24 23:46:11 +08:00

Compare commits

..

66 Commits

Author SHA1 Message Date
6tail
fc0a6291d1 v1.2.6 新增治水、分饼、耕田、得金、日禄;新增时辰LunarTime;新增获取当天的所有时辰。 2021-10-13 22:26:11 +08:00
6tail
2694429549 v1.2.5 修复公元0至4年转阴历错误的问题。 2021-09-17 22:09:07 +08:00
6tail
012649009a v1.2.4 修复闰冬月、闰腊月的问题;修复日历不准的问题;修复物候错误;大运、小运、流年支持自定义轮数。 2021-09-13 22:21:14 +08:00
6tail
c93031cc28 修复闰冬月、闰腊月的问题;修复日历不准的问题;修复物候错误;大运、小运、流年支持自定义轮数。 2021-09-13 15:41:49 +08:00
6tail
d26313d2e3 init from v1.2.3 2021-06-01 21:52:15 +08:00
6tail
d65f6852e9 v1.2.3 修复除夕错误;代码优化。 2021-06-01 21:38:30 +08:00
6tail
dffee267c0 v1.2.2 修正2016年国庆节数据;删除5月23日世界读书日;修复v1.2.0和v1.2.1的重大bug。 2021-05-23 14:20:17 +08:00
6tail
5a5b0da7ab v1.2.1 优化Calendar 2021-04-14 22:17:53 +08:00
6tail
36117fdd94 Merge branch 'v1.1.0-SNAPSHOT' 2021-04-14 22:12:37 +08:00
6tail
2821cda010 v1.2.0 支持0001到9999年。 2021-04-11 21:16:37 +08:00
6tail
358cc7546c Merge branch 'v1.1.0-SNAPSHOT' 2021-04-11 21:14:24 +08:00
6tail
513084bde2 v1.1.18 更新农历纪念日;新增六曜、物候。 2021-01-15 22:21:25 +08:00
6tail
df6d310b8b Merge branch 'v1.1.0-SNAPSHOT' 2021-01-15 22:13:56 +08:00
6tail
d9dcbc4e2a v1.1.17 修复星座错误;新增数九、三伏。 2021-01-06 10:27:03 +08:00
6tail
85cf35f945 Merge branch 'v1.1.0-SNAPSHOT' 2021-01-06 10:24:02 +08:00
6tail
2eb2b508ee v1.1.16 八字增加可选流派(1晚子时日柱算明天,2晚子时日柱算当天,默认2)。 2020-12-17 23:06:10 +08:00
6tail
04195c201b Merge branch 'v1.1.0-SNAPSHOT' 2020-12-17 23:03:49 +08:00
6tail
cbab78d641 v1.1.15 修复八字流年计算错误。 2020-11-27 13:08:34 +08:00
6tail
a44ced263d Merge branch 'v1.1.0-SNAPSHOT' 2020-11-27 13:06:45 +08:00
6tail
a235e076db v1.1.14 修复长生十二神的错误。 2020-11-26 19:38:19 +08:00
6tail
4995e3f9d0 Merge branch 'v1.1.0-SNAPSHOT' 2020-11-26 19:36:20 +08:00
6tail
316e9b7b88 v1.1.13 法定假日更新至2021年底。 2020-11-25 22:45:58 +08:00
6tail
b220249cd7 Merge branch 'v1.1.0-SNAPSHOT' 2020-11-25 22:43:54 +08:00
6tail
954c841944 v1.1.12 修复节日计算错误。 2020-11-19 15:12:04 +08:00
6tail
1cff6441f7 Merge branch 'v1.1.0-SNAPSHOT' 2020-11-19 15:07:14 +08:00
6tail
12a4bb0efa v1.1.11 新增旬、旬空(空亡)。 2020-11-19 12:46:41 +08:00
6tail
6abe5ae1a2 Merge branch 'v1.1.0-SNAPSHOT' 2020-11-19 12:44:14 +08:00
6tail
85d56e5c3b v1.1.10 新增可自定义节假日数据;新增阳历日期按工作日推移。 2020-10-30 12:57:30 +08:00
6tail
b7fac53a81 Merge branch 'v1.1.0-SNAPSHOT' 2020-10-30 12:54:50 +08:00
6tail
10beaefd34 v1.1.9 修复八字排盘流年干支错误。 2020-10-25 13:17:17 +08:00
6tail
f1be26456d Merge branch 'v1.1.0-SNAPSHOT' 2020-10-25 13:09:30 +08:00
6tail
df6119c19e v1.1.8 修复计算精度问题。 2020-10-25 00:06:18 +08:00
6tail
c7cd454f2d Merge branch 'v1.1.0-SNAPSHOT' 2020-10-25 00:04:55 +08:00
6tail
392ac5b00a v1.1.7 修复值月九星数组下标越界的问题。 2020-10-17 20:05:02 +08:00
6tail
9ec735cd4b Merge branch 'v1.1.0-SNAPSHOT' 2020-10-17 20:03:48 +08:00
6tail
bd18254834 v1.1.6 修复阳历年12月底获取下一节气为空的问题。 2020-10-16 09:54:06 +08:00
6tail
28dbf8f45f Merge branch 'v1.1.0-SNAPSHOT' 2020-10-16 09:51:54 +08:00
6tail
cc2bbb5049 v1.1.5 修复立春至正月初一之间八字年月柱错误的问题;新增支持农历日期的推移。 2020-10-15 19:30:43 +08:00
6tail
9bb808da35 Merge branch 'v1.1.0-SNAPSHOT' 2020-10-15 19:14:57 +08:00
6tail
60634d7cd8 v1.1.4 增加获取节气名、上一气令、下一气令、当天节气、当天节令、当天气令的方法;节气对象增加判断是节令还是气令的方法。 2020-10-12 22:58:35 +08:00
6tail
fba9a85135 Merge branch 'v1.1.0-SNAPSHOT' 2020-10-12 22:55:46 +08:00
6tail
64fc022ab4 v1.1.3 节气表新增农历上年末的大雪;修复年初获取上一节令返回null的问题。 2020-09-18 19:02:41 +08:00
6tail
6028aefbf2 Merge branch 'v1.1.0-SNAPSHOT' 2020-09-18 19:00:39 +08:00
6tail
b2a8ceba95 v1.1.2 新增临近节气;新增八字起运、大运、流年、小运、流月。 2020-08-31 09:48:47 +08:00
6tail
5ca73f4e1c v1.1.2 新增临近节气;新增八字起运、大运、流年、小运、流月。 2020-08-31 09:48:02 +08:00
6tail
5fb3e4351c v1.1.2 新增临近节气;新增八字起运、大运、流年、小运、流月。 2020-08-31 09:47:35 +08:00
6tail
7ec5533187 Merge branch 'v1.1.0-SNAPSHOT' 2020-07-29 11:44:45 +08:00
6tail
24ab60dd50 Merge branch 'v1.1.0-SNAPSHOT' 2020-07-28 23:15:46 +08:00
6tail
a2e72f43f2 Merge branch 'v1.1.0-SNAPSHOT' 2020-07-27 23:29:10 +08:00
6tail
5a403ab55b Merge branch 'v1.1.0-SNAPSHOT' 2020-07-22 23:26:16 +08:00
6tail
f4884fd78f v1.1.1 2020-07-22 16:25:18 +08:00
6tail
8e02850b0b Merge branch 'v1.1.0-SNAPSHOT' 2020-07-22 16:05:26 +08:00
6tail
fd110cd004 Merge branch 'v1.1.0-SNAPSHOT' 2020-07-17 12:06:48 +08:00
6tail
83ee6e2565 Merge branch 'v1.1.0-SNAPSHOT' 2020-07-16 17:38:44 +08:00
6tail
99347bf757 Merge branch 'v1.1.0-SNAPSHOT' 2020-07-15 19:05:48 +08:00
6tail
21bd8acfdd Merge branch 'v1.1.0-SNAPSHOT' 2020-07-15 16:56:43 +08:00
6tail
d837a07d31 Merge branch 'v1.1.0-SNAPSHOT' 2020-07-09 22:05:45 +08:00
6tail
152ab075ba Merge branch 'v1.1.0-SNAPSHOT' 2020-07-09 17:10:04 +08:00
6tail
64ef6f2f9d Merge branch 'v1.1.0-SNAPSHOT' 2020-06-28 21:39:12 +08:00
6tail
f4cdd7d3db Merge branch 'v1.1.0-SNAPSHOT' 2020-06-22 15:35:00 +08:00
6tail
cbdded954b Merge branch 'v1.1.0-SNAPSHOT' 2020-05-30 10:25:02 +08:00
6tail
5b50389b27 Merge remote-tracking branch 'remotes/origin/v1.1.0-SNAPSHOT' 2020-05-28 22:22:05 +08:00
6tail
dcbe964822 Merge remote-tracking branch 'remotes/origin/v1.1.0-SNAPSHOT' 2020-05-27 00:08:39 +08:00
6tail
52ebc9d678 修复时辰天干计算错误,支持早子时和晚子时 2020-05-26 23:12:19 +08:00
6tail
b0b7f7fa8e Merge remote-tracking branch 'remotes/origin/v1.1.0-SNAPSHOT' 2020-05-26 23:07:59 +08:00
6tail
f6c0e37ff5 新增每日吉神宜趋、凶煞宜忌 2020-05-26 18:11:02 +08:00
22 changed files with 1217 additions and 258 deletions

View File

@@ -1,6 +1,6 @@
# lunar [![License](https://img.shields.io/badge/license-MIT-4EB1BA.svg?style=flat-square)](https://github.com/6tail/lunar-java/blob/master/LICENSE)
lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)工具,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道黑道日及吉凶、法定节假日及调休等。
lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)工具,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶、法定节假日及调休等。
> 支持java 1.5及以上版本。
@@ -10,6 +10,16 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
[English](https://github.com/6tail/lunar-java/blob/master/README_EN.md)
### 正式版本
```xml
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.6</version>
</dependency>
```
### 快照版本
```xml
@@ -28,13 +38,13 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</dependency>
```
### 下载jar
如果使用jar,建议下载最新的SNAPSHOT版本,bug将得到及时的修复。
如果使用jar,建议下载最新的版本,bug将得到及时的修复。
[Download](https://github.com/6tail/lunar-java/releases)

View File

@@ -6,6 +6,15 @@ lunar is a calendar library for Solar and Chinese Lunar.
[简体中文](https://github.com/6tail/lunar-java/blob/master/README.md)
### Release
```xml
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.6</version>
</dependency>
```
### Snapshot
@@ -25,13 +34,13 @@ lunar is a calendar library for Solar and Chinese Lunar.
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</dependency>
```
### Download
If you will use jars in your projects, I suggest you to download latest snapshot versions with less bugs.
If you will use jars in your projects, I suggest you to download latest versions with less bugs.
[Download](https://github.com/6tail/lunar-java/releases)

View File

@@ -7,7 +7,7 @@
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<packaging>jar</packaging>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.6</version>
<name>${project.groupId}:${project.artifactId}</name>
<url>https://github.com/6tail/lunar-java</url>
<description>a calendar library for Solar and Chinese Lunar</description>

View File

@@ -2,6 +2,7 @@ package com.nlf.calendar;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
/**
* 精确日期
@@ -10,8 +11,13 @@ import java.util.Date;
*/
public class ExactDate {
/**
* 时区
*/
private static final TimeZone TIME_ZONE = TimeZone.getTimeZone("GMT+8");
public static Calendar fromYmdHms(int year, int month, int day, int hour, int minute, int second) {
Calendar c = Calendar.getInstance();
Calendar c = Calendar.getInstance(TIME_ZONE);
c.set(year, month - 1, day, hour, minute, second);
c.set(Calendar.MILLISECOND, 0);
return c;
@@ -22,7 +28,7 @@ public class ExactDate {
}
public static Calendar fromDate(Date date) {
Calendar c = Calendar.getInstance();
Calendar c = Calendar.getInstance(TIME_ZONE);
c.setTime(date);
c.set(Calendar.MILLISECOND, 0);
return c;

View File

@@ -1,7 +1,5 @@
package com.nlf.calendar;
import com.nlf.calendar.util.LunarUtil;
/**
* 节气
*
@@ -48,15 +46,13 @@ public class JieQi {
*/
public void setName(String name) {
this.name = name;
for(String key: LunarUtil.JIE){
if(key.equals(name)){
this.jie = true;
return;
}
}
for(String key: LunarUtil.QI){
if(key.equals(name)){
this.qi = true;
for(int i=0,j=Lunar.JIE_QI.length;i<j;i++){
if(name.equals(Lunar.JIE_QI[i])){
if(i%2==0){
this.qi = true;
}else{
this.jie = true;
}
return;
}
}

View File

@@ -11,47 +11,18 @@ import java.util.*;
* @author 6tail
*/
public class Lunar {
/**
* 节气表头部追加农历上年末的节气名(节令:大雪),以示区分
*/
public static final String JIE_QI_PREPEND = "DA_XUE";
/**
* 节气表尾部追加农历下年初的节气名(气令:冬至),以示区分
*/
public static final String JIE_QI_APPEND = "DONG_ZHI";
/**
* 农历年初节气名(气令:冬至)
*/
public static final String JIE_QI_FIRST = "冬至";
/**
* 农历年末节气名(节令:大雪)
*/
public static final String JIE_QI_LAST = "大雪";
/**
* 节气表尾部追加阳历下年初的第一个节气名(节令:小寒),以示区分
*/
public static final String JIE_APPEND_SOLAR_FIRST = "XIAO_HAN";
/**
* 节气表尾部追加阳历下年初的第二个节气名(气令:大寒),以示区分
*/
public static final String QI_APPEND_SOLAR_SECOND = "DA_HAN";
/**
* 阳历下年初的第一个节气名(节令:小寒)
*/
public static final String JIE_SOLAR_FIRST = "小寒";
/**
* 阳历下年初的第二个节气名(气令:大寒)
*/
public static final String QI_SOLAR_SECOND = "大寒";
/**
* 1天对应的毫秒
*/
private static final long MS_PER_DAY = 86400000L;
/**
* 节气表,国标以冬至为首个节气
* 节气表,国标以冬至为首个气令
*/
public static final String[] JIE_QI = {"冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪"};
public static final String[] JIE_QI_IN_USE = {JIE_QI_PREPEND, "冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", JIE_QI_APPEND, JIE_APPEND_SOLAR_FIRST, QI_APPEND_SOLAR_SECOND};
/**
* 实际的节气表
*/
public static final String[] JIE_QI_IN_USE = {"DA_XUE", "冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "DONG_ZHI", "XIAO_HAN", "DA_HAN", "LI_CHUN", "YU_SHUI", "JING_ZHE"};
/**
* 农历年
@@ -271,6 +242,14 @@ public class Lunar {
yearGanIndex = offset % 10;
yearZhiIndex = offset % 12;
if (yearGanIndex < 0) {
yearGanIndex += 10;
}
if (yearZhiIndex < 0) {
yearZhiIndex += 12;
}
//以立春作为新一年的开始的干支纪年
int g = yearGanIndex;
int z = yearZhiIndex;
@@ -279,16 +258,20 @@ public class Lunar {
int gExact = yearGanIndex;
int zExact = yearZhiIndex;
//获取立春的阳历时刻
Solar liChun = jieQi.get("立春");
String liChunYmd = liChun.toYmd();
String liChunYmdHms = liChun.toYmdHms();
int solarYear = solar.getYear();
String solarYmd = solar.toYmd();
String solarYmdHms = solar.toYmdHms();
//获取立春的阳历时刻
Solar liChun = jieQi.get("立春");
if (liChun.getYear() != solarYear) {
liChun = jieQi.get("LI_CHUN");
}
String liChunYmd = liChun.toYmd();
String liChunYmdHms = liChun.toYmdHms();
//阳历和阴历年份相同代表正月初一及以后
if (year == solar.getYear()) {
if (year == solarYear) {
//立春日期判断
if (solarYmd.compareTo(liChunYmd) < 0) {
g--;
@@ -299,7 +282,7 @@ public class Lunar {
gExact--;
zExact--;
}
} else {
} else if (year < solarYear) {
if (solarYmd.compareTo(liChunYmd) >= 0) {
g++;
z++;
@@ -310,91 +293,60 @@ public class Lunar {
}
}
if (g < 0) {
g += 10;
}
if (g >= 10) {
g -= 10;
}
if (z < 0) {
z += 12;
}
if (z >= 12) {
z -= 12;
}
if (gExact < 0) {
gExact += 10;
}
if (gExact >= 10) {
gExact -= 10;
}
if (zExact < 0) {
zExact += 12;
}
if (zExact >= 12) {
zExact -= 12;
}
yearGanIndexByLiChun = (g<0?g+10:g)%10;
yearZhiIndexByLiChun = (z<0?z+12:z)%12;
yearGanIndexByLiChun = g;
yearZhiIndexByLiChun = z;
yearGanIndexExact = gExact;
yearZhiIndexExact = zExact;
yearGanIndexExact = (gExact<0?gExact+10:gExact)%10;
yearZhiIndexExact = (zExact<0?zExact+12:zExact)%12;
}
/**
* 干支纪月计算
* 计算干支纪月
*/
private void computeMonth() {
Solar start = null;
Solar end;
//干偏移值(以立春当天起算)
int gOffset = ((yearGanIndexByLiChun % 5 + 1) * 2) % 10;
//干偏移值(以立春交接时刻起算)
int gOffsetExact = ((yearGanIndexExact % 5 + 1) * 2) % 10;
String ymd = solar.toYmd();
String time = solar.toYmdHms();
int size = JIE_QI_IN_USE.length;
//序号:大雪到小寒之间-2,小寒到立春之间-1,立春之后0
int index = -2;
for (String jie : LunarUtil.JIE) {
end = jieQi.get(jie);
String ymd = solar.toYmd();
//序号:大雪以前-3,大雪到小寒之间-2,小寒到立春之间-1,立春之后0
int index = -3;
for (int i=0;i<size;i+=2) {
end = jieQi.get(JIE_QI_IN_USE[i]);
String symd = null == start ? ymd : start.toYmd();
String eymd = end.toYmd();
if (ymd.compareTo(symd) >= 0 && ymd.compareTo(eymd) < 0) {
if (ymd.compareTo(symd) >= 0 && ymd.compareTo(end.toYmd()) < 0) {
break;
}
start = end;
index++;
}
if (index < 0) {
index += 12;
}
monthGanIndex = (index + gOffset) % 10;
monthZhiIndex = (index + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
//干偏移值(以立春当天起算)
int offset = (((yearGanIndexByLiChun+(index<0?1:0)) % 5 + 1) * 2) % 10;
monthGanIndex = ((index<0?index+10:index) + offset) % 10;
monthZhiIndex = ((index<0?index+12:index) + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
//序号:大雪到小寒之间-2,小寒到立春之间-1,立春之后0
int indexExact = -2;
for (String jie : LunarUtil.JIE) {
end = jieQi.get(jie);
String time = solar.toYmdHms();
start = null;
index = -3;
for (int i=0;i<size;i+=2) {
end = jieQi.get(JIE_QI_IN_USE[i]);
String stime = null == start ? time : start.toYmdHms();
String etime = end.toYmdHms();
if (time.compareTo(stime) >= 0 && time.compareTo(etime) < 0) {
if (time.compareTo(stime) >= 0 && time.compareTo(end.toYmdHms()) < 0) {
break;
}
start = end;
indexExact++;
index++;
}
if (indexExact < 0) {
indexExact += 12;
}
monthGanIndexExact = (indexExact + gOffsetExact) % 10;
monthZhiIndexExact = (indexExact + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
//干偏移值(以立春交接时刻起算)
offset = (((yearGanIndexExact+(index<0?1:0)) % 5 + 1) * 2) % 10;
monthGanIndexExact = ((index<0?index+10:index) + offset) % 10;
monthZhiIndexExact = ((index<0?index+12:index) + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
}
/**
* 干支纪日计算
* 计算干支纪日
*/
private void computeDay() {
Solar noon = Solar.fromYmdHms(solar.getYear(), solar.getMonth(), solar.getDay(), 12, 0, 0);
@@ -427,7 +379,7 @@ public class Lunar {
}
/**
* 干支纪时计算
* 计算干支纪时
*/
private void computeTime() {
String hm = (hour < 10 ? "0" : "") + hour + ":" + (minute < 10 ? "0" : "") + minute;
@@ -436,7 +388,7 @@ public class Lunar {
}
/**
* 星期计算
* 计算星期
*/
private void computeWeek() {
this.weekIndex = solar.getWeek();
@@ -863,29 +815,42 @@ public class Lunar {
return LunarUtil.SEASON[Math.abs(month)];
}
protected String convertJieQi(String name){
String jq = name;
if("DONG_ZHI".equals(jq)){
jq = "冬至";
}else if("DA_HAN".equals(jq)){
jq = "大寒";
}else if("XIAO_HAN".equals(jq)){
jq = "小寒";
}else if("LI_CHUN".equals(jq)){
jq = "立春";
}else if("DA_XUE".equals(jq)){
jq = "大雪";
} else if ("YU_SHUI".equals(jq)) {
jq = "雨水";
} else if ("JING_ZHE".equals(jq)) {
jq = "惊蛰";
}
return jq;
}
/**
* 获取节令
*
* @return 节令
*/
public String getJie() {
for (String jie : LunarUtil.JIE) {
Solar d = jieQi.get(jie);
String jie = "";
for(int i=1,j=JIE_QI.length;i<j;i+=2){
String key = JIE_QI[i];
Solar d = jieQi.get(key);
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay()) {
return jie;
jie = key;
break;
}
}
// 追加的节令:大雪
Solar d = jieQi.get(JIE_QI_PREPEND);
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay()) {
return JIE_QI_LAST;
}
// 追加的节令:小寒
d = jieQi.get(JIE_APPEND_SOLAR_FIRST);
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay()) {
return JIE_SOLAR_FIRST;
}
return "";
return convertJieQi(jie);
}
/**
@@ -894,23 +859,16 @@ public class Lunar {
* @return 气令
*/
public String getQi() {
for (String qi : LunarUtil.QI) {
Solar d = jieQi.get(qi);
String qi = "";
for(int i=0,j=JIE_QI.length;i<j;i+=2){
String key = JIE_QI[i];
Solar d = jieQi.get(key);
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay()) {
return qi;
qi = key;
break;
}
}
// 追加的气令:冬至
Solar d = jieQi.get(JIE_QI_APPEND);
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay()) {
return JIE_QI_FIRST;
}
// 追加的气令:大寒
d = jieQi.get(QI_APPEND_SOLAR_SECOND);
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay()) {
return QI_SOLAR_SECOND;
}
return "";
return convertJieQi(qi);
}
/**
@@ -1005,6 +963,9 @@ public class Lunar {
if (null != f) {
l.add(f);
}
if (Math.abs(month) == 12 && day >= 29 && year != next(1).getYear()) {
l.add("除夕");
}
return l;
}
@@ -1954,7 +1915,12 @@ public class Lunar {
* @return 节气
*/
public JieQi getNextJie() {
return getNearJieQi(true, LunarUtil.JIE);
int l = JIE_QI_IN_USE.length/2;
String[] conditions = new String[l];
for(int i=0;i<l;i++){
conditions[i] = JIE_QI_IN_USE[i*2];
}
return getNearJieQi(true, conditions);
}
/**
@@ -1963,7 +1929,12 @@ public class Lunar {
* @return 节气
*/
public JieQi getPrevJie() {
return getNearJieQi(false, LunarUtil.JIE);
int l = JIE_QI_IN_USE.length/2;
String[] conditions = new String[l];
for(int i=0;i<l;i++){
conditions[i] = JIE_QI_IN_USE[i*2];
}
return getNearJieQi(false, conditions);
}
/**
@@ -1972,7 +1943,12 @@ public class Lunar {
* @return 节气
*/
public JieQi getNextQi() {
return getNearJieQi(true, LunarUtil.QI);
int l = JIE_QI_IN_USE.length/2;
String[] conditions = new String[l];
for(int i=0;i<l;i++){
conditions[i] = JIE_QI_IN_USE[i*2+1];
}
return getNearJieQi(true, conditions);
}
/**
@@ -1981,7 +1957,12 @@ public class Lunar {
* @return 节气
*/
public JieQi getPrevQi() {
return getNearJieQi(false, LunarUtil.QI);
int l = JIE_QI_IN_USE.length/2;
String[] conditions = new String[l];
for(int i=0;i<l;i++){
conditions[i] = JIE_QI_IN_USE[i*2+1];
}
return getNearJieQi(false, conditions);
}
/**
@@ -2019,19 +2000,7 @@ public class Lunar {
boolean filter = !filters.isEmpty();
String today = solar.toYmdHms();
for (Map.Entry<String, Solar> entry : jieQi.entrySet()) {
String jq = entry.getKey();
if (JIE_QI_APPEND.equals(jq)) {
jq = JIE_QI_FIRST;
}
if (JIE_QI_PREPEND.equals(jq)) {
jq = JIE_QI_LAST;
}
if (JIE_APPEND_SOLAR_FIRST.equals(jq)) {
jq = JIE_SOLAR_FIRST;
}
if (QI_APPEND_SOLAR_SECOND.equals(jq)) {
jq = QI_SOLAR_SECOND;
}
String jq = convertJieQi(entry.getKey());
if (filter) {
if (!filters.contains(jq)) {
continue;
@@ -2077,16 +2046,7 @@ public class Lunar {
break;
}
}
if (JIE_QI_APPEND.equals(name)) {
name = JIE_QI_FIRST;
} else if (JIE_QI_PREPEND.equals(name)) {
name = JIE_QI_LAST;
} else if (JIE_APPEND_SOLAR_FIRST.equals(name)) {
name = JIE_SOLAR_FIRST;
} else if (QI_APPEND_SOLAR_SECOND.equals(name)) {
name = QI_SOLAR_SECOND;
}
return name;
return convertJieQi(name);
}
/**
@@ -2528,11 +2488,11 @@ public class Lunar {
@SuppressWarnings("MagicConstant")
public ShuJiu getShuJiu() {
Calendar currentCalendar = ExactDate.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay());
Solar start = jieQi.get(JIE_QI_APPEND);
Solar start = jieQi.get("DONG_ZHI");
Calendar startCalendar = ExactDate.fromYmd(start.getYear(), start.getMonth(), start.getDay());
if (currentCalendar.compareTo(startCalendar) < 0) {
start = jieQi.get(JIE_QI_FIRST);
start = jieQi.get("冬至");
startCalendar = ExactDate.fromYmd(start.getYear(), start.getMonth(), start.getDay());
}
@@ -2642,6 +2602,44 @@ public class Lunar {
Calendar startCalendar = ExactDate.fromYmd(startSolar.getYear(), startSolar.getMonth(), startSolar.getDay());
int days = (int) ((currentCalendar.getTimeInMillis() - startCalendar.getTimeInMillis()) / MS_PER_DAY);
return LunarUtil.WU_HOU[offset * 3 + days / 5];
return LunarUtil.WU_HOU[(offset * 3 + days / 5) % LunarUtil.WU_HOU.length];
}
/**
* 获取日禄
* @return 日禄
*/
public String getDayLu() {
String gan = LunarUtil.LU.get(getDayGan());
String zhi = LunarUtil.LU.get(getDayZhi());
String lu = gan + "命互禄";
if (null != zhi) {
lu += " " + zhi + "命进禄";
}
return lu;
}
/**
* 获取时辰
*
* @return 时辰
*/
public LunarTime getTime() {
return new LunarTime(year, month, day, hour, minute, second);
}
/**
* 获取当天的时辰列表
*
* @return 时辰列表
*/
public List<LunarTime> getTimes() {
List<LunarTime> l = new ArrayList<LunarTime>();
l.add(new LunarTime(year, month, day, 0, 0, 0));
for(int i = 0; i < 12; i++){
l.add(new LunarTime(year, month, day, (i+1)*2-1, 0, 0));
}
return l;
}
}

View File

@@ -0,0 +1,373 @@
package com.nlf.calendar;
import com.nlf.calendar.util.LunarUtil;
import java.util.List;
import java.util.Map;
/**
* 时辰
*
* @author 6tail
*/
public class LunarTime {
/**
* 天干下标,0-9
*/
private int ganIndex;
/**
* 地支下标,0-11
*/
private int zhiIndex;
/**
* 阴历
*/
private Lunar lunar;
public LunarTime(int lunarYear, int lunarMonth, int lunarDay, int hour, int minute, int second) {
this.lunar = Lunar.fromYmdHms(lunarYear, lunarMonth, lunarDay, hour, minute, second);
this.zhiIndex = LunarUtil.getTimeZhiIndex(String.format("%02d:%02d", hour, minute));
this.ganIndex = (lunar.getDayGanIndexExact() % 5 * 2 + zhiIndex) % 10;
}
public static LunarTime fromYmdHms(int lunarYear, int lunarMonth, int lunarDay, int hour, int minute, int second) {
return new LunarTime(lunarYear, lunarMonth, lunarDay, hour, minute, second);
}
public int getGanIndex() {
return ganIndex;
}
public int getZhiIndex() {
return zhiIndex;
}
/**
* 获取生肖
*
* @return 生肖,如虎
*/
public String getShengXiao() {
return LunarUtil.SHENGXIAO[zhiIndex + 1];
}
/**
* 获取地支
*
* @return 地支
*/
public String getZhi() {
return LunarUtil.ZHI[zhiIndex + 1];
}
/**
* 获取天干
*
* @return 天干
*/
public String getGan() {
return LunarUtil.GAN[ganIndex + 1];
}
/**
* 获取干支(时柱)
*
* @return 干支(时柱)
*/
public String getGanZhi() {
return getGan() + getZhi();
}
/**
* 获取喜神方位
*
* @return 喜神方位,如艮
*/
public String getPositionXi() {
return LunarUtil.POSITION_XI[ganIndex + 1];
}
/**
* 获取喜神方位描述
*
* @return 喜神方位描述,如东北
*/
public String getPositionXiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionXi());
}
/**
* 获取阳贵神方位
*
* @return 阳贵神方位,如艮
*/
public String getPositionYangGui() {
return LunarUtil.POSITION_YANG_GUI[ganIndex + 1];
}
/**
* 获取阳贵神方位描述
*
* @return 阳贵神方位描述,如东北
*/
public String getPositionYangGuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionYangGui());
}
/**
* 获取阴贵神方位
*
* @return 阴贵神方位,如艮
*/
public String getPositionYinGui() {
return LunarUtil.POSITION_YIN_GUI[ganIndex + 1];
}
/**
* 获取阴贵神方位描述
*
* @return 阴贵神方位描述,如东北
*/
public String getPositionYinGuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionYinGui());
}
/**
* 获取福神方位
*
* @return 福神方位,如艮
*/
public String getPositionFu() {
return LunarUtil.POSITION_FU[ganIndex + 1];
}
/**
* 获取福神方位描述
*
* @return 福神方位描述,如东北
*/
public String getPositionFuDesc() {
return LunarUtil.POSITION_DESC.get(getPositionFu());
}
/**
* 获取财神方位
*
* @return 财神方位,如艮
*/
public String getPositionCai() {
return LunarUtil.POSITION_CAI[ganIndex + 1];
}
/**
* 获取财神方位描述
*
* @return 财神方位描述,如东北
*/
public String getPositionCaiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionCai());
}
/**
* 获取纳音
*
* @return 纳音,如剑锋金
*/
public String getNaYin() {
return LunarUtil.NAYIN.get(getGanZhi());
}
/**
* 获取值时天神
*
* @return 值时天神
*/
public String getTianShen() {
String dayZhi = lunar.getDayZhiExact();
int offset = LunarUtil.ZHI_TIAN_SHEN_OFFSET.get(dayZhi);
return LunarUtil.TIAN_SHEN[(zhiIndex + offset) % 12 + 1];
}
/**
* 获取值时天神类型:黄道/黑道
*
* @return 值时天神类型:黄道/黑道
*/
public String getTianShenType() {
return LunarUtil.TIAN_SHEN_TYPE.get(getTianShen());
}
/**
* 获取值时天神吉凶
*
* @return 吉/凶
*/
public String getTianShenLuck() {
return LunarUtil.TIAN_SHEN_TYPE_LUCK.get(getTianShenType());
}
/**
* 获取时冲
*
* @return 时冲,如申
*/
public String getChong() {
return LunarUtil.CHONG[zhiIndex + 1];
}
/**
* 获取时煞
*
* @return 时煞,如北
*/
public String getSha() {
return LunarUtil.SHA.get(getZhi());
}
/**
* 获取时冲生肖
*
* @return 时冲生肖,如猴
*/
public String getChongShengXiao() {
String chong = getChong();
for (int i = 0, j = LunarUtil.ZHI.length; i < j; i++) {
if (LunarUtil.ZHI[i].equals(chong)) {
return LunarUtil.SHENGXIAO[i];
}
}
return "";
}
/**
* 获取时冲描述
*
* @return 时冲描述,如(壬申)猴
*/
public String getChongDesc() {
return "(" + getChongGan() + getChong() + ")" + getChongShengXiao();
}
/**
* 获取无情之克的时冲天干
*
* @return 无情之克的时冲天干,如甲
*/
public String getChongGan() {
return LunarUtil.CHONG_GAN[ganIndex + 1];
}
/**
* 获取有情之克的时冲天干
*
* @return 有情之克的时冲天干,如甲
*/
public String getChongGanTie() {
return LunarUtil.CHONG_GAN_TIE[ganIndex + 1];
}
/**
* 获取宜,如果没有,返回["无"]
*
* @return 宜
*/
public List<String> getYi() {
return LunarUtil.getTimeYi(lunar.getDayInGanZhiExact(), getGanZhi());
}
/**
* 获取忌,如果没有,返回["无"]
*
* @return 忌
*/
public List<String> getJi() {
return LunarUtil.getTimeJi(lunar.getDayInGanZhiExact(), getGanZhi());
}
/**
* 获取值时九星(时家紫白星歌诀:三元时白最为佳,冬至阳生顺莫差,孟日七宫仲一白,季日四绿发萌芽,每把时辰起甲子,本时星耀照光华,时星移入中宫去,顺飞八方逐细查。夏至阴生逆回首,孟归三碧季加六,仲在九宫时起甲,依然掌中逆轮跨。)
*
* @return 值时九星
*/
public NineStar getNineStar() {
//顺逆
String solarYmd = lunar.getSolar().toYmd();
Map<String, Solar> jieQi = lunar.getJieQiTable();
boolean asc = false;
if (solarYmd.compareTo(jieQi.get("冬至").toYmd()) >= 0 && solarYmd.compareTo(jieQi.get("夏至").toYmd()) < 0) {
asc = true;
}
int start = asc ? 7 : 3;
String dayZhi = lunar.getDayZhi();
if ("子午卯酉".contains(dayZhi)) {
start = asc ? 1 : 9;
} else if ("辰戌丑未".contains(dayZhi)) {
start = asc ? 4 : 6;
}
int index = asc ? start + zhiIndex - 1 : start - zhiIndex - 1;
if (index > 8) {
index -= 9;
}
if (index < 0) {
index += 9;
}
return new NineStar(index);
}
/**
* 获取所在旬
*
* @return 旬
*/
public String getXun() {
return LunarUtil.getXun(getGanZhi());
}
/**
* 获取值时空亡
*
* @return 空亡(旬空)
*/
public String getXunKong() {
return LunarUtil.getXunKong(getGanZhi());
}
/**
* 获取当前时辰的最早时分
*
* @return 时分,如:21:00
*/
public String getMinHm() {
int hour = lunar.getHour();
if (hour <1){
return "00:00";
} else if (hour > 22) {
return "23:00";
}
return String.format("%02d:00", hour % 2 == 0? hour - 1 : hour);
}
/**
* 获取当前时辰的最晚时分
*
* @return 时分,如:22:59
*/
public String getMaxHm() {
int hour = lunar.getHour();
if (hour <1){
return "00:59";
} else if (hour > 22) {
return "23:59";
}
return String.format("%02d:59", hour % 2 == 0? hour : hour + 1);
}
@Override
public String toString() {
return getGanZhi();
}
}

View File

@@ -1,9 +1,12 @@
package com.nlf.calendar;
import com.nlf.calendar.util.LunarUtil;
import com.nlf.calendar.util.ShouXingUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 农历年
@@ -12,6 +15,28 @@ import java.util.List;
*/
public class LunarYear {
/**
* 闰冬月年份
*/
private static final int[] LEAP_11 = {75, 94, 170, 238, 265, 322, 389, 469, 553, 583, 610, 678, 735, 754, 773, 849, 887, 936, 1050, 1069, 1126, 1145, 1164, 1183, 1259, 1278, 1308, 1373, 1403, 1441, 1460, 1498, 1555, 1593, 1612, 1631, 1642, 2033, 2128, 2147, 2242, 2614, 2728, 2910, 3062, 3244, 3339, 3616, 3711, 3730, 3825, 4007, 4159, 4197, 4322, 4341, 4379, 4417, 4531, 4599, 4694, 4713, 4789, 4808, 4971, 5085, 5104, 5161, 5180, 5199, 5294, 5305, 5476, 5677, 5696, 5772, 5791, 5848, 5886, 6049, 6068, 6144, 6163, 6258, 6402, 6440, 6497, 6516, 6630, 6641, 6660, 6679, 6736, 6774, 6850, 6869, 6899, 6918, 6994, 7013, 7032, 7051, 7070, 7089, 7108, 7127, 7146, 7222, 7271, 7290, 7309, 7366, 7385, 7404, 7442, 7461, 7480, 7491, 7499, 7594, 7624, 7643, 7662, 7681, 7719, 7738, 7814, 7863, 7882, 7901, 7939, 7958, 7977, 7996, 8034, 8053, 8072, 8091, 8121, 8159, 8186, 8216, 8235, 8254, 8273, 8311, 8330, 8341, 8349, 8368, 8444, 8463, 8474, 8493, 8531, 8569, 8588, 8626, 8664, 8683, 8694, 8702, 8713, 8721, 8751, 8789, 8808, 8816, 8827, 8846, 8884, 8903, 8922, 8941, 8971, 9036, 9066, 9085, 9104, 9123, 9142, 9161, 9180, 9199, 9218, 9256, 9294, 9313, 9324, 9343, 9362, 9381, 9419, 9438, 9476, 9514, 9533, 9544, 9552, 9563, 9571, 9582, 9601, 9639, 9658, 9666, 9677, 9696, 9734, 9753, 9772, 9791, 9802, 9821, 9886, 9897, 9916, 9935, 9954, 9973, 9992};
/**
* 闰腊月年份
*/
private static final int[] LEAP_12 = {37, 56, 113, 132, 151, 189, 208, 227, 246, 284, 303, 341, 360, 379, 417, 436, 458, 477, 496, 515, 534, 572, 591, 629, 648, 667, 697, 716, 792, 811, 830, 868, 906, 925, 944, 963, 982, 1001, 1020, 1039, 1058, 1088, 1153, 1202, 1221, 1240, 1297, 1335, 1392, 1411, 1422, 1430, 1517, 1525, 1536, 1574, 3358, 3472, 3806, 3988, 4751, 4941, 5066, 5123, 5275, 5343, 5438, 5457, 5495, 5533, 5552, 5715, 5810, 5829, 5905, 5924, 6421, 6535, 6793, 6812, 6888, 6907, 7002, 7184, 7260, 7279, 7374, 7556, 7746, 7757, 7776, 7833, 7852, 7871, 7966, 8015, 8110, 8129, 8148, 8224, 8243, 8338, 8406, 8425, 8482, 8501, 8520, 8558, 8596, 8607, 8615, 8645, 8740, 8778, 8835, 8865, 8930, 8960, 8979, 8998, 9017, 9055, 9074, 9093, 9112, 9150, 9188, 9237, 9275, 9332, 9351, 9370, 9408, 9427, 9446, 9457, 9465, 9495, 9560, 9590, 9628, 9647, 9685, 9715, 9742, 9780, 9810, 9818, 9829, 9848, 9867, 9905, 9924, 9943, 9962, 10000};
private static final Map<Integer, Integer> LEAP = new HashMap<Integer, Integer>();
private static final Map<Integer, LunarYear> CACHE = new HashMap<Integer, LunarYear>();
static {
for (int y : LEAP_11) {
LEAP.put(y, 13);
}
for (int y : LEAP_12) {
LEAP.put(y, 14);
}
}
/**
* 农历年
*/
@@ -44,26 +69,33 @@ public class LunarYear {
* @return 农历年
*/
public static LunarYear fromYear(int lunarYear) {
return new LunarYear(lunarYear);
LunarYear obj = CACHE.get(lunarYear);
if (null == obj) {
obj = new LunarYear(lunarYear);
CACHE.put(lunarYear, obj);
}
return obj;
}
private void compute() {
// 节气(中午12点)
double[] jq = new double[25];
double[] jq = new double[27];
// 合朔,即每月初一(中午12点)
double[] hs = new double[15];
double[] hs = new double[16];
// 每月天数
int[] dayCounts = new int[hs.length - 1];
int year = this.year - 2000;
// 从上年的大雪到下年的大寒
int currentYear = this.year;
int year = currentYear - 2000;
// 从上年的大雪到下年的立春
for (int i = 0, j = Lunar.JIE_QI_IN_USE.length; i < j; i++) {
// 精确的节气
double t = 36525 * ShouXingUtil.saLonT((year + (17 + i) * 15d / 360) * ShouXingUtil.PI_2);
t += ShouXingUtil.ONE_THIRD - ShouXingUtil.dtT(t);
jieQiJulianDays.add(t + Solar.J2000);
// 按中午12点算的节气
if (i > 0 && i < 26) {
if (i > 0 && i < 28) {
jq[i - 1] = Math.round(t);
}
}
@@ -82,25 +114,41 @@ public class LunarYear {
dayCounts[i] = (int) (hs[i + 1] - hs[i]);
}
int leap = -1;
if (hs[13] <= jq[24]) {
int i = 1;
while (hs[i + 1] > jq[2 * i] && i < 13) {
i++;
Integer currentYearLeap = LEAP.get(currentYear);
if (null == currentYearLeap) {
currentYearLeap = -1;
if (hs[13] <= jq[24]) {
int i = 1;
while (hs[i + 1] > jq[2 * i] && i < 13) {
i++;
}
currentYearLeap = i;
}
leap = i;
}
int y = this.year - 1;
int prevYear = currentYear - 1;
Integer prevYearLeap = LEAP.get(prevYear);
prevYearLeap = null == prevYearLeap ? -1 : prevYearLeap - 12;
int y = prevYear;
int m = 11;
for (int i = 0, j = dayCounts.length; i < j; i++) {
boolean isLeap = false;
if (i == leap) {
isLeap = true;
m--;
int cm = m;
boolean isNextLeap = false;
if (y == currentYear && i == currentYearLeap) {
cm = -cm;
} else if (y == prevYear && i == prevYearLeap) {
cm = -cm;
}
if (y == currentYear && i + 1 == currentYearLeap) {
isNextLeap = true;
} else if (y == prevYear && i + 1 == prevYearLeap) {
isNextLeap = true;
}
this.months.add(new LunarMonth(y, cm, dayCounts[i], hs[i] + Solar.J2000));
if (!isNextLeap) {
m++;
}
this.months.add(new LunarMonth(y, isLeap ? -m : m, dayCounts[i], hs[i] + Solar.J2000));
m++;
if (m == 13) {
m = 1;
y++;
@@ -164,6 +212,58 @@ public class LunarYear {
return 0;
}
/**
* 获取治水(正月第一个辰日是初几,就是几龙治水)
*
* @return 治水,如:二龙治水
*/
public String getZhiShui() {
int offset = 4 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayZhiIndex();
if (offset < 0) {
offset += 12;
}
return LunarUtil.NUMBER[offset+1] + "龙治水";
}
/**
* 获取分饼(正月第一个丙日是初几,就是几人分饼)
*
* @return 分饼,如:六人分饼
*/
public String getFenBing() {
int offset = 2 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
if (offset < 0) {
offset += 10;
}
return LunarUtil.NUMBER[offset+1] + "人分饼";
}
/**
* 获取耕田(正月第一个丑日是初几,就是几牛耕田)
*
* @return 耕田,如:六牛耕田
*/
public String getGengTian() {
int offset = 1 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayZhiIndex();
if (offset < 0) {
offset += 12;
}
return LunarUtil.NUMBER[offset+1] + "牛耕田";
}
/**
* 获取得金(正月第一个辛日是初几,就是几日得金)
*
* @return 得金,如:一日得金
*/
public String getDeJin() {
int offset = 7 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
if (offset < 0) {
offset += 10;
}
return LunarUtil.NUMBER[offset+1] + "日得金";
}
@Override
public String toString() {
return year + "";

View File

@@ -117,12 +117,21 @@ public class DaYun {
}
/**
* 获取流年
* 获取10轮流年
*
* @return 流年
*/
public LiuNian[] getLiuNian() {
int n = 10;
return getLiuNian(10);
}
/**
* 获取流年
*
* @param n 轮数
* @return 流年
*/
public LiuNian[] getLiuNian(int n) {
if (index < 1) {
n = endYear-startYear+1;
}
@@ -134,12 +143,20 @@ public class DaYun {
}
/**
* 获取小运
* 获取10轮小运
*
* @return 小运
*/
public XiaoYun[] getXiaoYun() {
int n = 10;
return getXiaoYun(10);
}
/**
* 获取小运
* @param n 轮数
* @return 小运
*/
public XiaoYun[] getXiaoYun(int n) {
if (index < 1) {
n = endYear-startYear+1;
}

View File

@@ -145,12 +145,21 @@ public class Yun {
}
/**
* 获取大运
* 获取10轮大运
*
* @return 大运
*/
public DaYun[] getDaYun() {
int n = 10;
return getDaYun(10);
}
/**
* 获取大运
*
* @param n 轮数
* @return 大运
*/
public DaYun[] getDaYun(int n) {
DaYun[] l = new DaYun[n];
for (int i = 0; i < n; i++) {
l[i] = new DaYun(this, i);

File diff suppressed because one or more lines are too long

View File

@@ -105,17 +105,13 @@ public class LunarUtil{
/** 彭祖百忌.地支 */
public static final String[] PENGZU_ZHI = {"","子不问卜自惹祸殃","丑不冠带主不还乡","寅不祭祀神鬼不尝","卯不穿井水泉不香","辰不哭泣必主重丧","巳不远行财物伏藏","午不苫盖屋主更张","未不服药毒气入肠","申不安床鬼祟入房","酉不会客醉坐颠狂","戌不吃犬作怪上床","亥不嫁娶不利新郎"};
/** 数字 */
public static final String[] NUMBER = {"〇","一","二","三","四","五","六","七","八","九"};
public static final String[] NUMBER = {"〇","一","二","三","四","五","六","七","八","九","十","十一","十二"};
/** 月 */
public static final String[] MONTH = {"","正","二","三","四","五","六","七","八","九","十","冬","腊"};
/** 季节 */
public static final String[] SEASON = {"","孟春","仲春","季春","孟夏","仲夏","季夏","孟秋","仲秋","季秋","孟冬","仲冬","季冬"};
/** 生肖 */
public static final String[] SHENGXIAO = {"","鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};
/** 气 */
public static final String[] QI = {"大寒","雨水","春分","谷雨","小满","夏至","大暑","处暑","秋分","霜降","小雪","冬至"};
/** 节 */
public static final String[] JIE = {"小寒","立春","惊蛰","清明","立夏","芒种","小暑","立秋","白露","寒露","立冬","大雪"};
/** 日 */
public static final String[] DAY = {"","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"};
/** 月相,朔月也叫新月,望月也叫满月 */
@@ -132,7 +128,6 @@ public class LunarUtil{
put("8-15","中秋节");
put("9-9","重阳节");
put("12-8","腊八节");
put("12-30","除夕");
}
};
/** 农历日期对应的非正式节日,参考《寿康宝鉴》 */
@@ -1102,6 +1097,32 @@ public class LunarUtil{
}
};
/** 禄(甲禄在寅,乙禄在卯,丙戊禄在巳、丁己禄在午、庚禄在申、辛禄在酉、壬禄在亥、癸禄在子) */
public static final Map<String,String> LU = new HashMap<String, String>(){
private static final long serialVersionUID = -1L;
{
put("甲","寅");
put("乙","卯");
put("丙","巳");
put("丁","午");
put("戊","巳");
put("己","午");
put("庚","申");
put("辛","酉");
put("壬","亥");
put("癸","子");
put("寅","甲");
put("卯","乙");
put("巳","丙,戊");
put("午","丁,己");
put("申","庚");
put("酉","辛");
put("亥","壬");
put("子","癸");
}
};
protected LunarUtil(){}
/**
@@ -1190,7 +1211,8 @@ public class LunarUtil{
}
}
if(matched) {
String ys = left.substring(left.indexOf(":") + 1, left.indexOf(","));
String ys = left.substring(left.indexOf(':') + 1);
ys = ys.substring(0, ys.indexOf(','));
for (int i = 0, j = ys.length(); i < j; i += 2) {
String m = ys.substring(i, i + 2);
l.add(YI_JI[Integer.parseInt(m,16)]);

View File

@@ -97,7 +97,6 @@ public class SolarUtil {
put("5-5", Collections.nCopies(1, "马克思诞辰纪念日"));
put("5-8", Collections.nCopies(1, "世界红十字日"));
put("5-11", Collections.nCopies(1, "世界肥胖日"));
put("5-23", Collections.nCopies(1, "世界读书日"));
put("5-27", Collections.nCopies(1, "上海解放日"));
put("5-31", Collections.nCopies(1, "世界无烟日"));
put("6-5", Collections.nCopies(1, "世界环境日"));

View File

@@ -108,6 +108,15 @@ public class BaZiTestNew {
}
}
@Test
public void testBazi2Solar3() {
List<Solar> l = Solar.fromBaZi("辛丑", "丁酉", "丙寅", "戊戌");
// [2021-09-15 20:00:00 星期三 处女座, 1961-09-30 20:00:00 星期六 天秤座]
for (Solar solar : l) {
System.out.println(solar.toFullString());
}
}
@Test
public void testBaziShiShenZhi() {
Solar solar = new Solar(2020, 1, 1, 22, 35, 0);

View File

@@ -57,6 +57,16 @@ public class BaZiTest {
Assert.assertEquals("时柱", "辛亥", eightChar.getTime());
}
@Test
public void testGanZhi3(){
Lunar lunar = new Lunar(2019,12,12,11,22,0);
EightChar eightChar = lunar.getEightChar();
Assert.assertEquals("年柱", "己亥", eightChar.getYear());
Assert.assertEquals("月柱", "丁丑", eightChar.getMonth());
Assert.assertEquals("日柱", "戊申", eightChar.getDay());
Assert.assertEquals("时柱", "戊午", eightChar.getTime());
}
@Test
public void testHideGan() {
Solar solar = new Solar(2005, 12, 23, 8, 37, 0);
@@ -230,4 +240,22 @@ public class BaZiTest {
}
}
@Test
public void test4() {
Lunar lunar = Lunar.fromYmd(1985, 12, 27);
Assert.assertEquals("1995-11-05", lunar.getEightChar().getYun(1).getStartSolar().toYmd());
}
@Test
public void test5() {
Lunar lunar = Lunar.fromYmd(1985, 1, 27);
Assert.assertEquals("1989-03-28", lunar.getEightChar().getYun(1).getStartSolar().toYmd());
}
@Test
public void test6() {
Lunar lunar = Lunar.fromYmd(1986, 12, 27);
Assert.assertEquals("1990-04-15", lunar.getEightChar().getYun(1).getStartSolar().toYmd());
}
}

View File

@@ -73,17 +73,6 @@ public class GanZhiTest {
Assert.assertEquals("丁丑",lunar.getMonthInGanZhi());
Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
solar = new Solar(2020,2,4,13,22,0);
lunar = solar.getLunar();
Assert.assertEquals("庚子",lunar.getYearInGanZhi());
Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
Assert.assertEquals("戊寅",lunar.getMonthInGanZhi());
Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
solar = new Solar(2020,2,4,18,22,0);
lunar = solar.getLunar();
Assert.assertEquals("庚子",lunar.getYearInGanZhi());
@@ -320,4 +309,28 @@ public class GanZhiTest {
Assert.assertEquals("戊辰",lunar.getYearInGanZhiExact());
}
@Test
public void test17() {
Solar solar = new Solar(2019, 2, 8, 13, 22, 0);
Lunar lunar = solar.getLunar();
Assert.assertEquals("己亥", lunar.getYearInGanZhi());
Assert.assertEquals("己亥", lunar.getYearInGanZhiByLiChun());
Assert.assertEquals("己亥", lunar.getYearInGanZhiExact());
Assert.assertEquals("丙寅", lunar.getMonthInGanZhi());
Assert.assertEquals("丙寅", lunar.getMonthInGanZhiExact());
}
@Test
public void test18() {
Solar solar = new Solar(2020,2,4,13,22,0);
Lunar lunar = solar.getLunar();
Assert.assertEquals("庚子",lunar.getYearInGanZhi());
Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
Assert.assertEquals("戊寅",lunar.getMonthInGanZhi());
Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
}
}

View File

@@ -1,5 +1,6 @@
package test;
import com.nlf.calendar.Holiday;
import com.nlf.calendar.Solar;
import com.nlf.calendar.util.HolidayUtil;
import org.junit.Assert;
@@ -116,4 +117,12 @@ public class HolidayTest {
Assert.assertEquals("2021-11-11 结婚纪念日 2021-11-11", HolidayUtil.getHoliday("2021-11-11") + "");
Assert.assertEquals("2021-12-01 她的生日 2021-12-01", HolidayUtil.getHoliday("2021-12-01") + "");
}
@Test
public void test1() {
Holiday holiday = HolidayUtil.getHoliday(2016,10,4);
Assert.assertNotNull(holiday);
Assert.assertNotNull(holiday.getTarget());
Assert.assertEquals("2016-10-01",holiday.getTarget());
}
}

View File

@@ -13,64 +13,343 @@ import org.junit.Test;
public class LunarTest {
@Test
public void test(){
Lunar date = new Lunar(2019,3,27,0,0,0);
Assert.assertEquals("二〇一九年三月廿七",date.toString());
Assert.assertEquals("二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 (七殿泰山王诞) 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[坎](正北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]",date.toFullString());
Assert.assertEquals("2019-05-01",date.getSolar().toString());
Assert.assertEquals("2019-05-01 00:00:00 星期三 (劳动节) 金牛座",date.getSolar().toFullString());
public void test() {
Lunar date = new Lunar(2019, 3, 27, 0, 0, 0);
Assert.assertEquals("二〇一九年三月廿七", date.toString());
Assert.assertEquals("二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 (七殿泰山王诞) 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[坎](正北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]", date.toFullString());
Assert.assertEquals("2019-05-01", date.getSolar().toString());
Assert.assertEquals("2019-05-01 00:00:00 星期三 (劳动节) 金牛座", date.getSolar().toFullString());
}
@Test
public void test1(){
Solar solar = new Solar(1,1,1,12,0,0);
Assert.assertEquals("〇年冬月十八",solar.getLunar().toString());
public void test1() {
Solar solar = new Solar(1, 1, 1, 12, 0, 0);
Assert.assertEquals("〇年冬月十八", solar.getLunar().toString());
}
@Test
public void test2(){
Solar solar = new Solar(9999,12,31,12,0,0);
Assert.assertEquals("九九九九年腊月初二",solar.getLunar().toString());
public void test2() {
Solar solar = new Solar(9999, 12, 31, 12, 0, 0);
Assert.assertEquals("九九九九年腊月初二", solar.getLunar().toString());
}
@Test
public void test3(){
Lunar lunar = new Lunar(0,11,18,12,0,0);
Assert.assertEquals("0001-01-01",lunar.getSolar().toString());
public void test3() {
Lunar lunar = new Lunar(0, 11, 18, 12, 0, 0);
Assert.assertEquals("0001-01-01", lunar.getSolar().toString());
}
@Test
public void test4(){
Lunar lunar = new Lunar(9999,12,2,12,0,0);
Assert.assertEquals("9999-12-31",lunar.getSolar().toString());
public void test4() {
Lunar lunar = new Lunar(9999, 12, 2, 12, 0, 0);
Assert.assertEquals("9999-12-31", lunar.getSolar().toString());
}
@Test
public void test5(){
Lunar lunar = new Lunar(1905,1,1,12,0,0);
Assert.assertEquals("1905-02-04",lunar.getSolar().toString());
public void test5() {
Lunar lunar = new Lunar(1905, 1, 1, 12, 0, 0);
Assert.assertEquals("1905-02-04", lunar.getSolar().toString());
}
@Test
public void test6(){
Lunar lunar = new Lunar(2038,12,29,12,0,0);
Assert.assertEquals("2039-01-23",lunar.getSolar().toString());
public void test6() {
Lunar lunar = new Lunar(2038, 12, 29, 12, 0, 0);
Assert.assertEquals("2039-01-23", lunar.getSolar().toString());
}
@Test
public void test7(){
Lunar lunar = new Lunar(2020,-4,2,13,0,0);
Assert.assertEquals("二〇二〇年闰四月初二",lunar.toString());
Assert.assertEquals("2020-05-24",lunar.getSolar().toString());
public void test7() {
Lunar lunar = new Lunar(2020, -4, 2, 13, 0, 0);
Assert.assertEquals("二〇二〇年闰四月初二", lunar.toString());
Assert.assertEquals("2020-05-24", lunar.getSolar().toString());
}
@Test
public void testNext(){
Solar solar = new Solar(2020,1,10,12,0,0);
public void test8() {
Lunar lunar = new Lunar(2020, 12, 10, 13, 0, 0);
Assert.assertEquals("二〇二〇年腊月初十", lunar.toString());
Assert.assertEquals("2021-01-22", lunar.getSolar().toString());
}
@Test
public void test9() {
Lunar lunar = new Lunar(1500, 1, 1, 12, 0, 0);
Assert.assertEquals("1500-01-31", lunar.getSolar().toString());
}
@Test
public void test10() {
Lunar lunar = new Lunar(1500, 12, 29, 12, 0, 0);
Assert.assertEquals("1501-01-18", lunar.getSolar().toString());
}
@Test
public void test11() {
Solar solar = new Solar(1500, 1, 1, 12, 0, 0);
Assert.assertEquals("一四九九年腊月初一", solar.getLunar().toString());
}
@Test
public void test12() {
Solar solar = new Solar(1500, 12, 31, 12, 0, 0);
Assert.assertEquals("一五〇〇年腊月十一", solar.getLunar().toString());
}
@Test
public void test13() {
Solar solar = new Solar(1582, 10, 4, 12, 0, 0);
Assert.assertEquals("一五八二年九月十八", solar.getLunar().toString());
}
@Test
public void test14() {
Solar solar = new Solar(1582, 10, 15, 12, 0, 0);
Assert.assertEquals("一五八二年九月十九", solar.getLunar().toString());
}
@Test
public void test15() {
Lunar lunar = new Lunar(1582, 9, 18, 12, 0, 0);
Assert.assertEquals("1582-10-04", lunar.getSolar().toString());
}
@Test
public void test16() {
Lunar lunar = new Lunar(1582, 9, 19, 12, 0, 0);
Assert.assertEquals("1582-10-15", lunar.getSolar().toString());
}
@Test
public void test17() {
Lunar lunar = new Lunar(2019, 12, 12, 11, 22, 0);
Assert.assertEquals("2020-01-06", lunar.getSolar().toString());
}
@Test
public void test18() {
Lunar lunar = new Lunar(2021, 12, 29);
Assert.assertEquals("除夕", lunar.getFestivals().get(0));
}
@Test
public void test19() {
Lunar lunar = new Lunar(2020, 12, 30);
Assert.assertEquals("除夕", lunar.getFestivals().get(0));
}
@Test
public void test20() {
Lunar lunar = new Lunar(2020, 12, 29);
Assert.assertEquals(0, lunar.getFestivals().size());
}
@Test
public void test21() {
Solar solar = Solar.fromYmd(2022, 1, 31);
Lunar lunar = solar.getLunar();
for(int i=-50;i<50;i++){
Assert.assertEquals("推移天数:"+i,solar.next(i).getLunar().toFullString(),lunar.next(i).toFullString());
Assert.assertEquals("除夕", lunar.getFestivals().get(0));
}
@Test
public void test22() {
Lunar lunar = Lunar.fromYmd(2033, -11, 1);
Assert.assertEquals("2033-12-22", lunar.getSolar().toYmd());
}
@Test
public void test23() {
Lunar lunar = Lunar.fromYmd(2022, 1, 1);
Assert.assertEquals("五黄土玉衡", lunar.getYearNineStar().toString());
}
@Test
public void test24() {
Lunar lunar = Lunar.fromYmd(2033, 1, 1);
Assert.assertEquals("三碧木天玑", lunar.getYearNineStar().toString());
}
@Test
public void test25() {
Solar solar = new Solar(2021, 6, 7, 21, 18, 0);
Lunar lunar = solar.getLunar();
Assert.assertEquals("二〇二一年四月廿七", lunar.toString());
}
@Test
public void test26() {
Lunar lunar = Lunar.fromYmdHms(2021, 6, 7, 21, 18, 0);
Solar solar = lunar.getSolar();
Assert.assertEquals("2021-07-16", solar.toString());
}
@Test
public void testNext() {
Solar solar = new Solar(2020, 1, 10, 12, 0, 0);
Lunar lunar = solar.getLunar();
for (int i = -50; i < 50; i++) {
Assert.assertEquals("推移天数:" + i, solar.next(i).getLunar().toFullString(), lunar.next(i).toFullString());
}
}
@Test
public void test27() {
Solar solar = Solar.fromYmd(1989, 4, 28);
Lunar lunar = solar.getLunar();
Assert.assertEquals(23, lunar.getDay());
}
@Test
public void test28() {
Solar solar = Solar.fromYmd(1990, 10, 8);
Lunar lunar = solar.getLunar();
Assert.assertEquals("乙酉", lunar.getMonthInGanZhiExact());
}
@Test
public void test29() {
Solar solar = Solar.fromYmd(1990, 10, 9);
Lunar lunar = solar.getLunar();
Assert.assertEquals("丙戌", lunar.getMonthInGanZhiExact());
}
@Test
public void test30() {
Solar solar = Solar.fromYmd(1990, 10, 8);
Lunar lunar = solar.getLunar();
Assert.assertEquals("丙戌", lunar.getMonthInGanZhi());
}
@Test
public void test31() {
Solar solar = Solar.fromYmdHms(1987, 4, 17, 9, 0, 0);
Lunar lunar = solar.getLunar();
Assert.assertEquals("一九八七年三月二十", lunar.toString());
}
@Test
public void test32() {
Lunar lunar = Lunar.fromYmd(2034, 1, 1);
Assert.assertEquals("2034-02-19", lunar.getSolar().toYmd());
}
@Test
public void test33() {
Lunar lunar = Lunar.fromYmd(2033, 12, 1);
Assert.assertEquals("2034-01-20", lunar.getSolar().toYmd());
}
@Test
public void test34() {
Lunar lunar = Lunar.fromYmd(37, -12, 1);
Assert.assertEquals("闰腊", lunar.getMonthInChinese());
}
@Test
public void test35() {
Lunar lunar = Lunar.fromYmd(56, -12, 1);
Assert.assertEquals("闰腊", lunar.getMonthInChinese());
lunar = Lunar.fromYmd(75, -11, 1);
Assert.assertEquals("闰冬", lunar.getMonthInChinese());
lunar = Lunar.fromYmd(94, -11, 1);
Assert.assertEquals("闰冬", lunar.getMonthInChinese());
lunar = Lunar.fromYmd(94, 12, 1);
Assert.assertEquals("腊", lunar.getMonthInChinese());
lunar = Lunar.fromYmd(113, 12, 1);
Assert.assertEquals("腊", lunar.getMonthInChinese());
lunar = Lunar.fromYmd(113, -12, 1);
Assert.assertEquals("闰腊", lunar.getMonthInChinese());
lunar = Lunar.fromYmd(5552, -12, 1);
Assert.assertEquals("闰腊", lunar.getMonthInChinese());
}
@Test
public void test36() {
Solar solar = Solar.fromYmd(5553, 1, 22);
Lunar lunar = solar.getLunar();
Assert.assertEquals("五五五二年闰腊月初二", lunar.toString());
}
@Test
public void test37() {
Solar solar = Solar.fromYmd(7013, 12, 24);
Lunar lunar = solar.getLunar();
Assert.assertEquals("七〇一三年闰冬月初四", lunar.toString());
}
@Test
public void test38() {
Lunar lunar = Lunar.fromYmd(7013, -11, 4);
Solar solar = lunar.getSolar();
Assert.assertEquals("7013-12-24", solar.toString());
}
@Test
public void test39() {
Solar solar = Solar.fromYmd(1987, 4, 12);
Lunar lunar = solar.getLunar();
Assert.assertEquals("一九八七年三月十五", lunar.toString());
}
@Test
public void test40() {
Solar solar = Solar.fromYmd(1987, 4, 13);
Lunar lunar = solar.getLunar();
Assert.assertEquals("一九八七年三月十六", lunar.toString());
}
@Test
public void test41() {
Solar solar = Solar.fromYmd(4, 2, 10);
Lunar lunar = solar.getLunar();
Assert.assertEquals("鼠", lunar.getYearShengXiao());
}
@Test
public void test42() {
Solar solar = Solar.fromYmd(4, 2, 9);
Lunar lunar = solar.getLunar();
Assert.assertEquals("猪", lunar.getYearShengXiao());
}
@Test
public void test43() {
Solar solar = Solar.fromYmd(1, 2, 12);
Lunar lunar = solar.getLunar();
Assert.assertEquals("鸡", lunar.getYearShengXiao());
}
@Test
public void test44() {
Solar solar = Solar.fromYmd(1, 1, 1);
Lunar lunar = solar.getLunar();
Assert.assertEquals("猴", lunar.getYearShengXiao());
}
@Test
public void test45() {
Solar solar = Solar.fromYmd(1946, 9, 30);
Lunar lunar = solar.getLunar();
Assert.assertEquals("一九四六年九月初六", lunar.toString());
}
@Test
public void test46() {
Solar solar = Solar.fromYmd(1946, 9, 29);
Lunar lunar = solar.getLunar();
Assert.assertEquals("一九四六年九月初五", lunar.toString());
}
@Test
public void test47() {
Solar solar = Solar.fromYmd(2017, 2, 15);
Lunar lunar = solar.getLunar();
Assert.assertEquals("子命互禄 辛命进禄", lunar.getDayLu());
}
}

View File

@@ -1,6 +1,7 @@
package test;
import com.nlf.calendar.Solar;
import com.nlf.calendar.util.SolarUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -44,6 +45,11 @@ public class SolarTest {
Assert.assertEquals("二六年三月初八",solar.getLunar().toString());
}
@Test
public void test10(){
Assert.assertEquals(false, SolarUtil.isLeapYear(1500));
}
@Test
public void testNext(){
Solar date = new Solar(2020,1,23);

View File

@@ -68,4 +68,11 @@ public class WuHouTest {
Assert.assertEquals(solar.toString(),"鹖鴠不鸣",lunar.getWuHou());
}
@Test
public void test9(){
Solar solar = new Solar(1982,12,22);
Lunar lunar = solar.getLunar();
Assert.assertEquals(solar.toString(),"蚯蚓结",lunar.getWuHou());
}
}

View File

@@ -1,5 +1,6 @@
package test;
import com.nlf.calendar.LunarYear;
import com.nlf.calendar.SolarYear;
import org.junit.Assert;
import org.junit.Test;
@@ -21,4 +22,43 @@ public class YearTest {
Assert.assertEquals("2020年",year.next(1).toFullString());
}
@Test
public void test1(){
LunarYear year = new LunarYear(2017);
Assert.assertEquals("二龙治水",year.getZhiShui());
year = new LunarYear(2018);
Assert.assertEquals("二龙治水",year.getZhiShui());
year = new LunarYear(2019);
Assert.assertEquals("八龙治水",year.getZhiShui());
year = new LunarYear(5);
Assert.assertEquals("三龙治水",year.getZhiShui());
}
@Test
public void test2(){
LunarYear year = new LunarYear(2017);
Assert.assertEquals("二人分饼",year.getFenBing());
year = new LunarYear(2018);
Assert.assertEquals("八人分饼",year.getFenBing());
year = new LunarYear(5);
Assert.assertEquals("一人分饼",year.getFenBing());
}
@Test
public void test3(){
LunarYear year = new LunarYear(2021);
Assert.assertEquals("十一牛耕田",year.getGengTian());
}
@Test
public void test4(){
LunarYear year = new LunarYear(2018);
Assert.assertEquals("三日得金",year.getDeJin());
}
}

View File

@@ -24,4 +24,33 @@ public class YunTest {
Assert.assertEquals("起运阳历", "1989-02-18", yun.getStartSolar().toYmd());
}
@Test
public void test2() {
Lunar lunar = new Lunar(2019, 12, 12, 11, 22, 0);
System.out.println(lunar.getMonth());
System.out.println(lunar.toFullString());
System.out.println(lunar.getSolar().toFullString());
EightChar eightChar = lunar.getEightChar();
Yun yun = eightChar.getYun(1);
Assert.assertEquals("起运年数", 0, yun.getStartYear());
Assert.assertEquals("起运月数", 1, yun.getStartMonth());
Assert.assertEquals("起运天数", 0, yun.getStartDay());
Assert.assertEquals("起运阳历", "2020-02-06", yun.getStartSolar().toYmd());
}
@Test
public void test3() {
Solar solar = new Solar(2020, 1, 6, 11, 22, 0);
Lunar lunar = solar.getLunar();
System.out.println(lunar.getMonth());
System.out.println(lunar.toFullString());
System.out.println(lunar.getSolar().toFullString());
EightChar eightChar = lunar.getEightChar();
Yun yun = eightChar.getYun(1);
Assert.assertEquals("起运年数", 0, yun.getStartYear());
Assert.assertEquals("起运月数", 1, yun.getStartMonth());
Assert.assertEquals("起运天数", 0, yun.getStartDay());
Assert.assertEquals("起运阳历", "2020-02-06", yun.getStartSolar().toYmd());
}
}