1
0
mirror of synced 2026-10-12 17:56:07 +08:00

Compare commits

..

16 Commits

Author SHA1 Message Date
6tail
9a302e2a1a v1.7.3 修复个别日太岁方位的错误;修复八字身宫计算错误的问题。 2025-04-07 19:05:18 +08:00
6tail
264481532b v1.7.2 修复每日宜忌错误;更新2018之后的△T参数。 2025-03-05 21:02:53 +08:00
6tail
2fedf45007 v1.7.1 修复每日宜忌错误。 2025-02-27 21:36:09 +08:00
6tail
0d226722d6 v1.7.0 修复每日宜忌错别字。 2025-02-12 19:43:52 +08:00
6tail
6dbf70186d v1.4.0 修复九星错别字;优化每日宜忌算法;去除每日宜忌的重复项。 2025-02-06 20:46:13 +08:00
6tail
b6bde78e59 v1.3.15 新增2025年法定假日数据。 2024-11-12 21:14:19 +08:00
6tail
701cec10a0 v1.3.14 修复八字转阳历存在遗漏的问题。 2024-03-17 14:00:34 +08:00
6tail
0a4d172ef6 v1.3.13 修复节气当天获取下一节气仍为当前节气的问题;修复每日宜忌存在重复项的问题;修复八字转阳历存在遗漏的问题。 2024-02-29 11:59:27 +08:00
6tail
1c3ff0cbc5 v1.3.12 八字转阳历结果按时间先后排序,转换速度大幅提升。 2024-02-06 17:40:46 +08:00
6tail
e15a916e55 v1.3.11 修复命宫、身宫的错误。 2024-01-30 21:00:30 +08:00
6tail
1411d8017f v1.3.10 修复八字转阳历为空的问题;修复一处法定假日数据错误;十神优化。 2024-01-03 19:31:09 +08:00
6tail
a17402241a v1.3.9 修复星期错误的问题。 2023-11-09 11:58:29 +08:00
6tail
9e36b0739c v1.3.8 修复星期错误的问题;修正逐日胎神数据。 2023-11-07 21:22:16 +08:00
6tail
1c72c5769e v1.3.7 更新2024年法定假日数据;十神优化。 2023-10-26 11:21:09 +08:00
6tail
ceac1afc3e v1.3.6 中元节改为农历七月十五;修复Solar的nextMonth超期问题。 2023-09-03 11:39:25 +08:00
6tail
d66cd71f44 v1.3.5 Solar增加薪资比例;修正与寿星v5.10的节气误差;修复古时阴阳历转换错误的问题。 2023-08-20 17:15:24 +08:00
23 changed files with 1147 additions and 621 deletions

38
CHANGELOG.md Normal file
View File

@@ -0,0 +1,38 @@
# Changelog
## [1.3.12] - 2024-02-06
1. 八字转阳历结果按时间先后排序,转换速度大幅提升。
## [1.3.13] - 2024-02-29
1. 修复节气当天获取下一节气仍为当前节气的问题。
2. 修复每日宜忌存在重复项的问题。
3. 修复八字转阳历存在遗漏的问题。
## [1.3.14] - 2024-03-17
1. 修复八字转阳历存在遗漏的问题。
## [1.3.15] - 2024-11-12
1. 新增2025年法定假日数据。
## [1.4.0] - 2025-02-06
1. 修复九星错别字。
2. 优化每日宜忌算法。
3. 去除每日宜忌的重复项。
> 不建议使用该版本
## [1.7.0] - 2025-02-12
1. 修复每日宜忌错别字。
> 不建议使用该版本
## [1.7.1] - 2025-02-27
1. 修复每日宜忌错误。
> 不建议使用该版本
## [1.7.2] - 2025-03-05
1. 修复每日宜忌错误。
2. 更新2018之后的△T参数。
## [1.7.3] - 2025-04-07
1. 修复个别日太岁方位的错误。
2. 修复八字身宫计算错误的问题。

View File

