fs = TaoUtil.FESTIVAL.get(getMonth() + "-" + getDay());
75 | if (null != fs) {
76 | l.addAll(fs);
77 | }
78 | String jq = lunar.getJieQi();
79 | if ("冬至".equals(jq)) {
80 | l.add(new TaoFestival("元始天尊圣诞"));
81 | } else if ("夏至".equals(jq)) {
82 | l.add(new TaoFestival("灵宝天尊圣诞"));
83 | }
84 | // 八节日
85 | String f = TaoUtil.BA_JIE.get(jq);
86 | if (null != f) {
87 | l.add(new TaoFestival(f));
88 | }
89 | // 八会日
90 | f = TaoUtil.BA_HUI.get(lunar.getDayInGanZhi());
91 | if (null != f) {
92 | l.add(new TaoFestival(f));
93 | }
94 | return l;
95 | }
96 |
97 | private boolean isDayIn(String[] days) {
98 | String md = getMonth() + "-" + getDay();
99 | for (String d : days) {
100 | if (md.equals(d)) {
101 | return true;
102 | }
103 | }
104 | return false;
105 | }
106 |
107 | /**
108 | * 是否三会日
109 | *
110 | * @return true/false
111 | */
112 | public boolean isDaySanHui() {
113 | return isDayIn(TaoUtil.SAN_HUI);
114 | }
115 |
116 | /**
117 | * 是否三元日
118 | *
119 | * @return true/false
120 | */
121 | public boolean isDaySanYuan() {
122 | return isDayIn(TaoUtil.SAN_YUAN);
123 | }
124 |
125 | /**
126 | * 是否八节日
127 | *
128 | * @return true/false
129 | */
130 | public boolean isDayBaJie() {
131 | return TaoUtil.BA_JIE.containsKey(lunar.getJieQi());
132 | }
133 |
134 | /**
135 | * 是否五腊日
136 | *
137 | * @return true/false
138 | */
139 | public boolean isDayWuLa() {
140 | return isDayIn(TaoUtil.WU_LA);
141 | }
142 |
143 | /**
144 | * 是否八会日
145 | *
146 | * @return true/false
147 | */
148 | public boolean isDayBaHui() {
149 | return TaoUtil.BA_HUI.containsKey(lunar.getDayInGanZhi());
150 | }
151 |
152 | /**
153 | * 是否明戊日
154 | *
155 | * @return true/false
156 | */
157 | public boolean isDayMingWu() {
158 | return "戊".equals(lunar.getDayGan());
159 | }
160 |
161 | /**
162 | * 是否暗戊日
163 | *
164 | * @return true/false
165 | */
166 | public boolean isDayAnWu() {
167 | return lunar.getDayZhi().equals(TaoUtil.AN_WU[Math.abs(getMonth()) - 1]);
168 | }
169 |
170 | /**
171 | * 是否戊日
172 | *
173 | * @return true/false
174 | */
175 | public boolean isDayWu() {
176 | return isDayMingWu() || isDayAnWu();
177 | }
178 |
179 | /**
180 | * 是否天赦日
181 | *
182 | * @return true/false
183 | */
184 | public boolean isDayTianShe() {
185 | boolean ret = false;
186 | String mz = lunar.getMonthZhi();
187 | String dgz = lunar.getDayInGanZhi();
188 | if ("寅卯辰".contains(mz)) {
189 | if ("戊寅".equals(dgz)) {
190 | ret = true;
191 | }
192 | } else if ("巳午未".contains(mz)) {
193 | if ("甲午".equals(dgz)) {
194 | ret = true;
195 | }
196 | } else if ("申酉戌".contains(mz)) {
197 | if ("戊申".equals(dgz)) {
198 | ret = true;
199 | }
200 | } else if ("亥子丑".contains(mz)) {
201 | if ("甲子".equals(dgz)) {
202 | ret = true;
203 | }
204 | }
205 | return ret;
206 | }
207 |
208 | @Override
209 | public String toString() {
210 | return String.format("%s年%s月%s", getYearInChinese(), getMonthInChinese(), getDayInChinese());
211 | }
212 |
213 | public String toFullString() {
214 | return String.format("道歷%s年,天運%s年,%s月,%s日。%s月%s日,%s時。", getYearInChinese(), lunar.getYearInGanZhi(), lunar.getMonthInGanZhi(), lunar.getDayInGanZhi(), getMonthInChinese(), getDayInChinese(), lunar.getTimeZhi());
215 | }
216 |
217 | }
218 |
--------------------------------------------------------------------------------
/src/main/java/com/nlf/calendar/TaoFestival.java:
--------------------------------------------------------------------------------
1 | package com.nlf.calendar;
2 |
3 | /**
4 | * 道历节日
5 | *
6 | * @author 6tail
7 | */
8 | public class TaoFestival {
9 |
10 | /**
11 | * 名称
12 | */
13 | private final String name;
14 |
15 | /**
16 | * 备注
17 | */
18 | private final String remark;
19 |
20 | public TaoFestival(String name, String remark) {
21 | this.name = name;
22 | this.remark = null == remark ? "" : remark;
23 | }
24 |
25 | public TaoFestival(String name) {
26 | this(name, null);
27 | }
28 |
29 | public String getName() {
30 | return name;
31 | }
32 |
33 | public String getRemark() {
34 | return remark;
35 | }
36 |
37 | @Override
38 | public String toString() {
39 | return name;
40 | }
41 |
42 | public String toFullString() {
43 | StringBuilder s = new StringBuilder();
44 | s.append(name);
45 | if (null != remark && remark.length() > 0) {
46 | s.append("[");
47 | s.append(remark);
48 | s.append("]");
49 | }
50 | return s.toString();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/nlf/calendar/eightchar/DaYun.java:
--------------------------------------------------------------------------------
1 | package com.nlf.calendar.eightchar;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.util.LunarUtil;
5 |
6 | /**
7 | * 大运
8 | *
9 | * @author 6tail
10 | */
11 | public class DaYun {
12 | /**
13 | * 开始年(含)
14 | */
15 | private final int startYear;
16 |
17 | /**
18 | * 结束年(含)
19 | */
20 | private final int endYear;
21 |
22 | /**
23 | * 开始年龄(含)
24 | */
25 | private final int startAge;
26 |
27 | /**
28 | * 结束年龄(含)
29 | */
30 | private final int endAge;
31 |
32 | /**
33 | * 序数,0-9
34 | */
35 | private final int index;
36 |
37 | /**
38 | * 运
39 | */
40 | private final Yun yun;
41 |
42 | private final Lunar lunar;
43 |
44 | public DaYun(Yun yun, int index) {
45 | this.yun = yun;
46 | this.lunar = yun.getLunar();
47 | this.index = index;
48 | int birthYear = lunar.getSolar().getYear();
49 | int year = yun.getStartSolar().getYear();
50 | if (index < 1) {
51 | this.startYear = birthYear;
52 | this.startAge = 1;
53 | this.endYear = year - 1;
54 | this.endAge = year - birthYear;
55 | } else {
56 | int add = (index - 1) * 10;
57 | this.startYear = year + add;
58 | this.startAge = this.startYear - birthYear + 1;
59 | this.endYear = this.startYear + 9;
60 | this.endAge = this.startAge + 9;
61 | }
62 | }
63 |
64 | public int getStartYear() {
65 | return startYear;
66 | }
67 |
68 | public int getEndYear() {
69 | return endYear;
70 | }
71 |
72 | public int getStartAge() {
73 | return startAge;
74 | }
75 |
76 | public int getEndAge() {
77 | return endAge;
78 | }
79 |
80 | public int getIndex() {
81 | return index;
82 | }
83 |
84 | public Lunar getLunar() {
85 | return lunar;
86 | }
87 |
88 | /**
89 | * 获取干支
90 | *
91 | * @return 干支
92 | */
93 | public String getGanZhi() {
94 | if (index < 1) {
95 | return "";
96 | }
97 | int offset = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact());
98 | offset += yun.isForward() ? index : -index;
99 | int size = LunarUtil.JIA_ZI.length;
100 | if (offset >= size) {
101 | offset -= size;
102 | }
103 | if (offset < 0) {
104 | offset += size;
105 | }
106 | return LunarUtil.JIA_ZI[offset];
107 | }
108 |
109 | /**
110 | * 获取所在旬
111 | * @return 旬
112 | */
113 | public String getXun(){
114 | return LunarUtil.getXun(getGanZhi());
115 | }
116 |
117 | /**
118 | * 获取旬空(空亡)
119 | * @return 旬空(空亡)
120 | */
121 | public String getXunKong(){
122 | return LunarUtil.getXunKong(getGanZhi());
123 | }
124 |
125 | /**
126 | * 获取10轮流年
127 | *
128 | * @return 流年
129 | */
130 | public LiuNian[] getLiuNian() {
131 | return getLiuNian(10);
132 | }
133 |
134 | /**
135 | * 获取流年
136 | *
137 | * @param n 轮数
138 | * @return 流年
139 | */
140 | public LiuNian[] getLiuNian(int n) {
141 | if (index < 1) {
142 | n = endYear-startYear+1;
143 | }
144 | LiuNian[] l = new LiuNian[n];
145 | for (int i = 0; i < n; i++) {
146 | l[i] = new LiuNian(this, i);
147 | }
148 | return l;
149 | }
150 |
151 | /**
152 | * 获取10轮小运
153 | *
154 | * @return 小运
155 | */
156 | public XiaoYun[] getXiaoYun() {
157 | return getXiaoYun(10);
158 | }
159 |
160 | /**
161 | * 获取小运
162 | * @param n 轮数
163 | * @return 小运
164 | */
165 | public XiaoYun[] getXiaoYun(int n) {
166 | if (index < 1) {
167 | n = endYear-startYear+1;
168 | }
169 | XiaoYun[] l = new XiaoYun[n];
170 | for (int i = 0; i < n; i++) {
171 | l[i] = new XiaoYun(this, i, yun.isForward());
172 | }
173 | return l;
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/src/main/java/com/nlf/calendar/eightchar/LiuNian.java:
--------------------------------------------------------------------------------
1 | package com.nlf.calendar.eightchar;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.util.LunarUtil;
5 |
6 | /**
7 | * 流年
8 | *
9 | * @author 6tail
10 | */
11 | public class LiuNian {
12 | /**
13 | * 序数,0-9
14 | */
15 | private final int index;
16 |
17 | /**
18 | * 大运
19 | */
20 | private final DaYun daYun;
21 |
22 | /**
23 | * 年
24 | */
25 | private final int year;
26 |
27 | /**
28 | * 年龄
29 | */
30 | private final int age;
31 |
32 | private final Lunar lunar;
33 |
34 | public LiuNian(DaYun daYun, int index) {
35 | this.daYun = daYun;
36 | this.lunar = daYun.getLunar();
37 | this.index = index;
38 | this.year = daYun.getStartYear() + index;
39 | this.age = daYun.getStartAge() + index;
40 | }
41 |
42 | public int getIndex() {
43 | return index;
44 | }
45 |
46 | public int getYear() {
47 | return year;
48 | }
49 |
50 | public int getAge() {
51 | return age;
52 | }
53 |
54 | /**
55 | * 获取干支
56 | *
57 | * @return 干支
58 | */
59 | public String getGanZhi() {
60 | // 干支与出生日期和起运日期都没关系
61 | int offset = LunarUtil.getJiaZiIndex(lunar.getJieQiTable().get("立春").getLunar().getYearInGanZhiExact()) + this.index;
62 | if (daYun.getIndex() > 0) {
63 | offset += daYun.getStartAge() - 1;
64 | }
65 | offset %= LunarUtil.JIA_ZI.length;
66 | return LunarUtil.JIA_ZI[offset];
67 | }
68 |
69 | /**
70 | * 获取所在旬
71 | * @return 旬
72 | */
73 | public String getXun(){
74 | return LunarUtil.getXun(getGanZhi());
75 | }
76 |
77 | /**
78 | * 获取旬空(空亡)
79 | * @return 旬空(空亡)
80 | */
81 | public String getXunKong(){
82 | return LunarUtil.getXunKong(getGanZhi());
83 | }
84 |
85 | /**
86 | * 获取流月
87 | * @return 流月
88 | */
89 | public LiuYue[] getLiuYue() {
90 | int n = 12;
91 | LiuYue[] l = new LiuYue[n];
92 | for (int i = 0; i < n; i++) {
93 | l[i] = new LiuYue(this, i);
94 | }
95 | return l;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/com/nlf/calendar/eightchar/LiuYue.java:
--------------------------------------------------------------------------------
1 | package com.nlf.calendar.eightchar;
2 |
3 | import com.nlf.calendar.util.LunarUtil;
4 |
5 | /**
6 | * 流月
7 | *
8 | * @author 6tail
9 | */
10 | public class LiuYue {
11 | /**
12 | * 序数,0-11
13 | */
14 | private final int index;
15 |
16 | private final LiuNian liuNian;
17 |
18 | public LiuYue(LiuNian liuNian, int index) {
19 | this.liuNian = liuNian;
20 | this.index = index;
21 | }
22 |
23 | public int getIndex() {
24 | return index;
25 | }
26 |
27 | /**
28 | * 获取中文的月
29 | *
30 | * @return 中文月,如正
31 | */
32 | public String getMonthInChinese() {
33 | return LunarUtil.MONTH[index + 1];
34 | }
35 |
36 | /**
37 | * 获取干支
38 | *
39 | * 《五虎遁》
40 | * 甲己之年丙作首,
41 | * 乙庚之年戊为头,
42 | * 丙辛之年寻庚上,
43 | * 丁壬壬寅顺水流,
44 | * 若问戊癸何处走,
45 | * 甲寅之上好追求。
46 | *
47 | * @return 干支
48 | */
49 | public String getGanZhi() {
50 | int offset = 0;
51 | String yearGan = liuNian.getGanZhi().substring(0, 1);
52 | if ("甲".equals(yearGan) || "己".equals(yearGan)) {
53 | offset = 2;
54 | } else if ("乙".equals(yearGan) || "庚".equals(yearGan)) {
55 | offset = 4;
56 | } else if ("丙".equals(yearGan) || "辛".equals(yearGan)) {
57 | offset = 6;
58 | } else if ("丁".equals(yearGan) || "壬".equals(yearGan)) {
59 | offset = 8;
60 | }
61 | String gan = LunarUtil.GAN[(index + offset) % 10 + 1];
62 | String zhi = LunarUtil.ZHI[(index + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12 + 1];
63 | return gan + zhi;
64 | }
65 |
66 | /**
67 | * 获取所在旬
68 | * @return 旬
69 | */
70 | public String getXun(){
71 | return LunarUtil.getXun(getGanZhi());
72 | }
73 |
74 | /**
75 | * 获取旬空(空亡)
76 | * @return 旬空(空亡)
77 | */
78 | public String getXunKong(){
79 | return LunarUtil.getXunKong(getGanZhi());
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/nlf/calendar/eightchar/XiaoYun.java:
--------------------------------------------------------------------------------
1 | package com.nlf.calendar.eightchar;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.util.LunarUtil;
5 |
6 | /**
7 | * 小运
8 | *
9 | * @author 6tail
10 | */
11 | public class XiaoYun {
12 | /**
13 | * 序数,0-9
14 | */
15 | private final int index;
16 |
17 | /**
18 | * 大运
19 | */
20 | private final DaYun daYun;
21 |
22 | /**
23 | * 年
24 | */
25 | private final int year;
26 |
27 | /**
28 | * 年龄
29 | */
30 | private final int age;
31 |
32 | /**
33 | * 是否顺推
34 | */
35 | private final boolean forward;
36 |
37 | private final Lunar lunar;
38 |
39 | public XiaoYun(DaYun daYun, int index, boolean forward) {
40 | this.daYun = daYun;
41 | this.lunar = daYun.getLunar();
42 | this.index = index;
43 | this.year = daYun.getStartYear() + index;
44 | this.age = daYun.getStartAge() + index;
45 | this.forward = forward;
46 | }
47 |
48 | public int getIndex() {
49 | return index;
50 | }
51 |
52 | public int getYear() {
53 | return year;
54 | }
55 |
56 | public int getAge() {
57 | return age;
58 | }
59 |
60 | /**
61 | * 获取干支
62 | *
63 | * @return 干支
64 | */
65 | public String getGanZhi() {
66 | int offset = LunarUtil.getJiaZiIndex(lunar.getTimeInGanZhi());
67 | int add = this.index + 1;
68 | if (daYun.getIndex() > 0) {
69 | add += daYun.getStartAge() - 1;
70 | }
71 | offset += forward ? add : -add;
72 | int size = LunarUtil.JIA_ZI.length;
73 | while (offset < 0) {
74 | offset += size;
75 | }
76 | offset %= size;
77 | return LunarUtil.JIA_ZI[offset];
78 | }
79 |
80 | /**
81 | * 获取所在旬
82 | * @return 旬
83 | */
84 | public String getXun(){
85 | return LunarUtil.getXun(getGanZhi());
86 | }
87 |
88 | /**
89 | * 获取旬空(空亡)
90 | * @return 旬空(空亡)
91 | */
92 | public String getXunKong(){
93 | return LunarUtil.getXunKong(getGanZhi());
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/com/nlf/calendar/eightchar/Yun.java:
--------------------------------------------------------------------------------
1 | package com.nlf.calendar.eightchar;
2 |
3 | import com.nlf.calendar.EightChar;
4 | import com.nlf.calendar.JieQi;
5 | import com.nlf.calendar.Lunar;
6 | import com.nlf.calendar.Solar;
7 | import com.nlf.calendar.util.LunarUtil;
8 |
9 | /**
10 | * 运
11 | *
12 | * @author 6tail
13 | */
14 | public class Yun {
15 | /**
16 | * 性别(1男,0女)
17 | */
18 | private final int gender;
19 |
20 | /**
21 | * 起运年数
22 | */
23 | private int startYear;
24 |
25 | /**
26 | * 起运月数
27 | */
28 | private int startMonth;
29 |
30 | /**
31 | * 起运天数
32 | */
33 | private int startDay;
34 |
35 | /**
36 | * 起运小时数
37 | */
38 | private int startHour;
39 |
40 | /**
41 | * 是否顺推
42 | */
43 | private final boolean forward;
44 |
45 | private final Lunar lunar;
46 |
47 | /**
48 | * 使用默认流派1初始化运
49 | * @param eightChar 八字
50 | * @param gender 性别,1男,0女
51 | */
52 | public Yun(EightChar eightChar, int gender) {
53 | this(eightChar, gender, 1);
54 | }
55 |
56 | /**
57 | * 初始化运
58 | * @param eightChar 八字
59 | * @param gender 性别,1男,0女
60 | * @param sect 流派,1按天数和时辰数计算,3天1年,1天4个月,1时辰10天;2按分钟数计算
61 | */
62 | public Yun(EightChar eightChar, int gender, int sect) {
63 | this.lunar = eightChar.getLunar();
64 | this.gender = gender;
65 | // 阳
66 | boolean yang = 0 == lunar.getYearGanIndexExact() % 2;
67 | // 男
68 | boolean man = 1 == gender;
69 | forward = (yang && man) || (!yang && !man);
70 | computeStart(sect);
71 | }
72 |
73 | /**
74 | * 起运计算
75 | */
76 | private void computeStart(int sect) {
77 | // 上节
78 | JieQi prev = lunar.getPrevJie();
79 | // 下节
80 | JieQi next = lunar.getNextJie();
81 | // 出生日期
82 | Solar current = lunar.getSolar();
83 | // 阳男阴女顺推,阴男阳女逆推
84 | Solar start = forward ? current : prev.getSolar();
85 | Solar end = forward ? next.getSolar() : current;
86 |
87 | int year;
88 | int month;
89 | int day;
90 | int hour = 0;
91 |
92 | if (2 == sect) {
93 | long minutes = end.subtractMinute(start);
94 | long y = minutes / 4320;
95 | minutes -= y * 4320;
96 | long m = minutes / 360;
97 | minutes -= m * 360;
98 | long d = minutes / 12;
99 | minutes -= d * 12;
100 | long h = minutes * 2;
101 | year = (int)y;
102 | month = (int)m;
103 | day = (int)d;
104 | hour = (int)h;
105 | } else {
106 | int endTimeZhiIndex = (end.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(end.toYmdHms().substring(11, 16));
107 | int startTimeZhiIndex = (start.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(start.toYmdHms().substring(11, 16));
108 | // 时辰差
109 | int hourDiff = endTimeZhiIndex - startTimeZhiIndex;
110 | // 天数差
111 | int dayDiff = end.subtract(start);
112 | if (hourDiff < 0) {
113 | hourDiff += 12;
114 | dayDiff--;
115 | }
116 | int monthDiff = hourDiff * 10 / 30;
117 | month = dayDiff * 4 + monthDiff;
118 | day = hourDiff * 10 - monthDiff * 30;
119 | year = month / 12;
120 | month = month - year * 12;
121 | }
122 | this.startYear = year;
123 | this.startMonth = month;
124 | this.startDay = day;
125 | this.startHour = hour;
126 | }
127 |
128 | /**
129 | * 获取性别
130 | *
131 | * @return 性别(1男 , 0女)
132 | */
133 | public int getGender() {
134 | return gender;
135 | }
136 |
137 | /**
138 | * 获取起运年数
139 | *
140 | * @return 起运年数
141 | */
142 | public int getStartYear() {
143 | return startYear;
144 | }
145 |
146 | /**
147 | * 获取起运月数
148 | *
149 | * @return 起运月数
150 | */
151 | public int getStartMonth() {
152 | return startMonth;
153 | }
154 |
155 | /**
156 | * 获取起运天数
157 | *
158 | * @return 起运天数
159 | */
160 | public int getStartDay() {
161 | return startDay;
162 | }
163 |
164 | /**
165 | * 获取起运小时数
166 | *
167 | * @return 起运小时数
168 | */
169 | public int getStartHour() {
170 | return startHour;
171 | }
172 |
173 | /**
174 | * 是否顺推
175 | *
176 | * @return true/false
177 | */
178 | public boolean isForward() {
179 | return forward;
180 | }
181 |
182 | public Lunar getLunar() {
183 | return lunar;
184 | }
185 |
186 | /**
187 | * 获取起运的阳历日期
188 | *
189 | * @return 阳历日期
190 | */
191 | public Solar getStartSolar() {
192 | Solar solar = lunar.getSolar();
193 | solar = solar.nextYear(startYear);
194 | solar = solar.nextMonth(startMonth);
195 | solar = solar.next(startDay);
196 | return solar.nextHour(startHour);
197 | }
198 |
199 | /**
200 | * 获取10轮大运
201 | *
202 | * @return 大运
203 | */
204 | public DaYun[] getDaYun() {
205 | return getDaYun(10);
206 | }
207 |
208 | /**
209 | * 获取大运
210 | *
211 | * @param n 轮数
212 | * @return 大运
213 | */
214 | public DaYun[] getDaYun(int n) {
215 | DaYun[] l = new DaYun[n];
216 | for (int i = 0; i < n; i++) {
217 | l[i] = new DaYun(this, i);
218 | }
219 | return l;
220 | }
221 | }
222 |
223 |
--------------------------------------------------------------------------------
/src/main/java/com/nlf/calendar/util/SolarUtil.java:
--------------------------------------------------------------------------------
1 | package com.nlf.calendar.util;
2 |
3 | import com.nlf.calendar.Solar;
4 |
5 | import java.util.*;
6 |
7 | /**
8 | * 阳历工具
9 | *
10 | * @author 6tail
11 | */
12 | public class SolarUtil {
13 | /**
14 | * 星期
15 | */
16 | public static final String[] WEEK = {"日", "一", "二", "三", "四", "五", "六"};
17 | /**
18 | * 每月天数
19 | */
20 | public static final int[] DAYS_OF_MONTH = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
21 | /**
22 | * 星座
23 | */
24 | public static final String[] XINGZUO = {"白羊", "金牛", "双子", "巨蟹", "狮子", "处女", "天秤", "天蝎", "射手", "摩羯", "水瓶", "双鱼"};
25 | /**
26 | * 日期对应的节日
27 | */
28 | public static final Map FESTIVAL = new HashMap() {
29 | private static final long serialVersionUID = -1;
30 |
31 | {
32 | put("1-1", "元旦节");
33 | put("2-14", "情人节");
34 | put("3-8", "妇女节");
35 | put("3-12", "植树节");
36 | put("3-15", "消费者权益日");
37 | put("4-1", "愚人节");
38 | put("5-1", "劳动节");
39 | put("5-4", "青年节");
40 | put("6-1", "儿童节");
41 | put("7-1", "建党节");
42 | put("8-1", "建军节");
43 | put("9-10", "教师节");
44 | put("10-1", "国庆节");
45 | put("10-31", "万圣节前夜");
46 | put("11-1", "万圣节");
47 | put("12-24", "平安夜");
48 | put("12-25", "圣诞节");
49 | }
50 | };
51 | /**
52 | * 几月第几个星期几对应的节日
53 | */
54 | public static final Map WEEK_FESTIVAL = new HashMap() {
55 | private static final long serialVersionUID = -1;
56 |
57 | {
58 | put("3-0-1", "全国中小学生安全教育日");
59 | put("5-2-0", "母亲节");
60 | put("6-3-0", "父亲节");
61 | put("11-4-4", "感恩节");
62 | }
63 | };
64 | /**
65 | * 日期对应的非正式节日
66 | */
67 | public static final Map> OTHER_FESTIVAL = new HashMap>() {
68 | private static final long serialVersionUID = -1;
69 |
70 | {
71 | put("1-8", Collections.nCopies(1, "周恩来逝世纪念日"));
72 | put("1-10", Collections.nCopies(1, "中国人民警察节"));
73 | put("1-14", Collections.nCopies(1, "日记情人节"));
74 | put("1-21", Collections.nCopies(1, "列宁逝世纪念日"));
75 | put("1-26", Collections.nCopies(1, "国际海关日"));
76 | put("1-27", Collections.nCopies(1, "国际大屠杀纪念日"));
77 | put("2-2", Collections.nCopies(1, "世界湿地日"));
78 | put("2-4", Collections.nCopies(1, "世界抗癌日"));
79 | put("2-7", Collections.nCopies(1, "京汉铁路罢工纪念日"));
80 | put("2-10", Collections.nCopies(1, "国际气象节"));
81 | put("2-19", Collections.nCopies(1, "邓小平逝世纪念日"));
82 | put("2-20", Collections.nCopies(1, "世界社会公正日"));
83 | put("2-21", Collections.nCopies(1, "国际母语日"));
84 | put("2-24", Collections.nCopies(1, "第三世界青年日"));
85 | put("3-1", Collections.nCopies(1, "国际海豹日"));
86 | put("3-3", Arrays.asList("世界野生动植物日", "全国爱耳日"));
87 | put("3-5", Arrays.asList("周恩来诞辰纪念日", "中国青年志愿者服务日"));
88 | put("3-6", Collections.nCopies(1, "世界青光眼日"));
89 | put("3-7", Collections.nCopies(1, "女生节"));
90 | put("3-12", Collections.nCopies(1, "孙中山逝世纪念日"));
91 | put("3-14", Arrays.asList("马克思逝世纪念日", "白色情人节"));
92 | put("3-17", Collections.nCopies(1, "国际航海日"));
93 | put("3-18", Arrays.asList("全国科技人才活动日", "全国爱肝日"));
94 | put("3-20", Collections.nCopies(1, "国际幸福日"));
95 | put("3-21", Arrays.asList("世界森林日", "世界睡眠日", "国际消除种族歧视日"));
96 | put("3-22", Collections.nCopies(1, "世界水日"));
97 | put("3-23", Collections.nCopies(1, "世界气象日"));
98 | put("3-24", Collections.nCopies(1, "世界防治结核病日"));
99 | put("3-29", Collections.nCopies(1, "中国黄花岗七十二烈士殉难纪念日"));
100 | put("4-2", Arrays.asList("国际儿童图书日", "世界自闭症日"));
101 | put("4-4", Collections.nCopies(1, "国际地雷行动日"));
102 | put("4-7", Collections.nCopies(1, "世界卫生日"));
103 | put("4-8", Collections.nCopies(1, "国际珍稀动物保护日"));
104 | put("4-12", Collections.nCopies(1, "世界航天日"));
105 | put("4-14", Collections.nCopies(1, "黑色情人节"));
106 | put("4-15", Collections.nCopies(1, "全民国家安全教育日"));
107 | put("4-22", Arrays.asList("世界地球日", "列宁诞辰纪念日"));
108 | put("4-23", Collections.nCopies(1, "世界读书日"));
109 | put("4-24", Collections.nCopies(1, "中国航天日"));
110 | put("4-25", Collections.nCopies(1, "儿童预防接种宣传日"));
111 | put("4-26", Arrays.asList("世界知识产权日", "全国疟疾日"));
112 | put("4-28", Collections.nCopies(1, "世界安全生产与健康日"));
113 | put("4-30", Collections.nCopies(1, "全国交通安全反思日"));
114 | put("5-2", Collections.nCopies(1, "世界金枪鱼日"));
115 | put("5-3", Collections.nCopies(1, "世界新闻自由日"));
116 | put("5-5", Collections.nCopies(1, "马克思诞辰纪念日"));
117 | put("5-8", Collections.nCopies(1, "世界红十字日"));
118 | put("5-11", Collections.nCopies(1, "世界肥胖日"));
119 | put("5-12", Arrays.asList("全国防灾减灾日", "护士节"));
120 | put("5-14", Collections.nCopies(1, "玫瑰情人节"));
121 | put("5-15", Collections.nCopies(1, "国际家庭日"));
122 | put("5-19", Collections.nCopies(1, "中国旅游日"));
123 | put("5-20", Collections.nCopies(1, "网络情人节"));
124 | put("5-22", Collections.nCopies(1, "国际生物多样性日"));
125 | put("5-25", Collections.nCopies(1, "525心理健康节"));
126 | put("5-27", Collections.nCopies(1, "上海解放日"));
127 | put("5-29", Collections.nCopies(1, "国际维和人员日"));
128 | put("5-30", Collections.nCopies(1, "中国五卅运动纪念日"));
129 | put("5-31", Collections.nCopies(1, "世界无烟日"));
130 | put("6-3", Collections.nCopies(1, "世界自行车日"));
131 | put("6-5", Collections.nCopies(1, "世界环境日"));
132 | put("6-6", Collections.nCopies(1, "全国爱眼日"));
133 | put("6-8", Collections.nCopies(1, "世界海洋日"));
134 | put("6-11", Collections.nCopies(1, "中国人口日"));
135 | put("6-14", Arrays.asList("世界献血日", "亲亲情人节"));
136 | put("6-17", Collections.nCopies(1, "世界防治荒漠化与干旱日"));
137 | put("6-20", Collections.nCopies(1, "世界难民日"));
138 | put("6-21", Collections.nCopies(1, "国际瑜伽日"));
139 | put("6-25", Collections.nCopies(1, "全国土地日"));
140 | put("6-26", Arrays.asList("国际禁毒日", "联合国宪章日"));
141 | put("7-1", Collections.nCopies(1, "香港回归纪念日"));
142 | put("7-6", Arrays.asList("国际接吻日", "朱德逝世纪念日"));
143 | put("7-7", Collections.nCopies(1, "七七事变纪念日"));
144 | put("7-11", Arrays.asList("世界人口日", "中国航海日"));
145 | put("7-14", Collections.nCopies(1, "银色情人节"));
146 | put("7-18", Collections.nCopies(1, "曼德拉国际日"));
147 | put("7-30", Collections.nCopies(1, "国际友谊日"));
148 | put("8-3", Collections.nCopies(1, "男人节"));
149 | put("8-5", Collections.nCopies(1, "恩格斯逝世纪念日"));
150 | put("8-6", Collections.nCopies(1, "国际电影节"));
151 | put("8-8", Collections.nCopies(1, "全民健身日"));
152 | put("8-9", Collections.nCopies(1, "国际土著人日"));
153 | put("8-12", Collections.nCopies(1, "国际青年节"));
154 | put("8-14", Collections.nCopies(1, "绿色情人节"));
155 | put("8-19", Arrays.asList("世界人道主义日", "中国医师节"));
156 | put("8-22", Collections.nCopies(1, "邓小平诞辰纪念日"));
157 | put("8-29", Collections.nCopies(1, "全国测绘法宣传日"));
158 | put("9-3", Collections.nCopies(1, "中国抗日战争胜利纪念日"));
159 | put("9-5", Collections.nCopies(1, "中华慈善日"));
160 | put("9-8", Collections.nCopies(1, "世界扫盲日"));
161 | put("9-9", Arrays.asList("毛泽东逝世纪念日", "全国拒绝酒驾日"));
162 | put("9-14", Arrays.asList("世界清洁地球日", "相片情人节"));
163 | put("9-15", Collections.nCopies(1, "国际民主日"));
164 | put("9-16", Collections.nCopies(1, "国际臭氧层保护日"));
165 | put("9-17", Collections.nCopies(1, "世界骑行日"));
166 | put("9-18", Collections.nCopies(1, "九一八事变纪念日"));
167 | put("9-20", Collections.nCopies(1, "全国爱牙日"));
168 | put("9-21", Collections.nCopies(1, "国际和平日"));
169 | put("9-27", Collections.nCopies(1, "世界旅游日"));
170 | put("9-30", Collections.nCopies(1, "中国烈士纪念日"));
171 | put("10-1", Collections.nCopies(1, "国际老年人日"));
172 | put("10-2", Collections.nCopies(1, "国际非暴力日"));
173 | put("10-4", Collections.nCopies(1, "世界动物日"));
174 | put("10-11", Collections.nCopies(1, "国际女童日"));
175 | put("10-10", Collections.nCopies(1, "辛亥革命纪念日"));
176 | put("10-13", Arrays.asList("国际减轻自然灾害日", "中国少年先锋队诞辰日"));
177 | put("10-14", Collections.nCopies(1, "葡萄酒情人节"));
178 | put("10-16", Collections.nCopies(1, "世界粮食日"));
179 | put("10-17", Collections.nCopies(1, "全国扶贫日"));
180 | put("10-20", Collections.nCopies(1, "世界统计日"));
181 | put("10-24", Arrays.asList("世界发展信息日", "程序员节"));
182 | put("10-25", Collections.nCopies(1, "抗美援朝纪念日"));
183 | put("11-5", Collections.nCopies(1, "世界海啸日"));
184 | put("11-8", Collections.nCopies(1, "记者节"));
185 | put("11-9", Collections.nCopies(1, "全国消防日"));
186 | put("11-11", Collections.nCopies(1, "光棍节"));
187 | put("11-12", Collections.nCopies(1, "孙中山诞辰纪念日"));
188 | put("11-14", Collections.nCopies(1, "电影情人节"));
189 | put("11-16", Collections.nCopies(1, "国际宽容日"));
190 | put("11-17", Collections.nCopies(1, "国际大学生节"));
191 | put("11-19", Collections.nCopies(1, "世界厕所日"));
192 | put("11-28", Collections.nCopies(1, "恩格斯诞辰纪念日"));
193 | put("11-29", Collections.nCopies(1, "国际声援巴勒斯坦人民日"));
194 | put("12-1", Collections.nCopies(1, "世界艾滋病日"));
195 | put("12-2", Collections.nCopies(1, "全国交通安全日"));
196 | put("12-3", Collections.nCopies(1, "世界残疾人日"));
197 | put("12-4", Collections.nCopies(1, "全国法制宣传日"));
198 | put("12-5", Arrays.asList("世界弱能人士日", "国际志愿人员日"));
199 | put("12-7", Collections.nCopies(1, "国际民航日"));
200 | put("12-9", Arrays.asList("世界足球日", "国际反腐败日"));
201 | put("12-10", Collections.nCopies(1, "世界人权日"));
202 | put("12-11", Collections.nCopies(1, "国际山岳日"));
203 | put("12-12", Collections.nCopies(1, "西安事变纪念日"));
204 | put("12-13", Collections.nCopies(1, "国家公祭日"));
205 | put("12-14", Collections.nCopies(1, "拥抱情人节"));
206 | put("12-18", Collections.nCopies(1, "国际移徙者日"));
207 | put("12-26", Collections.nCopies(1, "毛泽东诞辰纪念日"));
208 | }
209 | };
210 |
211 | protected SolarUtil() {
212 | }
213 |
214 | /**
215 | * 是否闰年
216 | *
217 | * @param year 年
218 | * @return true/false 闰年/非闰年
219 | */
220 | public static boolean isLeapYear(int year) {
221 | if (year < 1600) {
222 | return year % 4 == 0;
223 | }
224 | return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
225 | }
226 |
227 | /**
228 | * 获取某年有多少天(平年365天,闰年366天)
229 | *
230 | * @param year 年
231 | * @return 天数
232 | */
233 | public static int getDaysOfYear(int year) {
234 | if (1582 == year) {
235 | return 355;
236 | }
237 | return isLeapYear(year) ? 366 : 365;
238 | }
239 |
240 | /**
241 | * 获取某年某月有多少天
242 | *
243 | * @param year 年
244 | * @param month 月
245 | * @return 天数
246 | */
247 | public static int getDaysOfMonth(int year, int month) {
248 | if (1582 == year && 10 == month) {
249 | return 21;
250 | }
251 | int m = month - 1;
252 | int d = DAYS_OF_MONTH[m];
253 | //公历闰年2月多一天
254 | if (m == Calendar.FEBRUARY && isLeapYear(year)) {
255 | d++;
256 | }
257 | return d;
258 | }
259 |
260 | /**
261 | * 获取某天为当年的第几天
262 | *
263 | * @param year 年
264 | * @param month 月
265 | * @param day 日
266 | * @return 第几天
267 | */
268 | public static int getDaysInYear(int year, int month, int day) {
269 | int days = 0;
270 | for (int i = 1; i < month; i++) {
271 | days += getDaysOfMonth(year, i);
272 | }
273 | int d = day;
274 | if (1582 == year && 10 == month) {
275 | if (day >= 15) {
276 | d -= 10;
277 | } else if (day > 4) {
278 | throw new IllegalArgumentException(String.format("wrong solar year %d month %d day %d", year, month, day));
279 | }
280 | }
281 | days += d;
282 | return days;
283 | }
284 |
285 | /**
286 | * 获取某年某月有多少周
287 | *
288 | * @param year 年
289 | * @param month 月
290 | * @param start 星期几作为一周的开始,1234560分别代表星期一至星期天
291 | * @return 周数
292 | */
293 | public static int getWeeksOfMonth(int year, int month, int start) {
294 | return (int) Math.ceil((getDaysOfMonth(year, month) + Solar.fromYmd(year, month, 1).getWeek() - start) * 1D / WEEK.length);
295 | }
296 |
297 | /**
298 | * 获取两个日期之间相差的天数(如果日期a比日期b小,天数为正,如果日期a比日期b大,天数为负)
299 | *
300 | * @param ay 年a
301 | * @param am 月a
302 | * @param ad 日a
303 | * @param by 年b
304 | * @param bm 月b
305 | * @param bd 日b
306 | * @return 天数
307 | */
308 | public static int getDaysBetween(int ay, int am, int ad, int by, int bm, int bd) {
309 | int n;
310 | int days;
311 | int i;
312 | if (ay == by) {
313 | n = getDaysInYear(by, bm, bd) - getDaysInYear(ay, am, ad);
314 | } else if (ay > by) {
315 | days = getDaysOfYear(by) - getDaysInYear(by, bm, bd);
316 | for (i = by + 1; i < ay; i++) {
317 | days += getDaysOfYear(i);
318 | }
319 | days += getDaysInYear(ay, am, ad);
320 | n = -days;
321 | } else {
322 | days = getDaysOfYear(ay) - getDaysInYear(ay, am, ad);
323 | for (i = ay + 1; i < by; i++) {
324 | days += getDaysOfYear(i);
325 | }
326 | days += getDaysInYear(by, bm, bd);
327 | n = days;
328 | }
329 | return n;
330 | }
331 |
332 | }
333 |
--------------------------------------------------------------------------------
/src/main/java/com/nlf/calendar/util/TaoUtil.java:
--------------------------------------------------------------------------------
1 | package com.nlf.calendar.util;
2 |
3 | import com.nlf.calendar.TaoFestival;
4 |
5 | import java.util.*;
6 |
7 | /**
8 | * 道历工具
9 | *
10 | * @author 6tail
11 | */
12 | public class TaoUtil {
13 | /**
14 | * 日期对应的节日
15 | */
16 | public static final Map> FESTIVAL = new HashMap>() {
17 | private static final long serialVersionUID = 1;
18 |
19 | {
20 | put("1-1", Collections.nCopies(1, new TaoFestival("天腊之辰", "天腊,此日五帝会于东方九炁青天")));
21 | put("1-3", Arrays.asList(new TaoFestival("郝真人圣诞"), new TaoFestival("孙真人圣诞")));
22 | put("1-5", Collections.nCopies(1, new TaoFestival("孙祖清静元君诞")));
23 | put("1-7", Collections.nCopies(1, new TaoFestival("举迁赏会", "此日上元赐福,天官同地水二官考校罪福")));
24 | put("1-9", Collections.nCopies(1, new TaoFestival("玉皇上帝圣诞")));
25 | put("1-13", Collections.nCopies(1, new TaoFestival("关圣帝君飞升")));
26 | put("1-15", Arrays.asList(new TaoFestival("上元天官圣诞"), new TaoFestival("老祖天师圣诞")));
27 | put("1-19", Collections.nCopies(1, new TaoFestival("长春邱真人(邱处机)圣诞")));
28 | put("1-28", Collections.nCopies(1, new TaoFestival("许真君(许逊天师)圣诞")));
29 | put("2-1", Arrays.asList(new TaoFestival("勾陈天皇大帝圣诞"), new TaoFestival("长春刘真人(刘渊然)圣诞")));
30 | put("2-2", Arrays.asList(new TaoFestival("土地正神诞"), new TaoFestival("姜太公圣诞")));
31 | put("2-3", Collections.nCopies(1, new TaoFestival("文昌梓潼帝君圣诞")));
32 | put("2-6", Collections.nCopies(1, new TaoFestival("东华帝君圣诞")));
33 | put("2-13", Collections.nCopies(1, new TaoFestival("度人无量葛真君圣诞")));
34 | put("2-15", Collections.nCopies(1, new TaoFestival("太清道德天尊(太上老君)圣诞")));
35 | put("2-19", Collections.nCopies(1, new TaoFestival("慈航真人圣诞")));
36 | put("3-1", Collections.nCopies(1, new TaoFestival("谭祖(谭处端)长真真人圣诞")));
37 | put("3-3", Collections.nCopies(1, new TaoFestival("玄天上帝圣诞")));
38 | put("3-6", Collections.nCopies(1, new TaoFestival("眼光娘娘圣诞")));
39 | put("3-15", Arrays.asList(new TaoFestival("天师张大真人圣诞"), new TaoFestival("财神赵公元帅圣诞")));
40 | put("3-16", Arrays.asList(new TaoFestival("三茅真君得道之辰"), new TaoFestival("中岳大帝圣诞")));
41 | put("3-18", Arrays.asList(new TaoFestival("王祖(王处一)玉阳真人圣诞"), new TaoFestival("后土娘娘圣诞")));
42 | put("3-19", Collections.nCopies(1, new TaoFestival("太阳星君圣诞")));
43 | put("3-20", Collections.nCopies(1, new TaoFestival("子孙娘娘圣诞")));
44 | put("3-23", Collections.nCopies(1, new TaoFestival("天后妈祖圣诞")));
45 | put("3-26", Collections.nCopies(1, new TaoFestival("鬼谷先师诞")));
46 | put("3-28", Collections.nCopies(1, new TaoFestival("东岳大帝圣诞")));
47 | put("4-1", Collections.nCopies(1, new TaoFestival("长生谭真君成道之辰")));
48 | put("4-10", Collections.nCopies(1, new TaoFestival("何仙姑圣诞")));
49 | put("4-14", Collections.nCopies(1, new TaoFestival("吕祖纯阳祖师圣诞")));
50 | put("4-15", Collections.nCopies(1, new TaoFestival("钟离祖师圣诞")));
51 | put("4-18", Arrays.asList(new TaoFestival("北极紫微大帝圣诞"), new TaoFestival("泰山圣母碧霞元君诞"), new TaoFestival("华佗神医先师诞")));
52 | put("4-20", Collections.nCopies(1, new TaoFestival("眼光圣母娘娘诞")));
53 | put("4-28", Collections.nCopies(1, new TaoFestival("神农先帝诞")));
54 | put("5-1", Collections.nCopies(1, new TaoFestival("南极长生大帝圣诞")));
55 | put("5-5", Arrays.asList(new TaoFestival("地腊之辰", "地腊,此日五帝会于南方三炁丹天"), new TaoFestival("南方雷祖圣诞"), new TaoFestival("地祗温元帅圣诞"), new TaoFestival("雷霆邓天君圣诞")));
56 | put("5-11", Collections.nCopies(1, new TaoFestival("城隍爷圣诞")));
57 | put("5-13", Arrays.asList(new TaoFestival("关圣帝君降神"), new TaoFestival("关平太子圣诞")));
58 | put("5-18", Collections.nCopies(1, new TaoFestival("张天师圣诞")));
59 | put("5-20", Collections.nCopies(1, new TaoFestival("马祖丹阳真人圣诞")));
60 | put("5-29", Collections.nCopies(1, new TaoFestival("紫青白祖师圣诞")));
61 | put("6-1", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
62 | put("6-2", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
63 | put("6-3", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
64 | put("6-4", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
65 | put("6-5", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
66 | put("6-6", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
67 | put("6-10", Collections.nCopies(1, new TaoFestival("刘海蟾祖师圣诞")));
68 | put("6-15", Collections.nCopies(1, new TaoFestival("灵官王天君圣诞")));
69 | put("6-19", Collections.nCopies(1, new TaoFestival("慈航(观音)成道日")));
70 | put("6-23", Collections.nCopies(1, new TaoFestival("火神圣诞")));
71 | put("6-24", Arrays.asList(new TaoFestival("南极大帝中方雷祖圣诞"), new TaoFestival("关圣帝君圣诞")));
72 | put("6-26", Collections.nCopies(1, new TaoFestival("二郎真君圣诞")));
73 | put("7-7", Arrays.asList(new TaoFestival("道德腊之辰", "道德腊,此日五帝会于西方七炁素天"), new TaoFestival("庆生中会", "此日中元赦罪,地官同天水二官考校罪福")));
74 | put("7-12", Collections.nCopies(1, new TaoFestival("西方雷祖圣诞")));
75 | put("7-15", Collections.nCopies(1, new TaoFestival("中元地官大帝圣诞")));
76 | put("7-18", Collections.nCopies(1, new TaoFestival("王母娘娘圣诞")));
77 | put("7-20", Collections.nCopies(1, new TaoFestival("刘祖(刘处玄)长生真人圣诞")));
78 | put("7-22", Collections.nCopies(1, new TaoFestival("财帛星君文财神增福相公李诡祖圣诞")));
79 | put("7-26", Collections.nCopies(1, new TaoFestival("张三丰祖师圣诞")));
80 | put("8-1", Collections.nCopies(1, new TaoFestival("许真君飞升日")));
81 | put("8-3", Collections.nCopies(1, new TaoFestival("九天司命灶君诞")));
82 | put("8-5", Collections.nCopies(1, new TaoFestival("北方雷祖圣诞")));
83 | put("8-10", Collections.nCopies(1, new TaoFestival("北岳大帝诞辰")));
84 | put("8-15", Collections.nCopies(1, new TaoFestival("太阴星君诞")));
85 | put("9-1", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
86 | put("9-2", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
87 | put("9-3", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
88 | put("9-4", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
89 | put("9-5", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
90 | put("9-6", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
91 | put("9-7", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
92 | put("9-8", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
93 | put("9-9", Arrays.asList(new TaoFestival("北斗九皇降世之辰"), new TaoFestival("斗姥元君圣诞"), new TaoFestival("重阳帝君圣诞"), new TaoFestival("玄天上帝飞升"), new TaoFestival("酆都大帝圣诞")));
94 | put("9-22", Collections.nCopies(1, new TaoFestival("增福财神诞")));
95 | put("9-23", Collections.nCopies(1, new TaoFestival("萨翁真君圣诞")));
96 | put("9-28", Collections.nCopies(1, new TaoFestival("五显灵官马元帅圣诞")));
97 | put("10-1", Arrays.asList(new TaoFestival("民岁腊之辰", "民岁腊,此日五帝会于北方五炁黑天"), new TaoFestival("东皇大帝圣诞")));
98 | put("10-3", Collections.nCopies(1, new TaoFestival("三茅应化真君圣诞")));
99 | put("10-6", Collections.nCopies(1, new TaoFestival("天曹诸司五岳五帝圣诞")));
100 | put("10-15", Arrays.asList(new TaoFestival("下元水官大帝圣诞"), new TaoFestival("建生大会", "此日下元解厄,水官同天地二官考校罪福")));
101 | put("10-18", Collections.nCopies(1, new TaoFestival("地母娘娘圣诞")));
102 | put("10-19", Collections.nCopies(1, new TaoFestival("长春邱真君飞升")));
103 | put("10-20", Collections.nCopies(1, new TaoFestival("虚靖天师(即三十代天师弘悟张真人)诞")));
104 | put("11-6", Collections.nCopies(1, new TaoFestival("西岳大帝圣诞")));
105 | put("11-9", Collections.nCopies(1, new TaoFestival("湘子韩祖圣诞")));
106 | put("11-11", Collections.nCopies(1, new TaoFestival("太乙救苦天尊圣诞")));
107 | put("11-26", Collections.nCopies(1, new TaoFestival("北方五道圣诞")));
108 | put("12-8", Collections.nCopies(1, new TaoFestival("王侯腊之辰", "王侯腊,此日五帝会于上方玄都玉京")));
109 | put("12-16", Arrays.asList(new TaoFestival("南岳大帝圣诞"), new TaoFestival("福德正神诞")));
110 | put("12-20", Collections.nCopies(1, new TaoFestival("鲁班先师圣诞")));
111 | put("12-21", Collections.nCopies(1, new TaoFestival("天猷上帝圣诞")));
112 | put("12-22", Collections.nCopies(1, new TaoFestival("重阳祖师圣诞")));
113 | put("12-23", Collections.nCopies(1, new TaoFestival("祭灶王", "最适宜谢旧年太岁,开启拜新年太岁")));
114 | put("12-25", Arrays.asList(new TaoFestival("玉帝巡天"), new TaoFestival("天神下降")));
115 | put("12-29", Collections.nCopies(1, new TaoFestival("清静孙真君(孙不二)成道")));
116 | }
117 | };
118 |
119 | /**
120 | * 八会日
121 | */
122 | public static final Map BA_HUI = new HashMap() {
123 |
124 | private static final long serialVersionUID = 1;
125 |
126 | {
127 | put("丙午", "天会");
128 | put("壬午", "地会");
129 | put("壬子", "人会");
130 | put("庚午", "日会");
131 | put("庚申", "月会");
132 | put("辛酉", "星辰会");
133 | put("甲辰", "五行会");
134 | put("甲戌", "四时会");
135 | }
136 | };
137 |
138 | /**
139 | * 八节日
140 | */
141 | public static final Map BA_JIE = new HashMap() {
142 |
143 | private static final long serialVersionUID = 1;
144 |
145 | {
146 | put("立春", "东北方度仙上圣天尊同梵炁始青天君下降");
147 | put("春分", "东方玉宝星上天尊同青帝九炁天君下降");
148 | put("立夏", "东南方好生度命天尊同梵炁始丹天君下降");
149 | put("夏至", "南方玄真万福天尊同赤帝三炁天君下降");
150 | put("立秋", "西南方太灵虚皇天尊同梵炁始素天君下降");
151 | put("秋分", "西方太妙至极天尊同白帝七炁天君下降");
152 | put("立冬", "西北方无量太华天尊同梵炁始玄天君下降");
153 | put("冬至", "北方玄上玉宸天尊同黑帝五炁天君下降");
154 | }
155 | };
156 |
157 | /**
158 | * 三会日
159 | */
160 | public static final String[] SAN_HUI = {"1-7", "7-7", "10-15"};
161 |
162 | /**
163 | * 三元日
164 | */
165 | public static final String[] SAN_YUAN = {"1-15", "7-15", "10-15"};
166 |
167 | /**
168 | * 五腊日
169 | */
170 | public static final String[] WU_LA = {"1-1", "5-5", "7-7", "10-1", "12-8"};
171 |
172 | /**
173 | * 暗戊
174 | */
175 | public static final String[] AN_WU = {"未", "戌", "辰", "寅", "午", "子", "酉", "申", "巳", "亥", "卯", "丑"};
176 |
177 | }
178 |
--------------------------------------------------------------------------------
/src/test/java/sample/BaZiTest.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.Solar;
5 | import org.junit.Test;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * 八字测试
11 | * @author 6tail
12 | * @deprecated 见BaZiTestNew
13 | */
14 | @Deprecated
15 | public class BaZiTest {
16 |
17 | @Test
18 | public void test1(){
19 | Solar solar = new Solar(2020,1,1,22,35,0);
20 | Lunar lunar = solar.getLunar();
21 | //[己亥, 丙子, 癸卯, 癸亥]
22 | System.out.println(lunar.getBaZi());
23 | }
24 |
25 | @Test
26 | public void test2(){
27 | Solar solar = new Solar(2020,1,6,14,35,0);
28 | Lunar lunar = solar.getLunar();
29 | //[己亥, 丁丑, 戊申, 己未]
30 | System.out.println(lunar.getBaZi());
31 | }
32 |
33 | @Test
34 | public void test3(){
35 | Solar solar = new Solar(2020,1,6,3,35,0);
36 | Lunar lunar = solar.getLunar();
37 | //[己亥, 丁丑, 戊辰, 癸亥]
38 | System.out.println(lunar.getBaZi());
39 | }
40 |
41 | @Test
42 | public void test4(){
43 | Solar solar = new Solar(2020,1,26,21,41,0);
44 | Lunar lunar = solar.getLunar();
45 | //[己亥, 丙子, 戊申, 甲寅]
46 | System.out.println(lunar.getBaZi());
47 | }
48 |
49 | @Test
50 | public void test5(){
51 | Solar solar = new Solar(2020,2,4,1,42,0);
52 | Lunar lunar = solar.getLunar();
53 | //[己亥, 丁丑, 丁丑, 辛丑]
54 | System.out.println(lunar.getBaZi());
55 | }
56 |
57 | @Test
58 | public void test6(){
59 | Solar solar = new Solar(2020,2,5,21,43,0);
60 | Lunar lunar = solar.getLunar();
61 | //[庚子, 戊寅, 戊寅, 癸亥]
62 | System.out.println(lunar.getBaZi());
63 | }
64 |
65 | @Test
66 | public void testBazi2Solar6() {
67 | List l = Solar.fromBaZi("庚子", "戊寅", "戊寅", "癸亥");
68 | // [2020-02-05 22:00:00, 1960-02-20 22:00:00]
69 | for (Solar solar : l) {
70 | System.out.println(solar.toFullString());
71 | }
72 | }
73 |
74 | @Test
75 | public void test7(){
76 | Solar solar = new Solar(2020,5,26,23,43,0);
77 | Lunar lunar = solar.getLunar();
78 | //[庚子, 辛巳, 庚午, 丙子]
79 | System.out.println(lunar.getBaZi());
80 | }
81 |
82 | @Test
83 | public void testBazi2Solar7() {
84 | List l = Solar.fromBaZi("庚子", "辛巳", "庚午", "丙子");
85 | // [2020-05-26 23:00:00, 2020-05-27 00:00:00]
86 | for (Solar solar : l) {
87 | System.out.println(solar.toFullString());
88 | }
89 | }
90 |
91 | @Test
92 | public void testBazi2Solar() {
93 | List l = Solar.fromBaZi("庚子", "癸未", "乙丑", "丁亥");
94 | // [2020-07-21 22:00:00, 1960-08-05 22:00:00]
95 | for (Solar solar : l) {
96 | System.out.println(solar.toFullString());
97 | }
98 | }
99 |
100 | @Test
101 | public void testBazi2Solar2() {
102 | List l = Solar.fromBaZi("庚子", "戊子", "己卯", "庚午");
103 | // [1960-12-17 12:00:00, 1901-01-01 12:00:00]
104 | for (Solar solar : l) {
105 | System.out.println(solar.toFullString());
106 | }
107 | }
108 |
109 | @Test
110 | public void testBaziShiShenZhi() {
111 | Solar solar = new Solar(2020,1,1,22,35,0);
112 | Lunar lunar = solar.getLunar();
113 | //[己亥, 丙子, 癸卯, 癸亥]
114 | System.out.println(lunar.getBaZi());
115 | //[七杀, 正财, 日主, 比肩]
116 | System.out.println(lunar.getBaZiShiShenGan());
117 | //[劫财, 比肩, 食神, 劫财]
118 | System.out.println(lunar.getBaZiShiShenZhi());
119 | //[劫财, 伤官]
120 | System.out.println(lunar.getBaZiShiShenYearZhi());
121 | //[比肩]
122 | System.out.println(lunar.getBaZiShiShenMonthZhi());
123 | //[食神]
124 | System.out.println(lunar.getBaZiShiShenDayZhi());
125 | //[劫财, 伤官]
126 | System.out.println(lunar.getBaZiShiShenTimeZhi());
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/src/test/java/sample/HalfYearTest.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import com.nlf.calendar.*;
4 | import org.junit.Test;
5 |
6 | /**
7 | * 半年示例
8 | */
9 | public class HalfYearTest {
10 |
11 | @Test
12 | public void test(){
13 | SolarHalfYear halfYear = new SolarHalfYear();
14 | System.out.println(halfYear);
15 | System.out.println(halfYear.toFullString());
16 |
17 | for(SolarMonth month:halfYear.getMonths()){
18 | System.out.println(month.toFullString());
19 | }
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/java/sample/HolidayTest.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import com.nlf.calendar.Holiday;
4 | import com.nlf.calendar.Solar;
5 | import com.nlf.calendar.util.HolidayUtil;
6 | import org.junit.Test;
7 |
8 | import java.util.List;
9 |
10 | public class HolidayTest {
11 |
12 | @Test
13 | public void test(){
14 | System.out.println(HolidayUtil.getHolidays("2017-10"));
15 | System.out.println(HolidayUtil.getHoliday("2020-01-01"));
16 | System.out.println(HolidayUtil.getHoliday("20200102"));
17 | System.out.println(HolidayUtil.getHolidays("202002"));
18 | System.out.println(HolidayUtil.getHolidays("20200201"));
19 | System.out.println(HolidayUtil.getHoliday(1999,1,5));
20 | System.out.println(HolidayUtil.getHoliday(2019,1,1));
21 | System.out.println(HolidayUtil.getHolidays(2020,5));
22 | System.out.println(HolidayUtil.getHolidays(2020));
23 |
24 | System.out.println(HolidayUtil.getHolidaysByTarget("20200501"));
25 | System.out.println(HolidayUtil.getHolidaysByTarget(2011,1,1));
26 | }
27 |
28 | @Test
29 | public void test1(){
30 | StringBuilder s = new StringBuilder();
31 | for(int i = 2001; i <= 2024; i++) {
32 | List l = HolidayUtil.getHolidays(i);
33 | for (Holiday d : l) {
34 | int index = -1;
35 | for (int x = 0;x expected = new ArrayList();
38 | expected.add("准提菩萨圣诞");
39 | Assert.assertEquals(expected, foto.getOtherFestivals());
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/java/test/FuTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Fu;
4 | import com.nlf.calendar.Lunar;
5 | import com.nlf.calendar.Solar;
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 |
9 | /**
10 | * 三伏测试
11 | *
12 | * @author 6tail
13 | */
14 | public class FuTest {
15 |
16 | @Test
17 | public void test1(){
18 | Solar solar = new Solar(2011,7,14);
19 | Lunar lunar = solar.getLunar();
20 | Fu fu = lunar.getFu();
21 | Assert.assertEquals(solar.toYmd(),"初伏",fu.toString());
22 | Assert.assertEquals(solar.toYmd(),"初伏第1天",fu.toFullString());
23 | }
24 |
25 | @Test
26 | public void test2(){
27 | Solar solar = new Solar(2011,7,23);
28 | Lunar lunar = solar.getLunar();
29 | Fu fu = lunar.getFu();
30 | Assert.assertEquals(solar.toYmd(),"初伏",fu.toString());
31 | Assert.assertEquals(solar.toYmd(),"初伏第10天",fu.toFullString());
32 | }
33 |
34 | @Test
35 | public void test3(){
36 | Solar solar = new Solar(2011,7,24);
37 | Lunar lunar = solar.getLunar();
38 | Fu fu = lunar.getFu();
39 | Assert.assertEquals(solar.toYmd(),"中伏",fu.toString());
40 | Assert.assertEquals(solar.toYmd(),"中伏第1天",fu.toFullString());
41 | }
42 |
43 | @Test
44 | public void test4(){
45 | Solar solar = new Solar(2011,8,12);
46 | Lunar lunar = solar.getLunar();
47 | Fu fu = lunar.getFu();
48 | Assert.assertEquals(solar.toYmd(),"中伏",fu.toString());
49 | Assert.assertEquals(solar.toYmd(),"中伏第20天",fu.toFullString());
50 | }
51 |
52 | @Test
53 | public void test5(){
54 | Solar solar = new Solar(2011,8,13);
55 | Lunar lunar = solar.getLunar();
56 | Fu fu = lunar.getFu();
57 | Assert.assertEquals(solar.toYmd(),"末伏",fu.toString());
58 | Assert.assertEquals(solar.toYmd(),"末伏第1天",fu.toFullString());
59 | }
60 |
61 | @Test
62 | public void test6(){
63 | Solar solar = new Solar(2011,8,22);
64 | Lunar lunar = solar.getLunar();
65 | Fu fu = lunar.getFu();
66 | Assert.assertEquals(solar.toYmd(),"末伏",fu.toString());
67 | Assert.assertEquals(solar.toYmd(),"末伏第10天",fu.toFullString());
68 | }
69 |
70 | @Test
71 | public void test7(){
72 | Solar solar = new Solar(2011,7,13);
73 | Lunar lunar = solar.getLunar();
74 | Fu fu = lunar.getFu();
75 | Assert.assertNull(solar.toYmd(),fu);
76 | }
77 |
78 | @Test
79 | public void test8(){
80 | Solar solar = new Solar(2011,8,23);
81 | Lunar lunar = solar.getLunar();
82 | Fu fu = lunar.getFu();
83 | Assert.assertNull(solar.toYmd(),fu);
84 | }
85 |
86 | @Test
87 | public void test9(){
88 | Solar solar = new Solar(2012,7,18);
89 | Lunar lunar = solar.getLunar();
90 | Fu fu = lunar.getFu();
91 | Assert.assertEquals(solar.toYmd(),"初伏",fu.toString());
92 | Assert.assertEquals(solar.toYmd(),"初伏第1天",fu.toFullString());
93 | }
94 |
95 | @Test
96 | public void test10(){
97 | Solar solar = new Solar(2012,8,5);
98 | Lunar lunar = solar.getLunar();
99 | Fu fu = lunar.getFu();
100 | Assert.assertEquals(solar.toYmd(),"中伏",fu.toString());
101 | Assert.assertEquals(solar.toYmd(),"中伏第9天",fu.toFullString());
102 | }
103 |
104 | @Test
105 | public void test11(){
106 | Solar solar = new Solar(2012,8,8);
107 | Lunar lunar = solar.getLunar();
108 | Fu fu = lunar.getFu();
109 | Assert.assertEquals(solar.toYmd(),"末伏",fu.toString());
110 | Assert.assertEquals(solar.toYmd(),"末伏第2天",fu.toFullString());
111 | }
112 |
113 | @Test
114 | public void test12(){
115 | Solar solar = new Solar(2020,7,17);
116 | Lunar lunar = solar.getLunar();
117 | Fu fu = lunar.getFu();
118 | Assert.assertEquals(solar.toYmd(),"初伏",fu.toString());
119 | Assert.assertEquals(solar.toYmd(),"初伏第2天",fu.toFullString());
120 | }
121 |
122 | @Test
123 | public void test13(){
124 | Solar solar = new Solar(2020,7,26);
125 | Lunar lunar = solar.getLunar();
126 | Fu fu = lunar.getFu();
127 | Assert.assertEquals(solar.toYmd(),"中伏",fu.toString());
128 | Assert.assertEquals(solar.toYmd(),"中伏第1天",fu.toFullString());
129 | }
130 |
131 | @Test
132 | public void test14(){
133 | Solar solar = new Solar(2020,8,24);
134 | Lunar lunar = solar.getLunar();
135 | Fu fu = lunar.getFu();
136 | Assert.assertEquals(solar.toYmd(),"末伏",fu.toString());
137 | Assert.assertEquals(solar.toYmd(),"末伏第10天",fu.toFullString());
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/src/test/java/test/GanZhiTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.Solar;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 |
8 | /**
9 | * 干支测试
10 | */
11 | public class GanZhiTest {
12 |
13 | @Test
14 | public void test(){
15 | Solar solar = new Solar(2020,1,1,13,22,0);
16 | Lunar lunar = solar.getLunar();
17 | Assert.assertEquals("己亥",lunar.getYearInGanZhi());
18 | Assert.assertEquals("己亥",lunar.getYearInGanZhiByLiChun());
19 | Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
20 |
21 | Assert.assertEquals("丙子",lunar.getMonthInGanZhi());
22 | Assert.assertEquals("丙子",lunar.getMonthInGanZhiExact());
23 |
24 |
25 | //小寒
26 | solar = new Solar(2020,1,6,13,22,0);
27 | lunar = solar.getLunar();
28 | Assert.assertEquals("己亥",lunar.getYearInGanZhi());
29 | Assert.assertEquals("己亥",lunar.getYearInGanZhiByLiChun());
30 | Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
31 |
32 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhi());
33 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
34 |
35 |
36 | solar = new Solar(2020,1,20,13,22,0);
37 | lunar = solar.getLunar();
38 | Assert.assertEquals("己亥",lunar.getYearInGanZhi());
39 | Assert.assertEquals("己亥",lunar.getYearInGanZhiByLiChun());
40 | Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
41 |
42 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhi());
43 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
44 |
45 |
46 | //春节
47 | solar = new Solar(2020,1,25,13,22,0);
48 | lunar = solar.getLunar();
49 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
50 | Assert.assertEquals("己亥",lunar.getYearInGanZhiByLiChun());
51 | Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
52 |
53 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhi());
54 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
55 |
56 |
57 | solar = new Solar(2020,1,30,13,22,0);
58 | lunar = solar.getLunar();
59 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
60 | Assert.assertEquals("己亥",lunar.getYearInGanZhiByLiChun());
61 | Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
62 |
63 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhi());
64 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
65 |
66 |
67 | solar = new Solar(2020,2,1,13,22,0);
68 | lunar = solar.getLunar();
69 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
70 | Assert.assertEquals("己亥",lunar.getYearInGanZhiByLiChun());
71 | Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
72 |
73 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhi());
74 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
75 |
76 | solar = new Solar(2020,2,4,18,22,0);
77 | lunar = solar.getLunar();
78 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
79 | Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
80 | Assert.assertEquals("庚子",lunar.getYearInGanZhiExact());
81 |
82 | Assert.assertEquals("戊寅",lunar.getMonthInGanZhi());
83 | Assert.assertEquals("戊寅",lunar.getMonthInGanZhiExact());
84 |
85 |
86 | solar = new Solar(2020,2,5,13,22,0);
87 | lunar = solar.getLunar();
88 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
89 | Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
90 | Assert.assertEquals("庚子",lunar.getYearInGanZhiExact());
91 |
92 | Assert.assertEquals("戊寅",lunar.getMonthInGanZhi());
93 | Assert.assertEquals("戊寅",lunar.getMonthInGanZhiExact());
94 |
95 |
96 | solar = new Solar(2020,5,22,13,22,0);
97 | lunar = solar.getLunar();
98 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
99 | Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
100 | Assert.assertEquals("庚子",lunar.getYearInGanZhiExact());
101 |
102 | Assert.assertEquals("辛巳",lunar.getMonthInGanZhi());
103 | Assert.assertEquals("辛巳",lunar.getMonthInGanZhiExact());
104 |
105 |
106 | solar = new Solar(2020,5,23,13,22,0);
107 | lunar = solar.getLunar();
108 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
109 | Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
110 | Assert.assertEquals("庚子",lunar.getYearInGanZhiExact());
111 |
112 | Assert.assertEquals("辛巳",lunar.getMonthInGanZhi());
113 | Assert.assertEquals("辛巳",lunar.getMonthInGanZhiExact());
114 |
115 | solar = new Solar(2020,5,29,13,22,0);
116 | lunar = solar.getLunar();
117 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
118 | Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
119 | Assert.assertEquals("庚子",lunar.getYearInGanZhiExact());
120 |
121 | Assert.assertEquals("辛巳",lunar.getMonthInGanZhi());
122 | Assert.assertEquals("辛巳",lunar.getMonthInGanZhiExact());
123 |
124 | solar = new Solar(2020,6,1,13,22,0);
125 | lunar = solar.getLunar();
126 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
127 | Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
128 | Assert.assertEquals("庚子",lunar.getYearInGanZhiExact());
129 |
130 | Assert.assertEquals("辛巳",lunar.getMonthInGanZhi());
131 | Assert.assertEquals("辛巳",lunar.getMonthInGanZhiExact());
132 |
133 | solar = new Solar(2020,6,29,13,22,0);
134 | lunar = solar.getLunar();
135 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
136 | Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
137 | Assert.assertEquals("庚子",lunar.getYearInGanZhiExact());
138 |
139 | Assert.assertEquals("壬午",lunar.getMonthInGanZhi());
140 | Assert.assertEquals("壬午",lunar.getMonthInGanZhiExact());
141 |
142 | solar = new Solar(2019,5,1,13,22,0);
143 | lunar = solar.getLunar();
144 | Assert.assertEquals("己亥",lunar.getYearInGanZhi());
145 | Assert.assertEquals("己亥",lunar.getYearInGanZhiByLiChun());
146 | Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
147 |
148 | Assert.assertEquals("戊辰",lunar.getMonthInGanZhi());
149 | Assert.assertEquals("戊辰",lunar.getMonthInGanZhiExact());
150 |
151 | solar = new Solar(1986,5,29,13,22,0);
152 | lunar = solar.getLunar();
153 | Assert.assertEquals("丙寅",lunar.getYearInGanZhi());
154 | Assert.assertEquals("丙寅",lunar.getYearInGanZhiByLiChun());
155 | Assert.assertEquals("丙寅",lunar.getYearInGanZhiExact());
156 |
157 | Assert.assertEquals("癸巳",lunar.getMonthInGanZhi());
158 | Assert.assertEquals("癸巳",lunar.getMonthInGanZhiExact());
159 |
160 | solar = new Solar(1986,5,1,1,22,0);
161 | lunar = solar.getLunar();
162 | Assert.assertEquals("丙寅",lunar.getYearInGanZhi());
163 | Assert.assertEquals("丙寅",lunar.getYearInGanZhiByLiChun());
164 | Assert.assertEquals("丙寅",lunar.getYearInGanZhiExact());
165 |
166 | Assert.assertEquals("壬辰",lunar.getMonthInGanZhi());
167 | Assert.assertEquals("壬辰",lunar.getMonthInGanZhiExact());
168 |
169 | solar = new Solar(1986,5,6,1,22,0);
170 | lunar = solar.getLunar();
171 | Assert.assertEquals("丙寅",lunar.getYearInGanZhi());
172 | Assert.assertEquals("丙寅",lunar.getYearInGanZhiByLiChun());
173 | Assert.assertEquals("丙寅",lunar.getYearInGanZhiExact());
174 |
175 | Assert.assertEquals("癸巳",lunar.getMonthInGanZhi());
176 | Assert.assertEquals("壬辰",lunar.getMonthInGanZhiExact());
177 |
178 | solar = new Solar(1986,5,6,23,22,0);
179 | lunar = solar.getLunar();
180 | Assert.assertEquals("丙寅",lunar.getYearInGanZhi());
181 | Assert.assertEquals("丙寅",lunar.getYearInGanZhiByLiChun());
182 | Assert.assertEquals("丙寅",lunar.getYearInGanZhiExact());
183 |
184 | Assert.assertEquals("癸巳",lunar.getMonthInGanZhi());
185 | Assert.assertEquals("癸巳",lunar.getMonthInGanZhiExact());
186 | }
187 |
188 | @Test
189 | public void test1() {
190 | Solar solar = new Solar(1996, 1, 16);
191 | Lunar lunar = solar.getLunar();
192 | Assert.assertEquals("壬子",lunar.getDayInGanZhi());
193 | }
194 |
195 | @Test
196 | public void test2() {
197 | Solar solar = new Solar(1997, 2, 16);
198 | Lunar lunar = solar.getLunar();
199 | Assert.assertEquals("己丑",lunar.getDayInGanZhi());
200 | }
201 |
202 | @Test
203 | public void test3() {
204 | Solar solar = new Solar(1998, 3, 16);
205 | Lunar lunar = solar.getLunar();
206 | Assert.assertEquals("壬戌",lunar.getDayInGanZhi());
207 | }
208 |
209 | @Test
210 | public void test4() {
211 | Solar solar = new Solar(1999, 4, 16);
212 | Lunar lunar = solar.getLunar();
213 | Assert.assertEquals("戊戌",lunar.getDayInGanZhi());
214 | }
215 |
216 | @Test
217 | public void test5() {
218 | Solar solar = new Solar(2000, 7, 16);
219 | Lunar lunar = solar.getLunar();
220 | Assert.assertEquals("乙亥",lunar.getDayInGanZhi());
221 | }
222 |
223 | @Test
224 | public void test6() {
225 | Solar solar = new Solar(2000, 1, 6);
226 | Lunar lunar = solar.getLunar();
227 | Assert.assertEquals("癸亥",lunar.getDayInGanZhi());
228 | }
229 |
230 | @Test
231 | public void test7() {
232 | Solar solar = new Solar(2000, 1, 9);
233 | Lunar lunar = solar.getLunar();
234 | Assert.assertEquals("丙寅",lunar.getDayInGanZhi());
235 | }
236 |
237 | @Test
238 | public void test8() {
239 | Solar solar = new Solar(2000, 2, 2);
240 | Lunar lunar = solar.getLunar();
241 | Assert.assertEquals("庚寅",lunar.getDayInGanZhi());
242 | }
243 |
244 | @Test
245 | public void test9() {
246 | Solar solar = new Solar(2012, 8, 5);
247 | Lunar lunar = solar.getLunar();
248 | Assert.assertEquals("戊戌",lunar.getDayInGanZhi());
249 | }
250 |
251 | @Test
252 | public void test10() {
253 | Solar solar = new Solar(2012, 9, 20);
254 | Lunar lunar = solar.getLunar();
255 | Assert.assertEquals("壬辰",lunar.getYearInGanZhi());
256 | Assert.assertEquals("己酉",lunar.getMonthInGanZhi());
257 | Assert.assertEquals("甲申",lunar.getDayInGanZhi());
258 | }
259 |
260 | @Test
261 | public void test11() {
262 | Solar solar = new Solar(2012, 10, 20);
263 | Lunar lunar = solar.getLunar();
264 | Assert.assertEquals("壬辰",lunar.getYearInGanZhi());
265 | Assert.assertEquals("庚戌",lunar.getMonthInGanZhi());
266 | Assert.assertEquals("甲寅",lunar.getDayInGanZhi());
267 | }
268 |
269 | @Test
270 | public void test12() {
271 | Solar solar = new Solar(2012, 11, 20);
272 | Lunar lunar = solar.getLunar();
273 | Assert.assertEquals("壬辰",lunar.getYearInGanZhi());
274 | Assert.assertEquals("辛亥",lunar.getMonthInGanZhi());
275 | Assert.assertEquals("乙酉",lunar.getDayInGanZhi());
276 | }
277 |
278 | @Test
279 | public void test13() {
280 | Solar solar = new Solar(2012, 12, 20);
281 | Lunar lunar = solar.getLunar();
282 | Assert.assertEquals("壬辰",lunar.getYearInGanZhi());
283 | Assert.assertEquals("壬子",lunar.getMonthInGanZhi());
284 | Assert.assertEquals("乙卯",lunar.getDayInGanZhi());
285 | }
286 |
287 | @Test
288 | public void test14() {
289 | Solar solar = new Solar(2012, 12, 27);
290 | Lunar lunar = solar.getLunar();
291 | Assert.assertEquals("壬辰",lunar.getYearInGanZhi());
292 | Assert.assertEquals("壬子",lunar.getMonthInGanZhi());
293 | Assert.assertEquals("壬戌",lunar.getDayInGanZhi());
294 | }
295 |
296 | @Test
297 | public void test15() {
298 | Solar solar = new Solar(1988, 2, 15);
299 | Lunar lunar = solar.getLunar();
300 | Assert.assertEquals("丁卯",lunar.getYearInGanZhi());
301 | }
302 |
303 | @Test
304 | public void test16() {
305 | Solar solar = new Solar(1988, 2, 15, 23, 30,0);
306 | Lunar lunar = solar.getLunar();
307 | Assert.assertEquals("丁卯",lunar.getYearInGanZhi());
308 | Assert.assertEquals("戊辰",lunar.getYearInGanZhiByLiChun());
309 | Assert.assertEquals("戊辰",lunar.getYearInGanZhiExact());
310 | }
311 |
312 | @Test
313 | public void test17() {
314 | Solar solar = new Solar(2019, 2, 8, 13, 22, 0);
315 | Lunar lunar = solar.getLunar();
316 | Assert.assertEquals("己亥", lunar.getYearInGanZhi());
317 | Assert.assertEquals("己亥", lunar.getYearInGanZhiByLiChun());
318 | Assert.assertEquals("己亥", lunar.getYearInGanZhiExact());
319 |
320 | Assert.assertEquals("丙寅", lunar.getMonthInGanZhi());
321 | Assert.assertEquals("丙寅", lunar.getMonthInGanZhiExact());
322 | }
323 |
324 | @Test
325 | public void test18() {
326 | Solar solar = new Solar(2020,2,4,13,22,0);
327 | Lunar lunar = solar.getLunar();
328 | Assert.assertEquals("庚子",lunar.getYearInGanZhi());
329 | Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
330 | Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
331 |
332 | Assert.assertEquals("戊寅",lunar.getMonthInGanZhi());
333 | Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
334 | }
335 |
336 | @Test
337 | public void test19() {
338 | Solar solar = new Solar(2022,4,6,20,18,0);
339 | Lunar lunar = solar.getLunar();
340 | Assert.assertEquals("壬寅",lunar.getYearInGanZhi());
341 | Assert.assertEquals("壬寅",lunar.getYearInGanZhiByLiChun());
342 | Assert.assertEquals("壬寅",lunar.getYearInGanZhiExact());
343 |
344 | Assert.assertEquals("甲辰",lunar.getMonthInGanZhi());
345 | Assert.assertEquals("甲辰",lunar.getMonthInGanZhiExact());
346 |
347 | Assert.assertEquals("己丑",lunar.getDayInGanZhi());
348 | Assert.assertEquals("己丑",lunar.getDayInGanZhiExact());
349 | Assert.assertEquals("己丑",lunar.getDayInGanZhiExact2());
350 |
351 | Assert.assertEquals("甲戌",lunar.getTimeInGanZhi());
352 | }
353 |
354 | }
355 |
--------------------------------------------------------------------------------
/src/test/java/test/HalfYearTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.SolarHalfYear;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | /**
8 | * 半年测试
9 | *
10 | * @author 6tail
11 | */
12 | public class HalfYearTest {
13 |
14 | @Test
15 | public void test(){
16 | SolarHalfYear halfYear = new SolarHalfYear(2019,5);
17 | Assert.assertEquals("2019.1",halfYear.toString());
18 | Assert.assertEquals("2019年上半年",halfYear.toFullString());
19 |
20 | Assert.assertEquals("2019.2",halfYear.next(1).toString());
21 | Assert.assertEquals("2019年下半年",halfYear.next(1).toFullString());
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/test/HolidayTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Holiday;
4 | import com.nlf.calendar.Solar;
5 | import com.nlf.calendar.util.HolidayUtil;
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 |
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | public class HolidayTest {
13 |
14 | @Test
15 | public void test2021() {
16 | Map holidays = new HashMap() {
17 | private static final long serialVersionUID = 1L;
18 |
19 | {
20 | put("2021-01-01", "2021-01-01 元旦节 2021-01-01");
21 | put("2021-01-02", "2021-01-02 元旦节 2021-01-01");
22 | put("2021-01-03", "2021-01-03 元旦节 2021-01-01");
23 |
24 | put("2021-02-11", "2021-02-11 春节 2021-02-12");
25 | put("2021-02-12", "2021-02-12 春节 2021-02-12");
26 | put("2021-02-13", "2021-02-13 春节 2021-02-12");
27 | put("2021-02-14", "2021-02-14 春节 2021-02-12");
28 | put("2021-02-15", "2021-02-15 春节 2021-02-12");
29 | put("2021-02-16", "2021-02-16 春节 2021-02-12");
30 | put("2021-02-17", "2021-02-17 春节 2021-02-12");
31 |
32 | put("2021-02-07", "2021-02-07 春节调休 2021-02-12");
33 | put("2021-02-20", "2021-02-20 春节调休 2021-02-12");
34 |
35 | put("2021-04-03", "2021-04-03 清明节 2021-04-04");
36 | put("2021-04-04", "2021-04-04 清明节 2021-04-04");
37 | put("2021-04-05", "2021-04-05 清明节 2021-04-04");
38 |
39 | put("2021-05-01", "2021-05-01 劳动节 2021-05-01");
40 | put("2021-05-02", "2021-05-02 劳动节 2021-05-01");
41 | put("2021-05-03", "2021-05-03 劳动节 2021-05-01");
42 | put("2021-05-04", "2021-05-04 劳动节 2021-05-01");
43 | put("2021-05-05", "2021-05-05 劳动节 2021-05-01");
44 |
45 | put("2021-04-25", "2021-04-25 劳动节调休 2021-05-01");
46 | put("2021-05-08", "2021-05-08 劳动节调休 2021-05-01");
47 |
48 | put("2021-06-12", "2021-06-12 端午节 2021-06-14");
49 | put("2021-06-13", "2021-06-13 端午节 2021-06-14");
50 | put("2021-06-14", "2021-06-14 端午节 2021-06-14");
51 |
52 | put("2021-09-19", "2021-09-19 中秋节 2021-09-21");
53 | put("2021-09-20", "2021-09-20 中秋节 2021-09-21");
54 | put("2021-09-21", "2021-09-21 中秋节 2021-09-21");
55 |
56 | put("2021-09-18", "2021-09-18 中秋节调休 2021-09-21");
57 |
58 | put("2021-10-01", "2021-10-01 国庆节 2021-10-01");
59 | put("2021-10-02", "2021-10-02 国庆节 2021-10-01");
60 | put("2021-10-03", "2021-10-03 国庆节 2021-10-01");
61 | put("2021-10-04", "2021-10-04 国庆节 2021-10-01");
62 | put("2021-10-05", "2021-10-05 国庆节 2021-10-01");
63 | put("2021-10-06", "2021-10-06 国庆节 2021-10-01");
64 | put("2021-10-07", "2021-10-07 国庆节 2021-10-01");
65 |
66 | put("2021-09-26", "2021-09-26 国庆节调休 2021-10-01");
67 | put("2021-10-09", "2021-10-09 国庆节调休 2021-10-01");
68 | }
69 | };
70 | Solar solar = Solar.fromYmd(2021, 1, 1);
71 | while (solar.toYmd().compareTo("2022-01-01") < 0) {
72 | String ymd = solar.toYmd();
73 | String holiday = holidays.get(ymd);
74 | Assert.assertEquals(ymd, holiday + "", HolidayUtil.getHoliday(ymd) + "");
75 |
76 | solar = solar.next(1);
77 | }
78 | }
79 |
80 | @Test
81 | public void test() {
82 | Assert.assertEquals("2020-01-01 元旦节 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
83 |
84 | // 将2020-01-01修改为春节
85 | HolidayUtil.fix("202001011120200101");
86 | Assert.assertEquals("2020-01-01 春节 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
87 |
88 | // 追加2099-01-01为元旦节
89 | HolidayUtil.fix("209901010120990101");
90 | Assert.assertEquals("2099-01-01 元旦节 2099-01-01", HolidayUtil.getHoliday("2099-01-01") + "");
91 |
92 | // 将2020-01-01修改为春节,并追加2099-01-01为元旦节
93 | HolidayUtil.fix("202001011120200101209901010120990101");
94 | Assert.assertEquals("2020-01-01 春节 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
95 | Assert.assertEquals("2099-01-01 元旦节 2099-01-01", HolidayUtil.getHoliday("2099-01-01") + "");
96 |
97 | // 自定义节假日名称
98 | String[] names = new String[HolidayUtil.NAMES.length];
99 | for (int i = 0, j = HolidayUtil.NAMES.length; i < j; i++) {
100 | names[i] = HolidayUtil.NAMES[i];
101 | }
102 | names[0] = "元旦";
103 | names[1] = "大年初一";
104 |
105 | HolidayUtil.fix(names, null);
106 | Assert.assertEquals("2020-01-01 大年初一 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
107 | Assert.assertEquals("2099-01-01 元旦 2099-01-01", HolidayUtil.getHoliday("2099-01-01") + "");
108 |
109 | // 追加节假日名称和数据
110 | names = new String[12];
111 | for (int i = 0, j = HolidayUtil.NAMES.length; i < j; i++) {
112 | names[i] = HolidayUtil.NAMES[i];
113 | }
114 | names[9] = "我的生日";
115 | names[10] = "结婚纪念日";
116 | names[11] = "她的生日";
117 |
118 | HolidayUtil.fix(names, "20210529912021052920211111:12021111120211201;120211201");
119 | Assert.assertEquals("2021-05-29 我的生日 2021-05-29", HolidayUtil.getHoliday("2021-05-29") + "");
120 | Assert.assertEquals("2021-11-11 结婚纪念日 2021-11-11", HolidayUtil.getHoliday("2021-11-11") + "");
121 | Assert.assertEquals("2021-12-01 她的生日 2021-12-01", HolidayUtil.getHoliday("2021-12-01") + "");
122 | }
123 |
124 | @Test
125 | public void test1() {
126 | Holiday holiday = HolidayUtil.getHoliday(2016,10,4);
127 | Assert.assertNotNull(holiday);
128 | Assert.assertNotNull(holiday.getTarget());
129 | Assert.assertEquals("2016-10-01",holiday.getTarget());
130 | }
131 |
132 | @Test
133 | public void testRemove() {
134 | // 设置默认的节假日名称
135 | HolidayUtil.fix(HolidayUtil.NAMES, null);
136 | Holiday holiday = HolidayUtil.getHoliday(2010,1,1);
137 | Assert.assertNotNull(holiday);
138 | Assert.assertEquals("元旦节",holiday.getName());
139 |
140 | HolidayUtil.fix("20100101~000000000000000000000000000");
141 | holiday = HolidayUtil.getHoliday(2010,1,1);
142 | Assert.assertNull(holiday);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/src/test/java/test/JieQiTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.Solar;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 |
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | /**
12 | * 节气测试
13 | *
14 | * @author 6tail
15 | */
16 | public class JieQiTest {
17 |
18 | @Test
19 | public void test2022() {
20 |
21 | Map jieQi = new HashMap(){
22 | private static final long serialVersionUID = 1L;
23 | {
24 | put("冬至","2021-12-21 23:59:09");
25 | put("小寒","2022-01-05 17:13:54");
26 | put("大寒","2022-01-20 10:38:56");
27 | put("立春","2022-02-04 04:50:36");
28 | put("雨水","2022-02-19 00:42:50");
29 | put("惊蛰","2022-03-05 22:43:34");
30 | put("春分","2022-03-20 23:33:15");
31 | put("清明","2022-04-05 03:20:03");
32 | put("谷雨","2022-04-20 10:24:07");
33 | put("立夏","2022-05-05 20:25:47");
34 | put("小满","2022-05-21 09:22:25");
35 | put("芒种","2022-06-06 00:25:38");
36 | put("夏至","2022-06-21 17:13:40");
37 | put("小暑","2022-07-07 10:37:49");
38 | put("大暑","2022-07-23 04:06:49");
39 | put("立秋","2022-08-07 20:28:57");
40 | put("处暑","2022-08-23 11:15:59");
41 | put("白露","2022-09-07 23:32:07");
42 | put("秋分","2022-09-23 09:03:31");
43 | put("寒露","2022-10-08 15:22:16");
44 | put("霜降","2022-10-23 18:35:31");
45 | put("立冬","2022-11-07 18:45:18");
46 | put("小雪","2022-11-22 16:20:18");
47 | put("大雪","2022-12-07 11:46:04");
48 | }
49 | };
50 |
51 | Solar solar = Solar.fromYmd(2022, 7, 15);
52 | Map result = solar.getLunar().getJieQiTable();
53 | for(Map.Entry entry:jieQi.entrySet()){
54 | String name = entry.getKey();
55 | Assert.assertEquals(name, entry.getValue(), result.get(name).toYmdHms());
56 | }
57 | }
58 |
59 | @Test
60 | public void test1986() {
61 |
62 | Map jieQi = new HashMap(){
63 | private static final long serialVersionUID = 1L;
64 | {
65 | put("冬至","1985-12-22 06:07:40");
66 | put("小寒","1986-01-05 23:28:02");
67 | put("大寒","1986-01-20 16:46:12");
68 | put("立春","1986-02-04 11:07:42");
69 | put("雨水","1986-02-19 06:57:31");
70 | put("惊蛰","1986-03-06 05:12:08");
71 | put("春分","1986-03-21 06:02:41");
72 | put("清明","1986-04-05 10:06:07");
73 | put("谷雨","1986-04-20 17:12:08");
74 | put("立夏","1986-05-06 03:30:36");
75 | put("小满","1986-05-21 16:27:55");
76 | put("芒种","1986-06-06 07:44:23");
77 | put("夏至","1986-06-22 00:29:57");
78 | put("小暑","1986-07-07 18:00:45");
79 | put("大暑","1986-07-23 11:24:23");
80 | put("立秋","1986-08-08 03:45:36");
81 | put("处暑","1986-08-23 18:25:47");
82 | put("白露","1986-09-08 06:34:37");
83 | put("秋分","1986-09-23 15:58:52");
84 | put("寒露","1986-10-08 22:06:45");
85 | put("霜降","1986-10-24 01:14:11");
86 | put("立冬","1986-11-08 01:12:49");
87 | put("小雪","1986-11-22 22:44:20");
88 | put("大雪","1986-12-07 18:00:56");
89 | }
90 | };
91 |
92 | Solar solar = Solar.fromYmd(1986, 7, 15);
93 | Map result = solar.getLunar().getJieQiTable();
94 | for(Map.Entry entry:jieQi.entrySet()){
95 | String name = entry.getKey();
96 | Assert.assertEquals(name, entry.getValue(), result.get(name).toYmdHms());
97 | }
98 | }
99 |
100 | @Test
101 | public void test() {
102 | Solar solar = Solar.fromYmd(1986,1,5);
103 | Lunar lunar = solar.getLunar();
104 | Assert.assertEquals("小寒", lunar.getJie());
105 | Assert.assertEquals("小寒", lunar.getJieQi());
106 | Assert.assertEquals("小寒", lunar.getCurrentJieQi().getName());
107 | Assert.assertEquals("小寒", lunar.getCurrentJie().getName());
108 | Assert.assertNull(lunar.getCurrentQi());
109 | Assert.assertEquals("", lunar.getQi());
110 | Assert.assertEquals("大雪", lunar.getPrevJie().getName());
111 | Assert.assertEquals("冬至", lunar.getPrevQi().getName());
112 | Assert.assertEquals("冬至", lunar.getPrevJieQi().getName());
113 |
114 | solar = Solar.fromYmdHms(1986,1,20,17,0,0);
115 | lunar = solar.getLunar();
116 | Assert.assertEquals("大寒", lunar.getQi());
117 | Assert.assertEquals("大寒", lunar.getJieQi());
118 | Assert.assertEquals("大寒", lunar.getCurrentJieQi().getName());
119 | Assert.assertEquals("大寒", lunar.getCurrentQi().getName());
120 | Assert.assertNull(lunar.getCurrentJie());
121 | Assert.assertEquals("", lunar.getJie());
122 | Assert.assertEquals("立春", lunar.getNextJie().getName());
123 | Assert.assertEquals("雨水", lunar.getNextQi().getName());
124 | Assert.assertEquals("立春", lunar.getNextJieQi().getName());
125 | solar = Solar.fromYmdHms(1986,1,20,14,0,0);
126 | lunar = solar.getLunar();
127 | Assert.assertEquals("小寒", lunar.getPrevJie().getName());
128 | Assert.assertEquals("冬至", lunar.getPrevQi().getName());
129 | Assert.assertEquals("小寒", lunar.getPrevJieQi().getName());
130 |
131 | solar = Solar.fromYmd(1986,12,7);
132 | lunar = solar.getLunar();
133 | Assert.assertEquals("大雪", lunar.getJie());
134 | Assert.assertEquals("大雪", lunar.getJieQi());
135 | Assert.assertEquals("大雪", lunar.getCurrentJieQi().getName());
136 | Assert.assertEquals("大雪", lunar.getCurrentJie().getName());
137 | Assert.assertNull(lunar.getCurrentQi());
138 | Assert.assertEquals("", lunar.getQi());
139 | Assert.assertEquals("大雪", lunar.getNextJie().getName());
140 | Assert.assertEquals("冬至", lunar.getNextQi().getName());
141 | Assert.assertEquals("大雪", lunar.getNextJieQi().getName());
142 |
143 | solar = Solar.fromYmd(1986,1,1);
144 | lunar = solar.getLunar();
145 | Assert.assertEquals("", lunar.getJie());
146 | Assert.assertEquals("", lunar.getQi());
147 | Assert.assertEquals("", lunar.getJieQi());
148 | Assert.assertNull(lunar.getCurrentJieQi());
149 | Assert.assertNull(lunar.getCurrentJie());
150 | Assert.assertNull(lunar.getCurrentQi());
151 | Assert.assertEquals("大雪", lunar.getPrevJie().getName());
152 | Assert.assertEquals("冬至", lunar.getPrevQi().getName());
153 | Assert.assertEquals("冬至", lunar.getPrevJieQi().getName());
154 | Assert.assertEquals("小寒", lunar.getNextJie().getName());
155 | Assert.assertEquals("大寒", lunar.getNextQi().getName());
156 | Assert.assertEquals("小寒", lunar.getNextJieQi().getName());
157 |
158 |
159 | solar = Solar.fromYmd(2012,12,25);
160 | lunar = solar.getLunar();
161 | Assert.assertEquals("", lunar.getJie());
162 | Assert.assertEquals("", lunar.getQi());
163 | Assert.assertEquals("", lunar.getJieQi());
164 | Assert.assertNull(lunar.getCurrentJie());
165 | Assert.assertNull(lunar.getCurrentQi());
166 | Assert.assertNull(lunar.getCurrentJieQi());
167 |
168 | Assert.assertEquals("小寒", lunar.getNextJie().getName());
169 | Assert.assertEquals("大寒", lunar.getNextQi().getName());
170 | Assert.assertEquals("小寒", lunar.getNextJieQi().getName());
171 |
172 | Assert.assertEquals("大雪", lunar.getPrevJie().getName());
173 | Assert.assertEquals("冬至", lunar.getPrevQi().getName());
174 | Assert.assertEquals("冬至", lunar.getPrevJieQi().getName());
175 | }
176 |
177 | @Test
178 | public void test7() {
179 | Lunar lunar = Lunar.fromYmd(2012, 9, 1);
180 | Assert.assertEquals("2012-09-07 13:29:01", lunar.getJieQiTable().get("白露").toYmdHms());
181 | }
182 |
183 | @Test
184 | public void test8() {
185 | Lunar lunar = Lunar.fromYmd(2050, 12, 1);
186 | Assert.assertEquals("2050-12-07 06:40:53", lunar.getJieQiTable().get("DA_XUE").toYmdHms());
187 | }
188 |
189 | @Test
190 | public void test9() {
191 | Solar solar = Solar.fromYmd(2021, 12, 21);
192 | Assert.assertEquals("冬至", solar.getLunar().getJieQi());
193 | Assert.assertEquals("", solar.getLunar().getJie());
194 | Assert.assertEquals("冬至", solar.getLunar().getQi());
195 | }
196 |
197 | @Test
198 | public void test10() {
199 | Lunar lunar = Solar.fromYmd(2023, 6, 1).getLunar();
200 | Assert.assertEquals("2022-12-22 05:48:01", lunar.getJieQiTable().get("冬至").toYmdHms());
201 | }
202 |
203 | @Test
204 | public void test11() {
205 | Lunar lunar = Solar.fromYmd(2025, 3, 5).getLunar();
206 | Assert.assertEquals("2025-03-05 16:07:02", lunar.getJieQiTable().get("惊蛰").toYmdHms());
207 | }
208 |
209 | }
210 |
--------------------------------------------------------------------------------
/src/test/java/test/JulianDayTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Solar;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | /**
8 | * 儒略日测试
9 | *
10 | * @author 6tail
11 | */
12 | public class JulianDayTest {
13 |
14 | @Test
15 | public void testSolar2JD() {
16 | Solar solar = Solar.fromYmd(2020, 7, 15);
17 | Assert.assertEquals(2459045.5, solar.getJulianDay(), 0);
18 | }
19 |
20 | @Test
21 | public void testJD2Solar() {
22 | Solar solar = Solar.fromJulianDay(2459045.5);
23 | Assert.assertEquals("2020-07-15 00:00:00", solar.toYmdHms());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/java/test/LiuYaoTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.Solar;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 |
8 | /**
9 | * 六曜测试
10 | *
11 | * @author 6tail
12 | */
13 | public class LiuYaoTest {
14 |
15 | @Test
16 | public void test1(){
17 | Solar solar = new Solar(2020,4,23);
18 | Lunar lunar = solar.getLunar();
19 | Assert.assertEquals(lunar.toString(),"佛灭",lunar.getLiuYao());
20 | }
21 |
22 | @Test
23 | public void test2(){
24 | Solar solar = new Solar(2021,1,15);
25 | Lunar lunar = solar.getLunar();
26 | Assert.assertEquals(lunar.toString(),"友引",lunar.getLiuYao());
27 | }
28 |
29 | @Test
30 | public void test3(){
31 | Solar solar = new Solar(2017,1,5);
32 | Lunar lunar = solar.getLunar();
33 | Assert.assertEquals(lunar.toString(),"先胜",lunar.getLiuYao());
34 | }
35 |
36 | @Test
37 | public void test4(){
38 | Solar solar = new Solar(2020,4,10);
39 | Lunar lunar = solar.getLunar();
40 | Assert.assertEquals(lunar.toString(),"友引",lunar.getLiuYao());
41 | }
42 |
43 | @Test
44 | public void test5(){
45 | Solar solar = new Solar(2020,6,11);
46 | Lunar lunar = solar.getLunar();
47 | Assert.assertEquals(lunar.toString(),"大安",lunar.getLiuYao());
48 | }
49 |
50 | @Test
51 | public void test6(){
52 | Solar solar = new Solar(2020,6,1);
53 | Lunar lunar = solar.getLunar();
54 | Assert.assertEquals(lunar.toString(),"先胜",lunar.getLiuYao());
55 | }
56 |
57 | @Test
58 | public void test7(){
59 | Solar solar = new Solar(2020,12,8);
60 | Lunar lunar = solar.getLunar();
61 | Assert.assertEquals(lunar.toString(),"先负",lunar.getLiuYao());
62 | }
63 |
64 | @Test
65 | public void test8(){
66 | Solar solar = new Solar(2020,12,11);
67 | Lunar lunar = solar.getLunar();
68 | Assert.assertEquals(lunar.toString(),"赤口",lunar.getLiuYao());
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/test/java/test/LunarMonthTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.LunarMonth;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | /**
8 | * 农历月测试
9 | *
10 | * @author 6tail
11 | */
12 | public class LunarMonthTest {
13 |
14 | @Test
15 | public void test(){
16 | LunarMonth month = LunarMonth.fromYm(2023, 1);
17 | Assert.assertEquals(1, month.getIndex());
18 | Assert.assertEquals("甲寅", month.getGanZhi());
19 | }
20 |
21 | @Test
22 | public void test1(){
23 | LunarMonth month = LunarMonth.fromYm(2023, -2);
24 | Assert.assertEquals(3, month.getIndex());
25 | Assert.assertEquals("丙辰", month.getGanZhi());
26 | }
27 |
28 | @Test
29 | public void test2(){
30 | LunarMonth month = LunarMonth.fromYm(2023, 3);
31 | Assert.assertEquals(4, month.getIndex());
32 | Assert.assertEquals("丁巳", month.getGanZhi());
33 | }
34 |
35 | @Test
36 | public void test3(){
37 | LunarMonth month = LunarMonth.fromYm(2024, 1);
38 | Assert.assertEquals(1, month.getIndex());
39 | Assert.assertEquals("丙寅", month.getGanZhi());
40 | }
41 |
42 | @Test
43 | public void test4(){
44 | LunarMonth month = LunarMonth.fromYm(2023, 12);
45 | Assert.assertEquals(13, month.getIndex());
46 | Assert.assertEquals("丙寅", month.getGanZhi());
47 | }
48 |
49 | @Test
50 | public void test5(){
51 | LunarMonth month = LunarMonth.fromYm(2022, 1);
52 | Assert.assertEquals(1, month.getIndex());
53 | Assert.assertEquals("壬寅", month.getGanZhi());
54 | }
55 |
56 | @Test
57 | public void test6(){
58 | LunarMonth month = LunarMonth.fromYm(2023, 9);
59 | Assert.assertEquals("癸亥", month.getGanZhi());
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/test/MonthTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.SolarMonth;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | /**
8 | * 月份测试
9 | *
10 | * @author 6tail
11 | */
12 | public class MonthTest {
13 |
14 | @Test
15 | public void test(){
16 | SolarMonth month = new SolarMonth(2019,5);
17 | Assert.assertEquals("2019-5",month.toString());
18 | Assert.assertEquals("2019年5月",month.toFullString());
19 |
20 | Assert.assertEquals("2019-6",month.next(1).toString());
21 | Assert.assertEquals("2019年6月",month.next(1).toFullString());
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/test/NineStarTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.LunarMonth;
5 | import com.nlf.calendar.LunarYear;
6 | import com.nlf.calendar.Solar;
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | public class NineStarTest {
11 | @Test
12 | public void test1() {
13 | Lunar lunar = Solar.fromYmd(1985, 2, 19).getLunar();
14 | Assert.assertEquals("六", lunar.getYearNineStar().getNumber());
15 | Assert.assertEquals("五黄土玉衡", lunar.getDayNineStar().toString());
16 | }
17 |
18 | @Test
19 | public void test2() {
20 | Lunar lunar = Lunar.fromYmd(2022, 1, 1);
21 | Assert.assertEquals("六白金开阳", lunar.getYearNineStar().toString());
22 | Assert.assertEquals("四绿木天权", lunar.getDayNineStar().toString());
23 | }
24 |
25 | @Test
26 | public void test3() {
27 | Lunar lunar = Lunar.fromYmd(2033, 1, 1);
28 | Assert.assertEquals("四绿木天权", lunar.getYearNineStar().toString());
29 | Assert.assertEquals("一白水天枢", lunar.getDayNineStar().toString());
30 | }
31 |
32 | @Test
33 | public void test4() {
34 | LunarYear y = LunarYear.fromYear(1985);
35 | Assert.assertEquals("六白金开阳", y.getNineStar().toString());
36 | }
37 |
38 | @Test
39 | public void test5() {
40 | LunarYear y = LunarYear.fromYear(2022);
41 | Assert.assertEquals("五黄土玉衡", y.getNineStar().toString());
42 | }
43 |
44 | @Test
45 | public void test6() {
46 | LunarYear y = LunarYear.fromYear(2033);
47 | Assert.assertEquals("三碧木天玑", y.getNineStar().toString());
48 | }
49 |
50 | @Test
51 | public void test7() {
52 | LunarMonth m = LunarMonth.fromYm(1985, 2);
53 | Assert.assertEquals("四绿木天权", m.getNineStar().toString());
54 | }
55 |
56 | @Test
57 | public void test8() {
58 | LunarMonth m = LunarMonth.fromYm(2022, 1);
59 | Assert.assertEquals("二黑土天璇", m.getNineStar().toString());
60 | }
61 |
62 | @Test
63 | public void test9() {
64 | LunarMonth m = LunarMonth.fromYm(2033, 1);
65 | Assert.assertEquals("五黄土玉衡", m.getNineStar().toString());
66 | }
67 |
68 | @Test
69 | public void test10() {
70 | Lunar d = Lunar.fromYmdHms(2033, 1, 1, 12, 0,0);
71 | Assert.assertEquals("七赤金摇光", d.getTimeNineStar().toString());
72 | }
73 |
74 | @Test
75 | public void test11() {
76 | Lunar d = Lunar.fromYmdHms(2011, 5, 3, 23, 0,0);
77 | Assert.assertEquals("七赤金摇光", d.getTimeNineStar().toString());
78 | }
79 |
80 | @Test
81 | public void test12() {
82 | LunarMonth m = LunarMonth.fromYm(2024, 11);
83 | Assert.assertEquals("四绿木天权", m.getNineStar().toString());
84 | m = LunarMonth.fromYm(2024, 12);
85 | Assert.assertEquals("三碧木天玑", m.getNineStar().toString());
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/java/test/SeasonTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.SolarSeason;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | /**
8 | * 季度测试
9 | *
10 | * @author 6tail
11 | */
12 | public class SeasonTest {
13 |
14 | @Test
15 | public void test(){
16 | SolarSeason season = new SolarSeason(2019,5);
17 | Assert.assertEquals("2019.2",season.toString());
18 | Assert.assertEquals("2019年2季度",season.toFullString());
19 |
20 | Assert.assertEquals("2019.3",season.next(1).toString());
21 | Assert.assertEquals("2019年3季度",season.next(1).toFullString());
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/test/ShuJiuTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.ShuJiu;
5 | import com.nlf.calendar.Solar;
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 |
9 | /**
10 | * 数九测试
11 | *
12 | * @author 6tail
13 | */
14 | public class ShuJiuTest {
15 |
16 | @Test
17 | public void test1(){
18 | Solar solar = new Solar(2020,12,21);
19 | Lunar lunar = solar.getLunar();
20 | ShuJiu shuJiu = lunar.getShuJiu();
21 | Assert.assertEquals(solar.toYmd(),"一九",shuJiu.toString());
22 | Assert.assertEquals(solar.toYmd(),"一九第1天",shuJiu.toFullString());
23 | }
24 |
25 | @Test
26 | public void test2(){
27 | Solar solar = new Solar(2020,12,22);
28 | Lunar lunar = solar.getLunar();
29 | ShuJiu shuJiu = lunar.getShuJiu();
30 | Assert.assertEquals(solar.toYmd(),"一九",shuJiu.toString());
31 | Assert.assertEquals(solar.toYmd(),"一九第2天",shuJiu.toFullString());
32 | }
33 |
34 | @Test
35 | public void test3(){
36 | Solar solar = new Solar(2020,1,7);
37 | Lunar lunar = solar.getLunar();
38 | ShuJiu shuJiu = lunar.getShuJiu();
39 | Assert.assertEquals(solar.toYmd(),"二九",shuJiu.toString());
40 | Assert.assertEquals(solar.toYmd(),"二九第8天",shuJiu.toFullString());
41 | }
42 |
43 | @Test
44 | public void test4(){
45 | Solar solar = new Solar(2021,1,6);
46 | Lunar lunar = solar.getLunar();
47 | ShuJiu shuJiu = lunar.getShuJiu();
48 | Assert.assertEquals(solar.toYmd(),"二九",shuJiu.toString());
49 | Assert.assertEquals(solar.toYmd(),"二九第8天",shuJiu.toFullString());
50 | }
51 |
52 | @Test
53 | public void test5(){
54 | Solar solar = new Solar(2021,1,8);
55 | Lunar lunar = solar.getLunar();
56 | ShuJiu shuJiu = lunar.getShuJiu();
57 | Assert.assertEquals(solar.toYmd(),"三九",shuJiu.toString());
58 | Assert.assertEquals(solar.toYmd(),"三九第1天",shuJiu.toFullString());
59 | }
60 |
61 | @Test
62 | public void test6(){
63 | Solar solar = new Solar(2021,3,5);
64 | Lunar lunar = solar.getLunar();
65 | ShuJiu shuJiu = lunar.getShuJiu();
66 | Assert.assertEquals(solar.toYmd(),"九九",shuJiu.toString());
67 | Assert.assertEquals(solar.toYmd(),"九九第3天",shuJiu.toFullString());
68 | }
69 |
70 | @Test
71 | public void test7(){
72 | Solar solar = new Solar(2021,7,5);
73 | Lunar lunar = solar.getLunar();
74 | ShuJiu shuJiu = lunar.getShuJiu();
75 | Assert.assertNull(solar.toYmd(),shuJiu);
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/src/test/java/test/SolarTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.Solar;
5 | import com.nlf.calendar.util.SolarUtil;
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 |
9 | /**
10 | * 阳历测试
11 | *
12 | * @author 6tail
13 | */
14 | public class SolarTest {
15 |
16 | @Test
17 | public void test(){
18 | Solar date = new Solar(2019,5,1);
19 | Assert.assertEquals("2019-05-01",date.toString());
20 | Assert.assertEquals("2019-05-01 00:00:00 星期三 (劳动节) 金牛座",date.toFullString());
21 | Assert.assertEquals("二〇一九年三月廿七",date.getLunar().toString());
22 | Assert.assertEquals("二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[艮](东北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]",date.getLunar().toFullString());
23 | }
24 |
25 | @Test
26 | public void test1(){
27 | Solar solar = new Solar(2020,5,24,13,0,0);
28 | Assert.assertEquals("二〇二〇年闰四月初二",solar.getLunar().toString());
29 | }
30 |
31 | @Test
32 | public void test6(){
33 | Solar solar = new Solar(11,1,1);
34 | Assert.assertEquals("一〇年腊月初八",solar.getLunar().toString());
35 | }
36 |
37 | @Test
38 | public void test7(){
39 | Solar solar = new Solar(11,3,1);
40 | Assert.assertEquals("一一年二月初八",solar.getLunar().toString());
41 | }
42 |
43 | @Test
44 | public void test9(){
45 | Solar solar = new Solar(26,4,13);
46 | Assert.assertEquals("二六年三月初八",solar.getLunar().toString());
47 | }
48 |
49 | @Test
50 | public void test10(){
51 | Assert.assertTrue(SolarUtil.isLeapYear(1500));
52 | }
53 |
54 | @Test
55 | public void testNext(){
56 | Solar date = new Solar(2020,1,23);
57 | Assert.assertEquals("2020-01-24",date.next(1).toString());
58 | // 仅工作日,跨越春节假期
59 | Assert.assertEquals("2020-02-03",date.next(1,true).toString());
60 |
61 | date = new Solar(2020,2,3);
62 | Assert.assertEquals("2020-01-31",date.next(-3).toString());
63 | // 仅工作日,跨越春节假期
64 | Assert.assertEquals("2020-01-21",date.next(-3,true).toString());
65 |
66 | date = new Solar(2020,2,9);
67 | Assert.assertEquals("2020-02-15",date.next(6).toString());
68 | // 仅工作日,跨越周末
69 | Assert.assertEquals("2020-02-17",date.next(6,true).toString());
70 |
71 | date = new Solar(2020,1,17);
72 | Assert.assertEquals("2020-01-18",date.next(1).toString());
73 | // 仅工作日,周日调休按上班算
74 | Assert.assertEquals("2020-01-19",date.next(1,true).toString());
75 | }
76 |
77 | @Test
78 | public void test11(){
79 | Solar solar = new Solar(2022, 3, 28);
80 | Assert.assertEquals("全国中小学生安全教育日",solar.getFestivals().get(0));
81 | }
82 |
83 | @Test
84 | public void test12(){
85 | Solar solar = new Solar(2022, 1, 1);
86 | Assert.assertEquals("2022-01-02", solar.next(1).toYmd());
87 | }
88 |
89 | @Test
90 | public void test13(){
91 | Solar solar = new Solar(2022, 1, 31);
92 | Assert.assertEquals("2022-02-01", solar.next(1).toYmd());
93 | }
94 |
95 | @Test
96 | public void test14(){
97 | Solar solar = new Solar(2022, 1, 1);
98 | Assert.assertEquals("2023-01-01", solar.next(365).toYmd());
99 | }
100 |
101 | @Test
102 | public void test15(){
103 | Solar solar = new Solar(2023, 1, 1);
104 | Assert.assertEquals("2022-01-01", solar.next(-365).toYmd());
105 | }
106 |
107 | @Test
108 | public void test16(){
109 | Solar solar = new Solar(1582, 10, 4);
110 | Assert.assertEquals("1582-10-15", solar.next(1).toYmd());
111 | }
112 |
113 | @Test
114 | public void test17(){
115 | Solar solar = new Solar(1582, 10, 4);
116 | Assert.assertEquals("1582-11-01", solar.next(18).toYmd());
117 | }
118 |
119 | @Test
120 | public void test18(){
121 | Solar solar = new Solar(1582, 11, 1);
122 | Assert.assertEquals("1582-10-04", solar.next(-18).toYmd());
123 | }
124 |
125 | @Test
126 | public void test19(){
127 | Solar solar = new Solar(1582, 11, 1);
128 | Assert.assertEquals("1582-10-15", solar.next(-17).toYmd());
129 | }
130 |
131 | @Test
132 | public void test20(){
133 | int days = SolarUtil.getDaysBetween(1582, 10, 4, 1582, 10, 15);
134 | Assert.assertEquals(1, days);
135 | }
136 |
137 | @Test
138 | public void test21(){
139 | int days = SolarUtil.getDaysBetween(1582, 10, 4, 1582, 11, 1);
140 | Assert.assertEquals(18, days);
141 | }
142 |
143 | @Test
144 | public void test22(){
145 | int days = SolarUtil.getDaysBetween(1582, 1, 1, 1583, 1, 1);
146 | Assert.assertEquals(355, days);
147 | }
148 |
149 | @Test
150 | public void test23(){
151 | Solar solar = Solar.fromYmd(1991, 5, 12);
152 | Lunar lunar = solar.getLunar();
153 | Assert.assertEquals("壬午", lunar.getDayInGanZhi());
154 | }
155 |
156 | @Test
157 | public void test24(){
158 | Solar solar = new Solar(1582, 10, 15);
159 | Assert.assertEquals("1582-09-30", solar.next(-5).toYmd());
160 | }
161 |
162 | @Test
163 | public void test25(){
164 | Solar solar = new Solar(1582, 10, 15);
165 | Assert.assertEquals("1582-10-04", solar.next(-1).toYmd());
166 | }
167 |
168 | @Test
169 | public void test26(){
170 | Solar solar = new Solar(1582, 10, 15);
171 | Assert.assertEquals("1582-09-29", solar.next(-6).toYmd());
172 | }
173 |
174 | @Test
175 | public void test27(){
176 | Solar solar = Solar.fromYmd(2023, 8, 31);
177 | Assert.assertEquals("2023-09-30", solar.nextMonth(1).toYmd());
178 | }
179 |
180 | @Test
181 | public void test28(){
182 | Solar solar = Solar.fromYmd(2023, 8, 31);
183 | Assert.assertEquals("2023-10-31", solar.nextMonth(2).toYmd());
184 | }
185 |
186 | @Test
187 | public void test29(){
188 | Solar solar = Solar.fromYmd(2023, 8, 31);
189 | Assert.assertEquals("2025-08-31", solar.nextYear(2).toYmd());
190 | }
191 |
192 | @Test
193 | public void test30(){
194 | Solar solar = Solar.fromYmd(2023, 8, 31);
195 | Assert.assertEquals("2024-02-29", solar.nextMonth(6).toYmd());
196 | }
197 |
198 | }
199 |
--------------------------------------------------------------------------------
/src/test/java/test/SolarWeekTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.SolarWeek;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | /**
8 | * 阳历周测试
9 | *
10 | * @author 6tail
11 | */
12 | public class SolarWeekTest {
13 |
14 | @Test
15 | public void test() {
16 | SolarWeek week = SolarWeek.fromYmd(2022, 5, 1, 0);
17 | Assert.assertEquals(1, week.getIndex());
18 | }
19 |
20 | @Test
21 | public void test1() {
22 | SolarWeek week = SolarWeek.fromYmd(2022, 5, 7, 0);
23 | Assert.assertEquals(1, week.getIndex());
24 | }
25 |
26 | @Test
27 | public void test2() {
28 | SolarWeek week = SolarWeek.fromYmd(2022, 5, 8, 0);
29 | Assert.assertEquals(2, week.getIndex());
30 | }
31 |
32 | @Test
33 | public void test3() {
34 | SolarWeek week = SolarWeek.fromYmd(2022, 5, 1, 1);
35 | Assert.assertEquals(1, week.getIndex());
36 | }
37 |
38 | @Test
39 | public void test4() {
40 | SolarWeek week = SolarWeek.fromYmd(2022, 5, 2, 1);
41 | Assert.assertEquals(2, week.getIndex());
42 | }
43 |
44 | @Test
45 | public void test5() {
46 | SolarWeek week = SolarWeek.fromYmd(2022, 5, 8, 1);
47 | Assert.assertEquals(2, week.getIndex());
48 | }
49 |
50 | @Test
51 | public void test6() {
52 | SolarWeek week = SolarWeek.fromYmd(2021, 11, 1, 0);
53 | Assert.assertEquals(1, week.getIndex());
54 | }
55 |
56 | @Test
57 | public void test7() {
58 | SolarWeek week = SolarWeek.fromYmd(2021, 11, 1, 1);
59 | Assert.assertEquals(1, week.getIndex());
60 | }
61 |
62 | @Test
63 | public void test8() {
64 | SolarWeek week = SolarWeek.fromYmd(2021, 5, 2, 2);
65 | Assert.assertEquals(1, week.getIndex());
66 | }
67 |
68 | @Test
69 | public void test9() {
70 | SolarWeek week = SolarWeek.fromYmd(2021, 5, 4, 2);
71 | Assert.assertEquals(2, week.getIndex());
72 | }
73 |
74 | @Test
75 | public void test10() {
76 | SolarWeek week = SolarWeek.fromYmd(2022, 3, 6, 0);
77 | Assert.assertEquals(11, week.getIndexInYear());
78 | }
79 |
80 | @Test
81 | public void test11() {
82 | SolarWeek week = SolarWeek.fromYmd(2022, 3, 6, 1);
83 | Assert.assertEquals(10, week.getIndexInYear());
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/test/java/test/TaoTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.Tao;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 |
8 | /**
9 | * 道历测试
10 | *
11 | * @author 6tail
12 | */
13 | public class TaoTest {
14 |
15 | @Test
16 | public void test() {
17 | Tao tao = Tao.fromLunar(Lunar.fromYmdHms(2021, 10, 17, 18, 0, 0));
18 | Assert.assertEquals("四七一八年十月十七", tao.toString());
19 | Assert.assertEquals("道歷四七一八年,天運辛丑年,己亥月,癸酉日。十月十七日,酉時。", tao.toFullString());
20 | }
21 |
22 | @Test
23 | public void test1() {
24 | Tao tao = Tao.fromYmd(4718, 10, 18);
25 | Assert.assertEquals("[地母娘娘圣诞, 四时会]", tao.getFestivals().toString());
26 |
27 | tao = Lunar.fromYmd(2021, 10, 18).getTao();
28 | Assert.assertEquals("[地母娘娘圣诞, 四时会]", tao.getFestivals().toString());
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/java/test/TimeTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.util.LunarUtil;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 |
8 | import java.util.HashMap;
9 | import java.util.LinkedHashMap;
10 | import java.util.Map;
11 |
12 | /**
13 | * 时辰测试
14 | *
15 | * @author 6tail
16 | */
17 | public class TimeTest {
18 |
19 | private static final Map ZHI = new LinkedHashMap(){
20 | private static final long serialVersionUID = -1L;
21 | {
22 | put("23:00","子");
23 | put("00:59","子");
24 | put("23:30","子");
25 |
26 | put("01:00","丑");
27 | put("02:59","丑");
28 | put("01:30","丑");
29 |
30 | put("03:00","寅");
31 | put("04:59","寅");
32 | put("03:30","寅");
33 |
34 | put("05:00","卯");
35 | put("06:59","卯");
36 | put("05:30","卯");
37 |
38 | put("07:00","辰");
39 | put("08:59","辰");
40 | put("07:30","辰");
41 |
42 | put("09:00","巳");
43 | put("10:59","巳");
44 | put("09:30","巳");
45 |
46 | put("11:00","午");
47 | put("12:59","午");
48 | put("11:30","午");
49 |
50 | put("13:00","未");
51 | put("14:59","未");
52 | put("13:30","未");
53 |
54 | put("15:00","申");
55 | put("16:59","申");
56 | put("15:30","申");
57 |
58 | put("17:00","酉");
59 | put("18:59","酉");
60 | put("17:30","酉");
61 |
62 | put("19:00","戌");
63 | put("20:59","戌");
64 | put("19:30","戌");
65 |
66 | put("21:00","亥");
67 | put("22:59","亥");
68 | put("21:30","亥");
69 |
70 | put(null,"子");
71 |
72 | put("","子");
73 | put("23:01:01","子");
74 | put("其他","子");
75 |
76 | put("21:01:01","亥");
77 | }
78 | };
79 |
80 | private static final Map GAN = new LinkedHashMap(){
81 | private static final long serialVersionUID = -1L;
82 | {
83 | //晚子时
84 | put("2020-4,5,23:00","戊");
85 | //早子时
86 | put("2020-4,5,00:59","丙");
87 | //晚子时
88 | put("2020-4,5,23:30","戊");
89 |
90 | put("2020-4,5,01:00","丁");
91 | put("2020-4,5,02:59","丁");
92 | put("2020-4,5,01:30","丁");
93 |
94 | put("2020-4,5,03:00","戊");
95 | put("2020-4,5,04:59","戊");
96 | put("2020-4,5,03:30","戊");
97 |
98 | put("2020-4,5,05:00","己");
99 | put("2020-4,5,06:59","己");
100 | put("2020-4,5,05:30","己");
101 |
102 | put("2020-4,5,07:00","庚");
103 | put("2020-4,5,08:59","庚");
104 | put("2020-4,5,07:30","庚");
105 |
106 | put("2020-4,5,09:00","辛");
107 | put("2020-4,5,10:59","辛");
108 | put("2020-4,5,09:30","辛");
109 |
110 | put("2020-4,5,11:00","壬");
111 | put("2020-4,5,12:59","壬");
112 | put("2020-4,5,11:30","壬");
113 |
114 | put("2020-4,5,13:00","癸");
115 | put("2020-4,5,14:59","癸");
116 | put("2020-4,5,13:30","癸");
117 |
118 | put("2020-4,5,15:00","甲");
119 | put("2020-4,5,16:59","甲");
120 | put("2020-4,5,15:30","甲");
121 |
122 | put("2020-4,5,17:00","乙");
123 | put("2020-4,5,18:59","乙");
124 | put("2020-4,5,17:30","乙");
125 |
126 | put("2020-4,5,19:00","丙");
127 | put("2020-4,5,20:59","丙");
128 | put("2020-4,5,19:30","丙");
129 |
130 | put("2020-4,5,21:00","丁");
131 | put("2020-4,5,22:59","丁");
132 | put("2020-4,5,21:30","丁");
133 |
134 | put("2020-4,5,null","丙");
135 |
136 | put("2020-4,5,","丙");
137 | put("2020-4,5,23:01:01","戊");
138 | put("2020-4,5,其他","丙");
139 | put("2020-4,5,0:90","丙");
140 |
141 | put("2020-4,5,21:01:01","丁");
142 |
143 | put("2020-4,2,23:00","壬");
144 | put("2020-4,2,11:20","丙");
145 | }
146 | };
147 |
148 | private static final Map GAN_ZHI = new HashMap(){
149 | private static final long serialVersionUID = -1L;
150 | {
151 | //晚子时
152 | put("2020-4,5,23:00","戊子");
153 | //早子时
154 | put("2020-4,5,00:59","丙子");
155 | //晚子时
156 | put("2020-4,5,23:30","戊子");
157 |
158 | put("2020-4,5,01:00","丁丑");
159 | put("2020-4,5,02:59","丁丑");
160 | put("2020-4,5,01:30","丁丑");
161 |
162 | put("2020-4,5,03:00","戊寅");
163 | put("2020-4,5,04:59","戊寅");
164 | put("2020-4,5,03:30","戊寅");
165 |
166 | put("2020-4,5,05:00","己卯");
167 | put("2020-4,5,06:59","己卯");
168 | put("2020-4,5,05:30","己卯");
169 |
170 | put("2020-4,5,07:00","庚辰");
171 | put("2020-4,5,08:59","庚辰");
172 | put("2020-4,5,07:30","庚辰");
173 |
174 | put("2020-4,5,09:00","辛巳");
175 | put("2020-4,5,10:59","辛巳");
176 | put("2020-4,5,09:30","辛巳");
177 |
178 | put("2020-4,5,11:00","壬午");
179 | put("2020-4,5,12:59","壬午");
180 | put("2020-4,5,11:30","壬午");
181 |
182 | put("2020-4,5,13:00","癸未");
183 | put("2020-4,5,14:59","癸未");
184 | put("2020-4,5,13:30","癸未");
185 |
186 | put("2020-4,5,15:00","甲申");
187 | put("2020-4,5,16:59","甲申");
188 | put("2020-4,5,15:30","甲申");
189 |
190 | put("2020-4,5,17:00","乙酉");
191 | put("2020-4,5,18:59","乙酉");
192 | put("2020-4,5,17:30","乙酉");
193 |
194 | put("2020-4,5,19:00","丙戌");
195 | put("2020-4,5,20:59","丙戌");
196 | put("2020-4,5,19:30","丙戌");
197 |
198 | put("2020-4,5,21:00","丁亥");
199 | put("2020-4,5,22:59","丁亥");
200 | put("2020-4,5,21:30","丁亥");
201 |
202 | put("2020-4,5,null","丙子");
203 |
204 | put("2020-4,5,","丙子");
205 | put("2020-4,5,23:01:01","戊子");
206 | put("2020-4,5,其他","丙子");
207 | put("2020-4,5,0:90","丙子");
208 |
209 | put("2020-4,5,20:21:01","丙戌");
210 | put("2020-4,5,21:01:01","丁亥");
211 | put("2020-4,5,01:21:01","丁丑");
212 |
213 | put("2020-4,2,23:00","壬子");
214 | put("2020-4,2,11:20","丙午");
215 | put("20204,28,23:20","甲子");
216 | put("20204,29,00:20","甲子");
217 | }
218 | };
219 |
220 | @Test
221 | public void testLunarTimeGanZhi(){
222 | for(Map.Entry entry:GAN_ZHI.entrySet()){
223 | int hour = 0,minute = 0;
224 | String time = entry.getKey();
225 | int year = Integer.parseInt(time.substring(0,4));
226 | int month = Integer.parseInt(time.substring(4,time.indexOf(",")));
227 | int day = Integer.parseInt(time.substring(time.indexOf(",")+1,time.lastIndexOf(",")));
228 | String hm = time.substring(time.lastIndexOf(",")+1);
229 | if(hm.length()>=5){
230 | hour = Integer.parseInt(hm.substring(0,2),10);
231 | minute = Integer.parseInt(hm.substring(3,5),10);
232 | }
233 | Lunar lunar = Lunar.fromYmdHms(year,month,day,hour,minute,0);
234 | String ganZhi = entry.getValue();
235 | Assert.assertEquals(lunar.getYear()+"年"+lunar.getMonthInChinese()+"月"+lunar.getDayInChinese()+" "+hm, ganZhi, lunar.getTimeInGanZhi());
236 | }
237 | }
238 | @Test
239 | public void testLunarTimeGan(){
240 | for(Map.Entry entry:GAN.entrySet()){
241 | int hour = 0,minute = 0;
242 | String time = entry.getKey();
243 | int year = Integer.parseInt(time.substring(0,4));
244 | int month = Integer.parseInt(time.substring(4,time.indexOf(",")));
245 | int day = Integer.parseInt(time.substring(time.indexOf(",")+1,time.lastIndexOf(",")));
246 | String hm = time.substring(time.lastIndexOf(",")+1);
247 | if(hm.length()>=5){
248 | hour = Integer.parseInt(hm.substring(0,2),10);
249 | minute = Integer.parseInt(hm.substring(3,5),10);
250 | }
251 | Lunar lunar = Lunar.fromYmdHms(year,month,day,hour,minute,0);
252 | String gan = entry.getValue();
253 | Assert.assertEquals(lunar.getYear()+"年"+lunar.getMonthInChinese()+"月"+lunar.getDayInChinese()+" "+hm, gan, lunar.getTimeGan());
254 | }
255 | }
256 |
257 |
258 | @Test
259 | public void test(){
260 | for(Map.Entry entry:ZHI.entrySet()){
261 | String hm = entry.getKey();
262 | String zhi = entry.getValue();
263 | Assert.assertEquals(hm, zhi, LunarUtil.convertTime(hm));
264 | }
265 | }
266 | }
267 |
--------------------------------------------------------------------------------
/src/test/java/test/WeekTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Solar;
4 | import com.nlf.calendar.SolarWeek;
5 | import com.nlf.calendar.util.SolarUtil;
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 |
9 | /**
10 | * 周测试
11 | *
12 | * @author 6tail
13 | */
14 | public class WeekTest {
15 |
16 | @Test
17 | public void testFromMonday(){
18 | //一周的开始从星期一开始计
19 | int start = 1;
20 | SolarWeek week = new SolarWeek(2019,5,1,start);
21 | Assert.assertEquals("2019.5.1",week.toString());
22 | Assert.assertEquals("2019年5月第1周",week.toFullString());
23 | //当月共几周
24 | Assert.assertEquals(5,SolarUtil.getWeeksOfMonth(week.getYear(),week.getMonth(),start));
25 | //当周第一天
26 | Assert.assertEquals("2019-04-29",week.getFirstDay().toString());
27 | //当周第一天(本月)
28 | Assert.assertEquals("2019-05-01",week.getFirstDayInMonth().toString());
29 | }
30 |
31 | @Test
32 | public void testFromSunday(){
33 | //一周的开始从星期日开始计
34 | int start = 0;
35 | SolarWeek week = new SolarWeek(2019,5,1,start);
36 | Assert.assertEquals("2019.5.1",week.toString());
37 | Assert.assertEquals("2019年5月第1周",week.toFullString());
38 | //当月共几周
39 | Assert.assertEquals(5,SolarUtil.getWeeksOfMonth(week.getYear(),week.getMonth(),start));
40 | //当周第一天
41 | Assert.assertEquals("2019-04-28",week.getFirstDay().toString());
42 | //当周第一天(本月)
43 | Assert.assertEquals("2019-05-01",week.getFirstDayInMonth().toString());
44 | }
45 |
46 | @Test
47 | public void test1(){
48 | Solar solar = Solar.fromYmd(1582, 10, 1);
49 | Assert.assertEquals(1, solar.getWeek());
50 | }
51 |
52 | @Test
53 | public void test2(){
54 | Solar solar = Solar.fromYmd(1582, 10, 15);
55 | Assert.assertEquals(5, solar.getWeek());
56 | }
57 |
58 | @Test
59 | public void test3(){
60 | Solar solar = Solar.fromYmd(1129, 11, 17);
61 | Assert.assertEquals(0, solar.getWeek());
62 | }
63 |
64 | @Test
65 | public void test4(){
66 | Solar solar = Solar.fromYmd(1129, 11, 1);
67 | Assert.assertEquals(5, solar.getWeek());
68 | }
69 |
70 | @Test
71 | public void test5(){
72 | Solar solar = Solar.fromYmd(8, 11, 1);
73 | Assert.assertEquals(4, solar.getWeek());
74 | }
75 |
76 | @Test
77 | public void test6(){
78 | Solar solar = Solar.fromYmd(1582, 9, 30);
79 | Assert.assertEquals(0, solar.getWeek());
80 | }
81 |
82 | @Test
83 | public void test7(){
84 | Solar solar = Solar.fromYmd(1582, 1, 1);
85 | Assert.assertEquals(1, solar.getWeek());
86 | }
87 |
88 | @Test
89 | public void test8(){
90 | Solar solar = Solar.fromYmd(1500, 2, 29);
91 | Assert.assertEquals(6, solar.getWeek());
92 | }
93 |
94 | @Test
95 | public void test9(){
96 | Solar solar = Solar.fromYmd(9865, 7, 26);
97 | Assert.assertEquals(3, solar.getWeek());
98 | }
99 |
100 | @Test
101 | public void test10(){
102 | Assert.assertEquals(6, Solar.fromYmd(1961, 9, 30).getWeek());
103 | Assert.assertEquals(6, Solar.fromYmdHms(1961, 9, 30, 23, 59, 59).getWeek());
104 | Assert.assertEquals(6, Solar.fromYmdHms(1961, 9, 30, 20, 0, 0).getWeek());
105 | }
106 |
107 | @Test
108 | public void test11(){
109 | Assert.assertEquals(3, Solar.fromYmdHms(2021, 9, 15, 20, 0, 0).getWeek());
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/src/test/java/test/WuHouTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Lunar;
4 | import com.nlf.calendar.Solar;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 |
8 | /**
9 | * 物候测试
10 | *
11 | * @author 6tail
12 | */
13 | public class WuHouTest {
14 |
15 | @Test
16 | public void test1(){
17 | Solar solar = new Solar(2020,4,23);
18 | Lunar lunar = solar.getLunar();
19 | Assert.assertEquals(solar.toString(),"萍始生",lunar.getWuHou());
20 | }
21 |
22 | @Test
23 | public void test2(){
24 | Solar solar = new Solar(2021,1,15);
25 | Lunar lunar = solar.getLunar();
26 | Assert.assertEquals(solar.toString(),"雉始雊",lunar.getWuHou());
27 | }
28 |
29 | @Test
30 | public void test3(){
31 | Solar solar = new Solar(2017,1,5);
32 | Lunar lunar = solar.getLunar();
33 | Assert.assertEquals(solar.toString(),"雁北乡",lunar.getWuHou());
34 | }
35 |
36 | @Test
37 | public void test4(){
38 | Solar solar = new Solar(2020,4,10);
39 | Lunar lunar = solar.getLunar();
40 | Assert.assertEquals(solar.toString(),"田鼠化为鴽",lunar.getWuHou());
41 | }
42 |
43 | @Test
44 | public void test5(){
45 | Solar solar = new Solar(2020,6,11);
46 | Lunar lunar = solar.getLunar();
47 | Assert.assertEquals(solar.toString(),"鵙始鸣",lunar.getWuHou());
48 | }
49 |
50 | @Test
51 | public void test6(){
52 | Solar solar = new Solar(2020,6,1);
53 | Lunar lunar = solar.getLunar();
54 | Assert.assertEquals(solar.toString(),"麦秋至",lunar.getWuHou());
55 | }
56 |
57 | @Test
58 | public void test7(){
59 | Solar solar = new Solar(2020,12,8);
60 | Lunar lunar = solar.getLunar();
61 | Assert.assertEquals(solar.toString(),"鹖鴠不鸣",lunar.getWuHou());
62 | }
63 |
64 | @Test
65 | public void test8(){
66 | Solar solar = new Solar(2020,12,11);
67 | Lunar lunar = solar.getLunar();
68 | Assert.assertEquals(solar.toString(),"鹖鴠不鸣",lunar.getWuHou());
69 | }
70 |
71 | @Test
72 | public void test9(){
73 | Solar solar = new Solar(1982,12,22);
74 | Lunar lunar = solar.getLunar();
75 | Assert.assertEquals(solar.toString(),"蚯蚓结",lunar.getWuHou());
76 | }
77 |
78 | @Test
79 | public void test10(){
80 | Solar solar = new Solar(2021,12,21);
81 | Lunar lunar = solar.getLunar();
82 | Assert.assertEquals(solar.toString(),"冬至 初候",lunar.getHou());
83 | }
84 |
85 | @Test
86 | public void test11(){
87 | Solar solar = new Solar(2021,12,26);
88 | Lunar lunar = solar.getLunar();
89 | Assert.assertEquals(solar.toString(),"冬至 二候",lunar.getHou());
90 | }
91 |
92 | @Test
93 | public void test12(){
94 | Solar solar = new Solar(2021,12,31);
95 | Lunar lunar = solar.getLunar();
96 | Assert.assertEquals(solar.toString(),"冬至 三候",lunar.getHou());
97 | }
98 |
99 | @Test
100 | public void test13(){
101 | Solar solar = new Solar(2022,1,5);
102 | Lunar lunar = solar.getLunar();
103 | Assert.assertEquals(solar.toString(),"小寒 初候",lunar.getHou());
104 | }
105 |
106 | @Test
107 | public void test15(){
108 | Solar solar = new Solar(2022,8,22);
109 | Lunar lunar = solar.getLunar();
110 | Assert.assertEquals(solar.toString(),"寒蝉鸣",lunar.getWuHou());
111 | }
112 |
113 | @Test
114 | public void test16(){
115 | Solar solar = new Solar(2022,8,23);
116 | Lunar lunar = solar.getLunar();
117 | Assert.assertEquals(solar.toString(),"鹰乃祭鸟",lunar.getWuHou());
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/src/test/java/test/XingZuoTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.Solar;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | /**
8 | * 星座测试
9 | *
10 | * @author 6tail
11 | */
12 | public class XingZuoTest {
13 |
14 | @Test
15 | public void test1(){
16 | Solar solar = new Solar(2020,3,21);
17 | Assert.assertEquals(solar.toYmd(),"白羊",solar.getXingZuo());
18 | solar = new Solar(2020,4,19);
19 | Assert.assertEquals(solar.toYmd(),"白羊",solar.getXingZuo());
20 | }
21 |
22 | @Test
23 | public void test2(){
24 | Solar solar = new Solar(2020,4,20);
25 | Assert.assertEquals(solar.toYmd(),"金牛",solar.getXingZuo());
26 | solar = new Solar(2020,5,20);
27 | Assert.assertEquals(solar.toYmd(),"金牛",solar.getXingZuo());
28 | }
29 |
30 | @Test
31 | public void test3(){
32 | Solar solar = new Solar(2020,5,21);
33 | Assert.assertEquals(solar.toYmd(),"双子",solar.getXingZuo());
34 | solar = new Solar(2020,6,21);
35 | Assert.assertEquals(solar.toYmd(),"双子",solar.getXingZuo());
36 | }
37 |
38 | @Test
39 | public void test4(){
40 | Solar solar = new Solar(2020,6,22);
41 | Assert.assertEquals(solar.toYmd(),"巨蟹",solar.getXingZuo());
42 | solar = new Solar(2020,7,22);
43 | Assert.assertEquals(solar.toYmd(),"巨蟹",solar.getXingZuo());
44 | }
45 |
46 | @Test
47 | public void test5(){
48 | Solar solar = new Solar(2020,7,23);
49 | Assert.assertEquals(solar.toYmd(),"狮子",solar.getXingZuo());
50 | solar = new Solar(2020,8,22);
51 | Assert.assertEquals(solar.toYmd(),"狮子",solar.getXingZuo());
52 | }
53 |
54 | @Test
55 | public void test6(){
56 | Solar solar = new Solar(2020,8,23);
57 | Assert.assertEquals(solar.toYmd(),"处女",solar.getXingZuo());
58 | solar = new Solar(2020,9,22);
59 | Assert.assertEquals(solar.toYmd(),"处女",solar.getXingZuo());
60 | }
61 |
62 | @Test
63 | public void test7(){
64 | Solar solar = new Solar(2020,9,23);
65 | Assert.assertEquals(solar.toYmd(),"天秤",solar.getXingZuo());
66 | solar = new Solar(2020,10,23);
67 | Assert.assertEquals(solar.toYmd(),"天秤",solar.getXingZuo());
68 | }
69 |
70 | @Test
71 | public void test8(){
72 | Solar solar = new Solar(2020,10,24);
73 | Assert.assertEquals(solar.toYmd(),"天蝎",solar.getXingZuo());
74 | solar = new Solar(2020,11,22);
75 | Assert.assertEquals(solar.toYmd(),"天蝎",solar.getXingZuo());
76 | }
77 |
78 | @Test
79 | public void test9(){
80 | Solar solar = new Solar(2020,11,23);
81 | Assert.assertEquals(solar.toYmd(),"射手",solar.getXingZuo());
82 | solar = new Solar(2020,12,21);
83 | Assert.assertEquals(solar.toYmd(),"射手",solar.getXingZuo());
84 | }
85 |
86 | @Test
87 | public void test10(){
88 | Solar solar = new Solar(2020,12,22);
89 | Assert.assertEquals(solar.toYmd(),"摩羯",solar.getXingZuo());
90 | solar = new Solar(2021,1,19);
91 | Assert.assertEquals(solar.toYmd(),"摩羯",solar.getXingZuo());
92 | }
93 |
94 | @Test
95 | public void test11(){
96 | Solar solar = new Solar(2021,1,20);
97 | Assert.assertEquals(solar.toYmd(),"水瓶",solar.getXingZuo());
98 | solar = new Solar(2021,2,18);
99 | Assert.assertEquals(solar.toYmd(),"水瓶",solar.getXingZuo());
100 | }
101 |
102 | @Test
103 | public void test12(){
104 | Solar solar = new Solar(2021,2,19);
105 | Assert.assertEquals(solar.toYmd(),"双鱼",solar.getXingZuo());
106 | solar = new Solar(2021,3,20);
107 | Assert.assertEquals(solar.toYmd(),"双鱼",solar.getXingZuo());
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/test/java/test/XunTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.EightChar;
4 | import com.nlf.calendar.Lunar;
5 | import com.nlf.calendar.Solar;
6 | import com.nlf.calendar.util.LunarUtil;
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * 旬测试
15 | *
16 | * @author 6tail
17 | */
18 | public class XunTest {
19 |
20 | @Test
21 | public void testXun(){
22 | Map xun = new HashMap();
23 | xun.put("甲子","甲子");
24 | xun.put("乙丑","甲子");
25 | xun.put("丙寅","甲子");
26 | xun.put("丁卯","甲子");
27 | xun.put("戊辰","甲子");
28 | xun.put("己巳","甲子");
29 | xun.put("庚午","甲子");
30 | xun.put("辛未","甲子");
31 | xun.put("壬申","甲子");
32 | xun.put("癸酉","甲子");
33 | xun.put("甲戌","甲戌");
34 | xun.put("乙亥","甲戌");
35 | xun.put("丙子","甲戌");
36 | xun.put("丁丑","甲戌");
37 | xun.put("戊寅","甲戌");
38 | xun.put("己卯","甲戌");
39 | xun.put("庚辰","甲戌");
40 | xun.put("辛巳","甲戌");
41 | xun.put("壬午","甲戌");
42 | xun.put("癸未","甲戌");
43 | xun.put("甲申","甲申");
44 | xun.put("乙酉","甲申");
45 | xun.put("丙戌","甲申");
46 | xun.put("丁亥","甲申");
47 | xun.put("戊子","甲申");
48 | xun.put("己丑","甲申");
49 | xun.put("庚寅","甲申");
50 | xun.put("辛卯","甲申");
51 | xun.put("壬辰","甲申");
52 | xun.put("癸巳","甲申");
53 | xun.put("甲午","甲午");
54 | xun.put("乙未","甲午");
55 | xun.put("丙申","甲午");
56 | xun.put("丁酉","甲午");
57 | xun.put("戊戌","甲午");
58 | xun.put("己亥","甲午");
59 | xun.put("庚子","甲午");
60 | xun.put("辛丑","甲午");
61 | xun.put("壬寅","甲午");
62 | xun.put("癸卯","甲午");
63 | xun.put("甲辰","甲辰");
64 | xun.put("乙巳","甲辰");
65 | xun.put("丙午","甲辰");
66 | xun.put("丁未","甲辰");
67 | xun.put("戊申","甲辰");
68 | xun.put("己酉","甲辰");
69 | xun.put("庚戌","甲辰");
70 | xun.put("辛亥","甲辰");
71 | xun.put("壬子","甲辰");
72 | xun.put("癸丑","甲辰");
73 | xun.put("甲寅","甲寅");
74 | xun.put("乙卯","甲寅");
75 | xun.put("丙辰","甲寅");
76 | xun.put("丁巳","甲寅");
77 | xun.put("戊午","甲寅");
78 | xun.put("己未","甲寅");
79 | xun.put("庚申","甲寅");
80 | xun.put("辛酉","甲寅");
81 | xun.put("壬戌","甲寅");
82 | xun.put("癸亥","甲寅");
83 |
84 | for(Map.Entry entry:xun.entrySet()){
85 | Assert.assertEquals(entry.getValue(), LunarUtil.getXun(entry.getKey()));
86 | }
87 | }
88 |
89 | @Test
90 | public void testXunKong(){
91 | Map kong = new HashMap();
92 | kong.put("甲子","戌亥");
93 | kong.put("乙丑","戌亥");
94 | kong.put("丙寅","戌亥");
95 | kong.put("丁卯","戌亥");
96 | kong.put("戊辰","戌亥");
97 | kong.put("己巳","戌亥");
98 | kong.put("庚午","戌亥");
99 | kong.put("辛未","戌亥");
100 | kong.put("壬申","戌亥");
101 | kong.put("癸酉","戌亥");
102 | kong.put("甲戌","申酉");
103 | kong.put("乙亥","申酉");
104 | kong.put("丙子","申酉");
105 | kong.put("丁丑","申酉");
106 | kong.put("戊寅","申酉");
107 | kong.put("己卯","申酉");
108 | kong.put("庚辰","申酉");
109 | kong.put("辛巳","申酉");
110 | kong.put("壬午","申酉");
111 | kong.put("癸未","申酉");
112 | kong.put("甲申","午未");
113 | kong.put("乙酉","午未");
114 | kong.put("丙戌","午未");
115 | kong.put("丁亥","午未");
116 | kong.put("戊子","午未");
117 | kong.put("己丑","午未");
118 | kong.put("庚寅","午未");
119 | kong.put("辛卯","午未");
120 | kong.put("壬辰","午未");
121 | kong.put("癸巳","午未");
122 | kong.put("甲午","辰巳");
123 | kong.put("乙未","辰巳");
124 | kong.put("丙申","辰巳");
125 | kong.put("丁酉","辰巳");
126 | kong.put("戊戌","辰巳");
127 | kong.put("己亥","辰巳");
128 | kong.put("庚子","辰巳");
129 | kong.put("辛丑","辰巳");
130 | kong.put("壬寅","辰巳");
131 | kong.put("癸卯","辰巳");
132 | kong.put("甲辰","寅卯");
133 | kong.put("乙巳","寅卯");
134 | kong.put("丙午","寅卯");
135 | kong.put("丁未","寅卯");
136 | kong.put("戊申","寅卯");
137 | kong.put("己酉","寅卯");
138 | kong.put("庚戌","寅卯");
139 | kong.put("辛亥","寅卯");
140 | kong.put("壬子","寅卯");
141 | kong.put("癸丑","寅卯");
142 | kong.put("甲寅","子丑");
143 | kong.put("乙卯","子丑");
144 | kong.put("丙辰","子丑");
145 | kong.put("丁巳","子丑");
146 | kong.put("戊午","子丑");
147 | kong.put("己未","子丑");
148 | kong.put("庚申","子丑");
149 | kong.put("辛酉","子丑");
150 | kong.put("壬戌","子丑");
151 | kong.put("癸亥","子丑");
152 |
153 | for(Map.Entry entry:kong.entrySet()){
154 | Assert.assertEquals(entry.getValue(), LunarUtil.getXunKong(entry.getKey()));
155 | }
156 | }
157 |
158 | @Test
159 | public void testXun1(){
160 | Solar solar = new Solar(2020,11,19,0,0,0);
161 | Lunar lunar = solar.getLunar();
162 | Assert.assertEquals("甲午",lunar.getYearXun());
163 | }
164 |
165 | @Test
166 | public void testXunKong1(){
167 | Solar solar = new Solar(2020,11,19,0,0,0);
168 | Lunar lunar = solar.getLunar();
169 | Assert.assertEquals("辰巳",lunar.getYearXunKong());
170 | Assert.assertEquals("午未",lunar.getMonthXunKong());
171 | Assert.assertEquals("戌亥",lunar.getDayXunKong());
172 | }
173 |
174 | @Test
175 | public void testBaZiDayXunKong(){
176 | Solar solar = new Solar(1990,12,23,8,37,0);
177 | Lunar lunar = solar.getLunar();
178 | EightChar eightChar = lunar.getEightChar();
179 | Assert.assertEquals("子丑",eightChar.getDayXunKong());
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/src/test/java/test/YearTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.LunarYear;
4 | import com.nlf.calendar.SolarYear;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 |
8 | /**
9 | * 年份测试
10 | *
11 | * @author 6tail
12 | */
13 | public class YearTest {
14 |
15 | @Test
16 | public void test(){
17 | SolarYear year = new SolarYear(2019);
18 | Assert.assertEquals("2019",year.toString());
19 | Assert.assertEquals("2019年",year.toFullString());
20 |
21 | Assert.assertEquals("2020",year.next(1).toString());
22 | Assert.assertEquals("2020年",year.next(1).toFullString());
23 | }
24 |
25 | @Test
26 | public void test1(){
27 | LunarYear year = new LunarYear(2017);
28 | Assert.assertEquals("二龙治水",year.getZhiShui());
29 |
30 | year = new LunarYear(2018);
31 | Assert.assertEquals("二龙治水",year.getZhiShui());
32 |
33 | year = new LunarYear(2019);
34 | Assert.assertEquals("八龙治水",year.getZhiShui());
35 |
36 | year = new LunarYear(5);
37 | Assert.assertEquals("三龙治水",year.getZhiShui());
38 | }
39 |
40 | @Test
41 | public void test2(){
42 | LunarYear year = new LunarYear(2017);
43 | Assert.assertEquals("二人分饼",year.getFenBing());
44 |
45 | year = new LunarYear(2018);
46 | Assert.assertEquals("八人分饼",year.getFenBing());
47 |
48 | year = new LunarYear(5);
49 | Assert.assertEquals("一人分饼",year.getFenBing());
50 | }
51 |
52 | @Test
53 | public void test3(){
54 | LunarYear year = new LunarYear(2021);
55 | Assert.assertEquals("十一牛耕田",year.getGengTian());
56 | }
57 |
58 | @Test
59 | public void test4(){
60 | LunarYear year = new LunarYear(2018);
61 | Assert.assertEquals("三日得金",year.getDeJin());
62 | }
63 |
64 | @Test
65 | public void test5(){
66 | LunarYear year = new LunarYear(1864);
67 | Assert.assertEquals("上元",year.getYuan());
68 | }
69 |
70 | @Test
71 | public void test6(){
72 | LunarYear year = new LunarYear(1923);
73 | Assert.assertEquals("上元",year.getYuan());
74 | }
75 |
76 | @Test
77 | public void test7(){
78 | LunarYear year = new LunarYear(1924);
79 | Assert.assertEquals("中元",year.getYuan());
80 | }
81 |
82 | @Test
83 | public void test8(){
84 | LunarYear year = new LunarYear(1983);
85 | Assert.assertEquals("中元",year.getYuan());
86 | }
87 |
88 | @Test
89 | public void test9(){
90 | LunarYear year = new LunarYear(1984);
91 | Assert.assertEquals("下元",year.getYuan());
92 | }
93 |
94 | @Test
95 | public void test10(){
96 | LunarYear year = new LunarYear(2043);
97 | Assert.assertEquals("下元",year.getYuan());
98 | }
99 |
100 | @Test
101 | public void test11(){
102 | LunarYear year = new LunarYear(1864);
103 | Assert.assertEquals("一运",year.getYun());
104 | }
105 |
106 | @Test
107 | public void test12(){
108 | LunarYear year = new LunarYear(1883);
109 | Assert.assertEquals("一运",year.getYun());
110 | }
111 |
112 | @Test
113 | public void test13(){
114 | LunarYear year = new LunarYear(1884);
115 | Assert.assertEquals("二运",year.getYun());
116 | }
117 |
118 | @Test
119 | public void test14(){
120 | LunarYear year = new LunarYear(1903);
121 | Assert.assertEquals("二运",year.getYun());
122 | }
123 |
124 | @Test
125 | public void test15(){
126 | LunarYear year = new LunarYear(1904);
127 | Assert.assertEquals("三运",year.getYun());
128 | }
129 |
130 | @Test
131 | public void test16(){
132 | LunarYear year = new LunarYear(1923);
133 | Assert.assertEquals("三运",year.getYun());
134 | }
135 |
136 | @Test
137 | public void test17(){
138 | LunarYear year = new LunarYear(2004);
139 | Assert.assertEquals("八运",year.getYun());
140 | }
141 |
142 | @Test
143 | public void test18(){
144 | LunarYear year = new LunarYear(2023);
145 | Assert.assertEquals(384, year.getDayCount());
146 | }
147 |
148 | @Test
149 | public void test19(){
150 | LunarYear year = new LunarYear(1517);
151 | Assert.assertEquals(384, year.getDayCount());
152 | }
153 |
154 | @Test
155 | public void test20(){
156 | LunarYear year = new LunarYear(1518);
157 | Assert.assertEquals(355, year.getDayCount());
158 | }
159 |
160 | @Test
161 | public void test21(){
162 | LunarYear year = new LunarYear(2022);
163 | Assert.assertEquals(355, year.getDayCount());
164 | }
165 |
166 | @Test
167 | public void test22(){
168 | LunarYear year = new LunarYear(2021);
169 | Assert.assertEquals(354, year.getDayCount());
170 | }
171 |
172 | }
173 |
--------------------------------------------------------------------------------
/src/test/java/test/YunTest.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import com.nlf.calendar.EightChar;
4 | import com.nlf.calendar.Lunar;
5 | import com.nlf.calendar.Solar;
6 | import com.nlf.calendar.eightchar.Yun;
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | /**
11 | * 起运测试
12 | */
13 | public class YunTest {
14 |
15 | @Test
16 | public void test1() {
17 | Solar solar = new Solar(1981, 1, 29, 23, 37, 0);
18 | Lunar lunar = solar.getLunar();
19 | EightChar eightChar = lunar.getEightChar();
20 | Yun yun = eightChar.getYun(0);
21 | Assert.assertEquals("起运年数", 8, yun.getStartYear());
22 | Assert.assertEquals("起运月数", 0, yun.getStartMonth());
23 | Assert.assertEquals("起运天数", 20, yun.getStartDay());
24 | Assert.assertEquals("起运阳历", "1989-02-18", yun.getStartSolar().toYmd());
25 | }
26 |
27 | @Test
28 | public void test2() {
29 | Lunar lunar = new Lunar(2019, 12, 12, 11, 22, 0);
30 | System.out.println(lunar.getMonth());
31 | System.out.println(lunar.toFullString());
32 | System.out.println(lunar.getSolar().toFullString());
33 | EightChar eightChar = lunar.getEightChar();
34 | Yun yun = eightChar.getYun(1);
35 | Assert.assertEquals("起运年数", 0, yun.getStartYear());
36 | Assert.assertEquals("起运月数", 1, yun.getStartMonth());
37 | Assert.assertEquals("起运天数", 0, yun.getStartDay());
38 | Assert.assertEquals("起运阳历", "2020-02-06", yun.getStartSolar().toYmd());
39 | }
40 |
41 | @Test
42 | public void test3() {
43 | Solar solar = new Solar(2020, 1, 6, 11, 22, 0);
44 | Lunar lunar = solar.getLunar();
45 | System.out.println(lunar.getMonth());
46 | System.out.println(lunar.toFullString());
47 | System.out.println(lunar.getSolar().toFullString());
48 | EightChar eightChar = lunar.getEightChar();
49 | Yun yun = eightChar.getYun(1);
50 | Assert.assertEquals("起运年数", 0, yun.getStartYear());
51 | Assert.assertEquals("起运月数", 1, yun.getStartMonth());
52 | Assert.assertEquals("起运天数", 0, yun.getStartDay());
53 | Assert.assertEquals("起运阳历", "2020-02-06", yun.getStartSolar().toYmd());
54 | }
55 |
56 | @Test
57 | public void test4() {
58 | Solar solar = new Solar(2022, 3, 9, 20, 51, 0);
59 | Lunar lunar = solar.getLunar();
60 | EightChar eightChar = lunar.getEightChar();
61 | Yun yun = eightChar.getYun(1);
62 | Assert.assertEquals("起运阳历", "2030-12-19", yun.getStartSolar().toYmd());
63 | }
64 |
65 | @Test
66 | public void test5() {
67 | Solar solar = new Solar(2022, 3, 9, 20, 51, 0);
68 | Lunar lunar = solar.getLunar();
69 | EightChar eightChar = lunar.getEightChar();
70 | Yun yun = eightChar.getYun(1, 2);
71 | Assert.assertEquals("起运年数", 8, yun.getStartYear());
72 | Assert.assertEquals("起运月数", 9, yun.getStartMonth());
73 | Assert.assertEquals("起运天数", 2, yun.getStartDay());
74 | Assert.assertEquals("起运阳历", "2030-12-12", yun.getStartSolar().toYmd());
75 | }
76 |
77 | @Test
78 | public void test6() {
79 | Solar solar = new Solar(2018, 6, 11, 9, 30, 0);
80 | Lunar lunar = solar.getLunar();
81 | EightChar eightChar = lunar.getEightChar();
82 | Yun yun = eightChar.getYun(0, 2);
83 | Assert.assertEquals("起运阳历", "2020-03-21", yun.getStartSolar().toYmd());
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------