@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.3.4</version>
<version>1.7.3</version>
</dependency>
```
@@ -54,3 +54,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
## 文档
请移步至 [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=6tail/lunar-java&type=Date)](https://star-history.com/#6tail/lunar-java&Date)

View File

@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.3.4</version>
<version>1.7.3</version>
</dependency>
```
@@ -50,3 +50,7 @@ Output:
## Documentation
Please visit [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=6tail/lunar-java&type=Date)](https://star-history.com/#6tail/lunar-java&Date)

View File

@@ -7,7 +7,7 @@
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<packaging>jar</packaging>
<version>1.3.4</version>
<version>1.7.3</version>
<name>${project.groupId}:${project.artifactId}</name>
<url>https://github.com/6tail/lunar-java</url>
<description>a calendar library for Solar and Chinese Lunar</description>
@@ -104,6 +104,7 @@
<goal>jar</goal>
</goals>
<configuration>
<javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable>
<additionalparam>-Xdoclint:none</additionalparam>
<source>${source-version}</source>
</configuration>

View File

@@ -145,14 +145,14 @@ public class EightChar {
* @return 十神
*/
public String getYearShiShenGan() {
return LunarUtil.SHI_SHEN_GAN.get(getDayGan() + getYearGan());
return LunarUtil.SHI_SHEN.get(getDayGan() + getYearGan());
}
private List<String> getShiShenZhi(String zhi) {
List<String> hideGan = LunarUtil.ZHI_HIDE_GAN.get(zhi);
List<String> l = new ArrayList<String>(hideGan.size());
for (String gan : hideGan) {
l.add(LunarUtil.SHI_SHEN_ZHI.get(getDayGan() + zhi + gan));
l.add(LunarUtil.SHI_SHEN.get(getDayGan() + gan));
}
return l;
}
@@ -264,7 +264,7 @@ public class EightChar {
* @return 十神
*/
public String getMonthShiShenGan() {
return LunarUtil.SHI_SHEN_GAN.get(getDayGan() + getMonthGan());
return LunarUtil.SHI_SHEN.get(getDayGan() + getMonthGan());
}
/**
@@ -426,7 +426,7 @@ public class EightChar {
* @return 十神
*/
public String getTimeShiShenGan() {
return LunarUtil.SHI_SHEN_GAN.get(getDayGan() + getTimeGan());
return LunarUtil.SHI_SHEN.get(getDayGan() + getTimeGan());
}
/**
@@ -499,29 +499,15 @@ public class EightChar {
* @return 命宫
*/
public String getMingGong() {
int monthZhiIndex = 0;
int timeZhiIndex = 0;
for (int i = 0, j = MONTH_ZHI.length; i < j; i++) {
String zhi = MONTH_ZHI[i];
if (lunar.getMonthZhiExact().equals(zhi)) {
monthZhiIndex = i;
}
if (lunar.getTimeZhi().equals(zhi)) {
timeZhiIndex = i;
}
int monthZhiIndex = LunarUtil.find(getMonthZhi(), MONTH_ZHI, 0);
int timeZhiIndex = LunarUtil.find(getTimeZhi(), MONTH_ZHI, 0);
int offset = monthZhiIndex + timeZhiIndex;
offset = (offset >= 14 ? 26 : 14) - offset;
int ganIndex = (lunar.getYearGanIndexExact() + 1) * 2 + offset;
while (ganIndex > 10) {
ganIndex -= 10;
}
int zhiIndex = 26 - (monthZhiIndex + timeZhiIndex);
if (zhiIndex > 12) {
zhiIndex -= 12;
}
int jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
if (jiaZiIndex >= 60) {
jiaZiIndex -= 60;
}
if (jiaZiIndex < 0) {
jiaZiIndex += 60;
}
return LunarUtil.JIA_ZI[jiaZiIndex];
return LunarUtil.GAN[ganIndex] + MONTH_ZHI[offset];
}
/**
@@ -539,29 +525,14 @@ public class EightChar {
* @return 身宫
*/
public String getShenGong() {
int monthZhiIndex = 0;
int timeZhiIndex = 0;
for (int i = 0, j = MONTH_ZHI.length; i < j; i++) {
String zhi = MONTH_ZHI[i];
if (lunar.getMonthZhiExact().equals(zhi)) {
monthZhiIndex = i;
}
if (lunar.getTimeZhi().equals(zhi)) {
timeZhiIndex = i;
}
int monthZhiIndex = LunarUtil.find(getMonthZhi(), MONTH_ZHI, 0);
int timeZhiIndex = LunarUtil.find(getTimeZhi(), LunarUtil.ZHI, 0);
int offset = (monthZhiIndex + timeZhiIndex - 1) % 12;
int ganIndex = (lunar.getYearGanIndexExact() + 1) * 2 + offset;
while (ganIndex > 10) {
ganIndex -= 10;
}
int zhiIndex = 2 + monthZhiIndex + timeZhiIndex;
if (zhiIndex > 12) {
zhiIndex -= 12;
}
int jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
if (jiaZiIndex >= 60) {
jiaZiIndex -= 60;
}
if (jiaZiIndex < 0) {
jiaZiIndex += 60;
}
return LunarUtil.JIA_ZI[jiaZiIndex];
return LunarUtil.GAN[ganIndex + 1] + MONTH_ZHI[offset + 1];
}
/**

View File

@@ -1347,11 +1347,11 @@ public class Lunar {
protected String getDayPositionTaiSui(String dayInGanZhi, int yearZhiIndex) {
String p;
if ("甲子,乙丑,丙寅,丁卯,戊辰,已巳".contains(dayInGanZhi)) {
if ("甲子,乙丑,丙寅,丁卯,戊辰,己巳".contains(dayInGanZhi)) {
p = "震";
} else if ("丙子,丁丑,戊寅,已卯,庚辰,辛巳".contains(dayInGanZhi)) {
} else if ("丙子,丁丑,戊寅,己卯,庚辰,辛巳".contains(dayInGanZhi)) {
p = "离";
} else if ("戊子,已丑,庚寅,辛卯,壬辰,癸巳".contains(dayInGanZhi)) {
} else if ("戊子,己丑,庚寅,辛卯,壬辰,癸巳".contains(dayInGanZhi)) {
p = "中";
} else if ("庚子,辛丑,壬寅,癸卯,甲辰,乙巳".contains(dayInGanZhi)) {
p = "兑";
@@ -2380,7 +2380,7 @@ public class Lunar {
Solar solar = entry.getValue();
String day = wholeDay ? solar.toYmd() : solar.toYmdHms();
if (forward) {
if (day.compareTo(today) < 0) {
if (day.compareTo(today) <= 0) {
continue;
}
if (null == near) {
@@ -2944,11 +2944,7 @@ public class Lunar {
days = current.subtract(start);
Solar liQiuSolar = Solar.fromYmd(liQiu.getYear(), liQiu.getMonth(), liQiu.getDay());
// 末伏
if (!liQiuSolar.isAfter(start)) {
if (days < 10) {
return new Fu("末伏", days + 1);
}
} else {
if (liQiuSolar.isAfter(start)) {
// 中伏
if (days < 10) {
return new Fu("中伏", days + 11);
@@ -2956,9 +2952,9 @@ public class Lunar {
// 末伏第1天
start = start.next(10);
days = current.subtract(start);
if (days < 10) {
return new Fu("末伏", days + 1);
}
}
if (days < 10) {
return new Fu("末伏", days + 1);
}
return null;
}

View File

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

View File

@@ -18,7 +18,7 @@ public class NineStar {
/**
* 七色
*/
public static final String[] COLOR = {"白", "黒", "碧", "绿", "黄", "白", "赤", "白", "紫"};
public static final String[] COLOR = {"白", "黑", "碧", "绿", "黄", "白", "赤", "白", "紫"};
/**
* 五行

View File

@@ -89,9 +89,13 @@ public class Solar {
if (month < 1 || month > 12) {
throw new IllegalArgumentException(String.format("wrong month %d", month));
}
if (day < 1 || day > 31) {
if (day < 1) {
throw new IllegalArgumentException(String.format("wrong day %d", day));
}
int days = SolarUtil.getDaysOfMonth(year, month);
if (day > days) {
throw new IllegalArgumentException(String.format("only %d days in solar year %d month %d", days, year, month));
}
if (hour < 0 || hour > 23) {
throw new IllegalArgumentException(String.format("wrong hour %d", hour));
}
@@ -186,6 +190,10 @@ public class Solar {
minute -= 60;
hour++;
}
if (hour > 23) {
hour -= 24;
day += 1;
}
this.year = year;
this.month = month;
this.day = day;
@@ -292,49 +300,72 @@ public class Solar {
public static List<Solar> fromBaZi(String yearGanZhi, String monthGanZhi, String dayGanZhi, String timeGanZhi, int sect, int baseYear) {
sect = (1 == sect) ? 1 : 2;
List<Solar> l = new ArrayList<Solar>();
List<Integer> years = new ArrayList<Integer>();
Solar today = fromDate(new Date());
int offsetYear = LunarUtil.getJiaZiIndex(today.getLunar().getYearInGanZhiExact())-LunarUtil.getJiaZiIndex(yearGanZhi);
if(offsetYear < 0){
offsetYear += 60;
// 月地支距寅月的偏移值
int m = LunarUtil.find(monthGanZhi.substring(1), LunarUtil.ZHI, -1) - 2;
if (m < 0) {
m += 12;
}
int startYear = today.getYear() - offsetYear - 1;
int minYear = baseYear - 2;
while (startYear >= minYear) {
years.add(startYear);
startYear -= 60;
// 月天干要一致
if (((LunarUtil.find(yearGanZhi.substring(0, 1), LunarUtil.GAN, -1) + 1) * 2 + m) % 10 != LunarUtil.find(monthGanZhi.substring(0, 1), LunarUtil.GAN, -1)) {
return l;
}
List<Integer> hours = new ArrayList<Integer>(2);
String timeZhi = timeGanZhi.substring(1);
for(int i = 1, j = LunarUtil.ZHI.length; i < j; i++){
if(LunarUtil.ZHI[i].equals(timeZhi)){
hours.add((i - 1) * 2);
break;
}
// 1年的立春是辛酉,序号57
int y = LunarUtil.getJiaZiIndex(yearGanZhi) - 57;
if (y < 0) {
y += 60;
}
if ("子".equals(timeZhi)) {
hours.add(23);
y++;
// 节令偏移值
m *= 2;
// 时辰地支转时刻,子时按零点算
int h = LunarUtil.find(timeGanZhi.substring(1), LunarUtil.ZHI, -1) * 2;
int[] hours = {h};
if (0 == h && 2 == sect) {
hours = new int[]{0, 23};
}
for (int hour: hours) {
for (Integer y : years) {
int maxYear = y + 3;
int year = y;
int month = 11;
if (year < baseYear) {
year = baseYear;
month = 1;
}
Solar solar = fromYmdHms(year, month, 1, hour, 0, 0);
while (solar.getYear() <= maxYear) {
Lunar lunar = solar.getLunar();
String dgz = (2 == sect) ? lunar.getDayInGanZhiExact2() : lunar.getDayInGanZhiExact();
if (lunar.getYearInGanZhiExact().equals(yearGanZhi) && lunar.getMonthInGanZhiExact().equals(monthGanZhi) && dgz.equals(dayGanZhi) && lunar.getTimeInGanZhi().equals(timeGanZhi)) {
l.add(solar);
break;
int startYear = baseYear - 1;
// 结束年
Calendar c = Calendar.getInstance(TIME_ZONE);
c.setTime(new Date());
c.set(Calendar.MILLISECOND, 0);
int endYear = c.get(Calendar.YEAR);
while (y <= endYear) {
if (y >= startYear) {
// 立春为寅月的开始
List<Solar> jieQiList = new ArrayList<Solar>(Lunar.fromYmd(y, 1, 1).getJieQiTable().values());
// 节令推移,年干支和月干支就都匹配上了
Solar solarTime = jieQiList.get(4 + m);
if (solarTime.getYear() >= baseYear) {
// 日干支和节令干支的偏移值
int d = LunarUtil.getJiaZiIndex(dayGanZhi) - LunarUtil.getJiaZiIndex(solarTime.getLunar().getDayInGanZhiExact2());
if (d < 0) {
d += 60;
}
if (d > 0) {
// 从节令推移天数
solarTime = solarTime.next(d);
}
for (int hour : hours) {
int mi = 0;
int s = 0;
if (d == 0 && hour == solarTime.getHour()) {
// 如果正好是节令当天,且小时和节令的小时数相等的极端情况,把分钟和秒钟带上
mi = solarTime.getMinute();
s = solarTime.getSecond();
}
// 验证一下
Solar solar = Solar.fromYmdHms(solarTime.getYear(), solarTime.getMonth(), solarTime.getDay(), hour, mi, s);
Lunar lunar = solar.getLunar();
String dgz = (2 == sect) ? lunar.getDayInGanZhiExact2() : lunar.getDayInGanZhiExact();
if (lunar.getYearInGanZhiExact().equals(yearGanZhi) && lunar.getMonthInGanZhiExact().equals(monthGanZhi) && dgz.equals(dayGanZhi) && lunar.getTimeInGanZhi().equals(timeGanZhi)) {
l.add(solar);
}
}
solar = solar.next(1);
}
}
y += 60;
}
return l;
}
@@ -354,26 +385,7 @@ public class Solar {
* @return 0123456
*/
public int getWeek() {
Solar start = fromYmd(1582, 10, 15);
int y = year;
int m = month;
int d = day;
Solar current = fromYmd(y, m, d);
// 蔡勒公式
if (m < 3) {
m += 12;
y--;
}
int c = y / 100;
y = y - c * 100;
int x = y + y / 4 + c / 4 - 2 * c;
int w;
if (current.isBefore(start)) {
w = (x + 13 * (m + 1) / 5 + d + 2) % 7;
} else {
w = (x + 26 * (m + 1) / 10 + d - 1) % 7;
}
return (w + 7) % 7;
return ((int) (getJulianDay() + 0.5) + 7000001) % 7;
}
/**
@@ -598,6 +610,7 @@ public class Solar {
/**
* 阳历日期相减,获得相差天数
*
* @param solar 阳历
* @return 天数
*/
@@ -607,6 +620,7 @@ public class Solar {
/**
* 阳历日期相减,获得相差分钟数
*
* @param solar 阳历
* @return 分钟数
*/
@@ -625,6 +639,7 @@ public class Solar {
/**
* 是否在指定日期之后
*
* @param solar 阳历
* @return true/false
*/
@@ -664,6 +679,7 @@ public class Solar {
/**
* 是否在指定日期之前
*
* @param solar 阳历
* @return true/false
*/
@@ -703,6 +719,7 @@ public class Solar {
/**
* 年推移
*
* @param years 年数
* @return 阳历
*/
@@ -710,24 +727,23 @@ public class Solar {
int y = year + years;
int m = month;
int d = day;
// 2月处理
if (2 == m) {
if (1582 == y && 10 == m) {
if (d > 4 && d < 15) {
d += 10;
}
} else if (2 == m) {
if (d > 28) {
if (!SolarUtil.isLeapYear(y)) {
d = 28;
}
}
}
if (1582 == y && 10 == m) {
if (d > 4 && d < 15) {
d += 10;
}
}
return fromYmdHms(y, m, d, hour, minute, second);
}
/**
* 月推移
*
* @param months 月数
* @return 阳历
*/
@@ -736,18 +752,15 @@ public class Solar {
int y = month.getYear();
int m = month.getMonth();
int d = day;
// 2月处理
if (2 == m) {
if (d > 28) {
if (!SolarUtil.isLeapYear(y)) {
d = 28;
}
}
}
if (1582 == y && 10 == m) {
if (d > 4 && d < 15) {
d += 10;
}
} else {
int maxDay = SolarUtil.getDaysOfMonth(y, m);
if (d > maxDay) {
d = maxDay;
}
}
return fromYmdHms(y, m, d, hour, minute, second);
}
@@ -791,7 +804,7 @@ public class Solar {
d += days;
}
if (1582 == y && 10 == m) {
if (d > 4 ) {
if (d > 4) {
d += 10;
}
}
@@ -806,7 +819,7 @@ public class Solar {
* @return 阳历日期
*/
public Solar next(int days, boolean onlyWorkday) {
if(!onlyWorkday) {
if (!onlyWorkday) {
return next(days);
}
Solar solar = fromYmdHms(year, month, day, hour, minute, second);
@@ -835,6 +848,7 @@ public class Solar {
/**
* 小时推移
*
* @param hours 小时数
* @return 阳历
*/
@@ -852,4 +866,55 @@ public class Solar {
return fromYmdHms(solar.getYear(), solar.getMonth(), solar.getDay(), hour, solar.getMinute(), solar.getSecond());
}
/**
* 获取薪资比例(感谢 https://gitee.com/smr1987)
*
* @return 薪资比例:1/2/3
*/
public int getSalaryRate() {
// 元旦节
if (month == 1 && day == 1) {
return 3;
}
// 劳动节
if (month == 5 && day == 1) {
return 3;
}
// 国庆
if (month == 10 && day >= 1 && day <= 3) {
return 3;
}
Lunar lunar = getLunar();
// 春节
if (lunar.getMonth() == 1 && lunar.getDay() >= 1 && lunar.getDay() <= 3) {
return 3;
}
// 端午
if (lunar.getMonth() == 5 && lunar.getDay() == 5) {
return 3;
}
// 中秋
if (lunar.getMonth() == 8 && lunar.getDay() == 15) {
return 3;
}
// 清明
if ("清明".equals(lunar.getJieQi())) {
return 3;
}
Holiday holiday = HolidayUtil.getHoliday(year, month, day);
if (null != holiday) {
// 法定假日非上班
if (!holiday.isWork()) {
return 2;
}
} else {
// 周末
int week = getWeek();
if (week == 6 || week == 0) {
return 2;
}
}
// 工作日
return 1;
}
}

View File

@@ -9,7 +9,7 @@ import com.nlf.calendar.util.LunarUtil;
*/
public class LiuYue {
/**
* 序数,0-9
* 序数,0-11
*/
private final int index;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -218,6 +218,9 @@ public class SolarUtil {
* @return true/false 闰年/非闰年
*/
public static boolean isLeapYear(int year) {
if (year < 1600) {
return year % 4 == 0;
}
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}

View File

@@ -77,7 +77,7 @@ public class BaZiTestNew {
public void test7() {
Solar solar = new Solar(2020, 5, 26, 23, 43, 0);
Lunar lunar = solar.getLunar();
//庚子, 辛巳, 庚午, 丙子]
// [庚子, 辛巳, 庚午, 丙子]
System.out.println(lunar.getEightChar());
}

View File

@@ -1,8 +1,12 @@
package sample;
import com.nlf.calendar.Holiday;
import com.nlf.calendar.Solar;
import com.nlf.calendar.util.HolidayUtil;
import org.junit.Test;
import java.util.List;
public class HolidayTest {
@Test
@@ -20,4 +24,31 @@ public class HolidayTest {
System.out.println(HolidayUtil.getHolidaysByTarget("20200501"));
System.out.println(HolidayUtil.getHolidaysByTarget(2011,1,1));
}
@Test
public void test1(){
StringBuilder s = new StringBuilder();
for(int i = 2001; i <= 2024; i++) {
List<Holiday> l = HolidayUtil.getHolidays(i);
for (Holiday d : l) {
int index = -1;
for (int x = 0;x <HolidayUtil.NAMES.length;x++) {
if (HolidayUtil.NAMES[x].equals(d.getName())) {
index = x;
break;
}
}
if (index == -1) {
throw new IllegalArgumentException(d.getName());
}
String day = d.getDay();
String target = d.getTarget();
Solar solar = Solar.fromYmd(Integer.parseInt(day.substring(0,4)), Integer.parseInt(day.substring(5,7)), Integer.parseInt(day.substring(8)));
Solar targetSolar = Solar.fromYmd(Integer.parseInt(target.substring(0,4)), Integer.parseInt(target.substring(5,7)), Integer.parseInt(target.substring(8)));
int diff = targetSolar.subtract(solar);
s.append(String.format("%s%d%d%s%02d", d.getDay().replace("-",""), d.isWork() ? 0 : 1, index, diff < 0 ? "-" : "+", Math.abs(diff)));
}
}
System.out.println(s);
}
}

View File

@@ -3,6 +3,7 @@ package test;
import com.nlf.calendar.EightChar;
import com.nlf.calendar.Lunar;
import com.nlf.calendar.Solar;
import com.nlf.calendar.eightchar.Yun;
import org.junit.Assert;
import org.junit.Test;
@@ -258,8 +259,8 @@ public class BaZiTest {
}
List<String> expected = new ArrayList<String>();
expected.add("1976-09-21 12:00:00");
expected.add("1916-10-06 12:00:00");
expected.add("1976-09-21 12:00:00");
Assert.assertEquals(expected, actual);
}
@@ -285,8 +286,8 @@ public class BaZiTest {
}
List<String> expected = new ArrayList<String>();
expected.add("1999-07-21 16:00:00");
expected.add("1939-08-05 16:00:00");
expected.add("1999-07-21 16:00:00");
Assert.assertEquals(expected, actual);
}
@@ -299,8 +300,8 @@ public class BaZiTest {
}
List<String> expected = new ArrayList<String>();
expected.add("1960-12-17 12:00:00");
expected.add("1901-01-01 12:00:00");
expected.add("1960-12-17 12:00:00");
Assert.assertEquals(expected, actual);
}
@@ -313,8 +314,8 @@ public class BaZiTest {
}
List<String> expected = new ArrayList<String>();
expected.add("2020-07-21 22:00:00");
expected.add("1960-08-05 22:00:00");
expected.add("2020-07-21 22:00:00");
Assert.assertEquals(expected, actual);
}
@@ -368,15 +369,15 @@ public class BaZiTest {
@Test
public void test14() {
List<Solar> l = Solar.fromBaZi("癸卯","甲寅","癸丑","甲子", 2, 1843);
List<Solar> l = Solar.fromBaZi("癸卯","甲寅","甲寅","甲子", 2, 1843);
List<String> actual = new ArrayList<String>();
for (Solar solar : l) {
actual.add(solar.toYmdHms());
}
List<String> expected = new ArrayList<String>();
expected.add("2023-02-24 23:00:00");
expected.add("1843-02-08 23:00:00");
expected.add("1843-02-09 00:00:00");
expected.add("2023-02-25 00:00:00");
Assert.assertEquals(expected, actual);
}
@@ -389,8 +390,8 @@ public class BaZiTest {
}
List<String> expected = new ArrayList<String>();
expected.add("1960-01-15 16:00:00");
expected.add("1900-01-29 16:00:00");
expected.add("1960-01-15 16:00:00");
Assert.assertEquals(expected, actual);
}
@@ -406,4 +407,146 @@ public class BaZiTest {
expected.add("1959-12-17 16:00:00");
Assert.assertEquals(expected, actual);
}
@Test
public void test17() {
Solar solar = new Solar(1986, 5, 29, 13, 37, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Assert.assertEquals("辛丑", eightChar.getShenGong());
}
@Test
public void test18() {
Solar solar = new Solar(2023, 10, 8, 18, 37, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Assert.assertEquals("己未", eightChar.getShenGong());
}
@Test
public void test19() {
List<Solar> l = Solar.fromBaZi("丁丑","癸卯","癸丑","辛酉");
List<String> actual = new ArrayList<String>();
for (Solar solar : l) {
actual.add(solar.toYmdHms());
}
List<String> expected = new ArrayList<String>();
expected.add("1937-03-27 18:00:00");
expected.add("1997-03-12 18:00:00");
Assert.assertEquals(expected, actual);
}
@Test
public void test20() {
List<Solar> l = Solar.fromBaZi("乙未","己卯","丁丑","甲辰");
List<String> actual = new ArrayList<String>();
for (Solar solar : l) {
actual.add(solar.toYmdHms());
}
List<String> expected = new ArrayList<String>();
expected.add("1955-03-17 08:00:00");
Assert.assertEquals(expected, actual);
}
@Test
public void test21() {
Lunar lunar = Solar.fromYmdHms(2024, 1, 29, 9, 30, 0).getLunar();
EightChar eightChar = lunar.getEightChar();
Assert.assertEquals("命宫", "癸亥", eightChar.getMingGong());
Assert.assertEquals("身宫", "己未", eightChar.getShenGong());
}
@Test
public void test22() {
Assert.assertEquals("身宫", "丙寅", Solar.fromYmdHms(1990, 1, 27, 0, 0, 0).getLunar().getEightChar().getShenGong());
}
@Test
public void test23() {
Assert.assertEquals("甲戌", Solar.fromYmdHms(2019, 3, 7, 8, 0, 0).getLunar().getEightChar().getMingGong());
}
@Test
public void test24() {
Assert.assertEquals("丁丑", Solar.fromYmdHms(2019, 3, 27, 2, 0, 0).getLunar().getEightChar().getMingGong());
}
@Test
public void test25() {
Assert.assertEquals("丙寅", Lunar.fromYmdHms(1994, 5, 20, 18, 0 ,0).getEightChar().getMingGong());
}
@Test
public void test26() {
Lunar lunar = Solar.fromYmdHms(1986, 2, 16, 8, 0, 0).getLunar();
EightChar eightChar = lunar.getEightChar();
Assert.assertEquals("命宫", "己亥", eightChar.getMingGong());
Assert.assertEquals("身宫", "乙未", eightChar.getShenGong());
}
@Test
public void test27() {
Lunar lunar = Solar.fromYmdHms(1972, 11, 27, 10, 0, 0).getLunar();
EightChar eightChar = lunar.getEightChar();
Assert.assertEquals("身宫", "乙巳", eightChar.getShenGong());
}
@Test
public void test28() {
Lunar lunar = Solar.fromYmdHms(1986, 5, 29, 13, 37, 0).getLunar();
EightChar eightChar = lunar.getEightChar();
Yun yun = eightChar.getYun(1, 2);
Assert.assertEquals(2, yun.getStartYear());
Assert.assertEquals(7, yun.getStartMonth());
Assert.assertEquals(0, yun.getStartDay());
}
@Test
public void test29() {
List<Solar> l = Solar.fromBaZi("甲辰","丙寅","壬戌","壬子", 2);
List<String> actual = new ArrayList<String>();
for (Solar solar : l) {
actual.add(solar.toYmdHms());
}
List<String> expected = new ArrayList<String>();
expected.add("2024-02-28 23:00:00");
Assert.assertEquals(expected, actual);
}
@Test
public void test30() {
List<Solar> l = Solar.fromBaZi("甲辰","丙寅","癸亥","壬子", 1);
List<String> actual = new ArrayList<String>();
for (Solar solar : l) {
actual.add(solar.toYmdHms());
}
List<String> expected = new ArrayList<String>();
expected.add("2024-02-29 00:00:00");
Assert.assertEquals(expected, actual);
}
@Test
public void test31() {
List<Solar> l = Solar.fromBaZi("丁卯","丁未","甲申","乙丑", 1, 1900);
List<String> actual = new ArrayList<String>();
for (Solar solar : l) {
actual.add(solar.toYmdHms());
}
List<String> expected = new ArrayList<String>();
expected.add("1987-08-03 02:00:00");
Assert.assertEquals(expected, actual);
}
@Test
public void test32() {
Lunar lunar = Solar.fromYmdHms(1980, 6, 15, 12, 30, 30).getLunar();
EightChar eightChar = lunar.getEightChar();
Assert.assertEquals("身宫", "己丑", eightChar.getShenGong());
}
}

View File

@@ -30,9 +30,9 @@ public class JieQiTest {
put("春分","2022-03-20 23:33:15");
put("清明","2022-04-05 03:20:03");
put("谷雨","2022-04-20 10:24:07");
put("立夏","2022-05-05 20:25:46");
put("立夏","2022-05-05 20:25:47");
put("小满","2022-05-21 09:22:25");
put("芒种","2022-06-06 00:25:37");
put("芒种","2022-06-06 00:25:38");
put("夏至","2022-06-21 17:13:40");
put("小暑","2022-07-07 10:37:49");
put("大暑","2022-07-23 04:06:49");
@@ -177,13 +177,13 @@ public class JieQiTest {
@Test
public void test7() {
Lunar lunar = Lunar.fromYmd(2012, 9, 1);
Assert.assertEquals("2012-09-07 13:29:00", lunar.getJieQiTable().get("白露").toYmdHms());
Assert.assertEquals("2012-09-07 13:29:01", lunar.getJieQiTable().get("白露").toYmdHms());
}
@Test
public void test8() {
Lunar lunar = Lunar.fromYmd(2050, 12, 1);
Assert.assertEquals("2050-12-07 06:41:00", lunar.getJieQiTable().get("DA_XUE").toYmdHms());
Assert.assertEquals("2050-12-07 06:40:53", lunar.getJieQiTable().get("DA_XUE").toYmdHms());
}
@Test
@@ -194,4 +194,16 @@ public class JieQiTest {
Assert.assertEquals("冬至", solar.getLunar().getQi());
}
@Test
public void test10() {
Lunar lunar = Solar.fromYmd(2023, 6, 1).getLunar();
Assert.assertEquals("2022-12-22 05:48:01", lunar.getJieQiTable().get("冬至").toYmdHms());
}
@Test
public void test11() {
Lunar lunar = Solar.fromYmd(2025, 3, 5).getLunar();
Assert.assertEquals("2025-03-05 16:07:02", lunar.getJieQiTable().get("惊蛰").toYmdHms());
}
}

View File

@@ -53,4 +53,10 @@ public class LunarMonthTest {
Assert.assertEquals("壬寅", month.getGanZhi());
}
@Test
public void test6(){
LunarMonth month = LunarMonth.fromYm(2023, 9);
Assert.assertEquals("癸亥", month.getGanZhi());
}
}

View File

@@ -7,8 +7,7 @@ import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.*;
/**
* 农历测试
@@ -377,7 +376,7 @@ public class LunarTest {
public void test52() {
Solar solar = Solar.fromYmd(2011, 11, 12);
Lunar lunar = solar.getLunar();
Assert.assertEquals("厕灶厨 外西南", lunar.getDayPositionTai());
Assert.assertEquals("厨灶厕 外西南", lunar.getDayPositionTai());
}
@Test
@@ -409,7 +408,7 @@ public class LunarTest {
Lunar lunar = solar.getLunar();
Assert.assertEquals("甲辰", lunar.getMonthInGanZhi());
Assert.assertEquals("癸卯", lunar.getMonthInGanZhiExact());
Assert.assertEquals(4, lunar.getDayJi().size());
Assert.assertEquals("[出火, 入宅, 安葬, 伐木]", lunar.getDayJi().toString());
}
@Test
@@ -627,4 +626,56 @@ public class LunarTest {
Assert.assertEquals("1537-02-10", lunar.getSolar().toString());
}
@Test
public void test92() {
Lunar lunar = Solar.fromYmd(917, 12, 1).getLunar();
Assert.assertEquals("九一七年闰十月十四", lunar.toString());
}
@Test
public void test93() {
Lunar lunar = Solar.fromYmd(917, 12, 31).getLunar();
Assert.assertEquals("九一七年冬月十五", lunar.toString());
}
@Test
public void test94() {
Lunar lunar = Solar.fromYmd(918, 1, 1).getLunar();
Assert.assertEquals("九一七年冬月十六", lunar.toString());
}
@Test
public void test95() {
Lunar lunar = Solar.fromYmd(2023, 10, 30).getLunar();
Assert.assertEquals("闭", lunar.getZhiXing());
}
@Test
public void test96() {
Lunar lunar = Solar.fromYmd(2025, 2, 7).getLunar();
Assert.assertEquals("[嫁娶, 祭祀, 祈福, 出行, 解除, 出火, 拆卸, 动土, 入宅, 移徙, 安床, 上梁, 栽种, 纳畜, 破土, 启钻, 安葬]", lunar.getDayYi().toString());
Assert.assertEquals("[开市, 立券, 理发, 作灶]", lunar.getDayJi().toString());
}
@Test
public void test97() {
Lunar lunar = Solar.fromYmd(2025, 3, 5).getLunar();
Assert.assertEquals("[破屋, 坏垣, 求医, 治病]", lunar.getDayYi().toString());
Assert.assertEquals("[诸事不宜]", lunar.getDayJi().toString());
}
@Test
public void test98() {
Lunar lunar = Solar.fromYmd(2025, 5, 3).getLunar();
Assert.assertEquals("[祭祀, 祈福, 求嗣, 斋醮, 沐浴, 纳畜, 入殓, 破土, 安葬]", lunar.getDayYi().toString());
Assert.assertEquals("[移徙, 入宅, 嫁娶, 出行, 安床]", lunar.getDayJi().toString());
}
@Test
public void test99() {
Lunar lunar = Solar.fromYmd(2025, 5, 4).getLunar();
Assert.assertEquals("[纳采, 祭祀, 祈福, 求嗣, 斋醮, 出行, 起基, 盖屋, 定磉, 安门, 入殓, 安葬]", lunar.getDayYi().toString());
Assert.assertEquals("[嫁娶, 开市, 纳财, 出火]", lunar.getDayJi().toString());
}
}

View File

@@ -1,6 +1,8 @@
package test;
import com.nlf.calendar.Lunar;
import com.nlf.calendar.LunarMonth;
import com.nlf.calendar.LunarYear;
import com.nlf.calendar.Solar;
import org.junit.Assert;
import org.junit.Test;
@@ -10,17 +12,77 @@ public class NineStarTest {
public void test1() {
Lunar lunar = Solar.fromYmd(1985, 2, 19).getLunar();
Assert.assertEquals("六", lunar.getYearNineStar().getNumber());
Assert.assertEquals("五黄土玉衡", lunar.getDayNineStar().toString());
}
@Test
public void test2() {
Lunar lunar = Lunar.fromYmd(2022, 1, 1);
Assert.assertEquals("六白金开阳", lunar.getYearNineStar().toString());
Assert.assertEquals("四绿木天权", lunar.getDayNineStar().toString());
}
@Test
public void test3() {
Lunar lunar = Lunar.fromYmd(2033, 1, 1);
Assert.assertEquals("四绿木天权", lunar.getYearNineStar().toString());
Assert.assertEquals("一白水天枢", lunar.getDayNineStar().toString());
}
@Test
public void test4() {
LunarYear y = LunarYear.fromYear(1985);
Assert.assertEquals("六白金开阳", y.getNineStar().toString());
}
@Test
public void test5() {
LunarYear y = LunarYear.fromYear(2022);
Assert.assertEquals("五黄土玉衡", y.getNineStar().toString());
}
@Test
public void test6() {
LunarYear y = LunarYear.fromYear(2033);
Assert.assertEquals("三碧木天玑", y.getNineStar().toString());
}
@Test
public void test7() {
LunarMonth m = LunarMonth.fromYm(1985, 2);
Assert.assertEquals("四绿木天权", m.getNineStar().toString());
}
@Test
public void test8() {
LunarMonth m = LunarMonth.fromYm(2022, 1);
Assert.assertEquals("二黑土天璇", m.getNineStar().toString());
}
@Test
public void test9() {
LunarMonth m = LunarMonth.fromYm(2033, 1);
Assert.assertEquals("五黄土玉衡", m.getNineStar().toString());
}
@Test
public void test10() {
Lunar d = Lunar.fromYmdHms(2033, 1, 1, 12, 0,0);
Assert.assertEquals("七赤金摇光", d.getTimeNineStar().toString());
}
@Test
public void test11() {
Lunar d = Lunar.fromYmdHms(2011, 5, 3, 23, 0,0);
Assert.assertEquals("七赤金摇光", d.getTimeNineStar().toString());
}
@Test
public void test12() {
LunarMonth m = LunarMonth.fromYm(2024, 11);
Assert.assertEquals("四绿木天权", m.getNineStar().toString());
m = LunarMonth.fromYm(2024, 12);
Assert.assertEquals("三碧木天玑", m.getNineStar().toString());
}
}

View File

@@ -48,7 +48,7 @@ public class SolarTest {
@Test
public void test10(){
Assert.assertFalse(SolarUtil.isLeapYear(1500));
Assert.assertTrue(SolarUtil.isLeapYear(1500));
}
@Test
@@ -171,4 +171,28 @@ public class SolarTest {
Assert.assertEquals("1582-09-29", solar.next(-6).toYmd());
}
@Test
public void test27(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2023-09-30", solar.nextMonth(1).toYmd());
}
@Test
public void test28(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2023-10-31", solar.nextMonth(2).toYmd());
}
@Test
public void test29(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2025-08-31", solar.nextYear(2).toYmd());
}
@Test
public void test30(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2024-02-29", solar.nextMonth(6).toYmd());
}
}

View File

@@ -54,4 +54,59 @@ public class WeekTest {
Solar solar = Solar.fromYmd(1582, 10, 15);
Assert.assertEquals(5, solar.getWeek());
}
@Test
public void test3(){
Solar solar = Solar.fromYmd(1129, 11, 17);
Assert.assertEquals(0, solar.getWeek());
}
@Test
public void test4(){
Solar solar = Solar.fromYmd(1129, 11, 1);
Assert.assertEquals(5, solar.getWeek());
}
@Test
public void test5(){
Solar solar = Solar.fromYmd(8, 11, 1);
Assert.assertEquals(4, solar.getWeek());
}
@Test
public void test6(){
Solar solar = Solar.fromYmd(1582, 9, 30);
Assert.assertEquals(0, solar.getWeek());
}
@Test
public void test7(){
Solar solar = Solar.fromYmd(1582, 1, 1);
Assert.assertEquals(1, solar.getWeek());
}
@Test
public void test8(){
Solar solar = Solar.fromYmd(1500, 2, 29);
Assert.assertEquals(6, solar.getWeek());
}
@Test
public void test9(){
Solar solar = Solar.fromYmd(9865, 7, 26);
Assert.assertEquals(3, solar.getWeek());
}
@Test
public void test10(){
Assert.assertEquals(6, Solar.fromYmd(1961, 9, 30).getWeek());
Assert.assertEquals(6, Solar.fromYmdHms(1961, 9, 30, 23, 59, 59).getWeek());
Assert.assertEquals(6, Solar.fromYmdHms(1961, 9, 30, 20, 0, 0).getWeek());
}
@Test
public void test11(){
Assert.assertEquals(3, Solar.fromYmdHms(2021, 9, 15, 20, 0, 0).getWeek());
}
}