Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0194eb4574 | ||
|
|
03b0c0aaf1 | ||
|
|
cb931339cf | ||
|
|
664af99ae0 | ||
|
|
9a302e2a1a | ||
|
|
264481532b | ||
|
|
2fedf45007 | ||
|
|
0d226722d6 | ||
|
|
6dbf70186d | ||
|
|
b6bde78e59 | ||
|
|
701cec10a0 | ||
|
|
0a4d172ef6 | ||
|
|
1c3ff0cbc5 | ||
|
|
e15a916e55 | ||
|
|
1411d8017f | ||
|
|
a17402241a | ||
|
|
9e36b0739c | ||
|
|
1c72c5769e |
54
CHANGELOG.md
Normal file
54
CHANGELOG.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# 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. 修复八字身宫计算错误的问题。
|
||||
|
||||
## [1.7.4] - 2025-04-29
|
||||
1. 修复身宫报错的问题。
|
||||
|
||||
## [1.7.5] - 2025-10-01
|
||||
1. 修复:极端情况下八字转公历时刻出现遗漏的问题。
|
||||
2. 优化:更新△T参数。
|
||||
3. 优化:吉神宜驱、凶神宜忌。
|
||||
|
||||
## [1.7.6] - 2025-10-21
|
||||
1. 修复:候的错别字。
|
||||
2. 修复:吉神宜驱、凶神宜忌的错误。
|
||||
3. 修复:农历闰月及后续月份的干支错误。
|
||||
|
||||
## [1.7.7] - 2025-11-05
|
||||
1. 新增:2026年法定假日。
|
||||
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
@@ -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.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
79
pom.xml
79
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.3.6</version>
|
||||
<version>1.7.7</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>
|
||||
@@ -30,18 +30,6 @@
|
||||
<developerConnection>scm:git:git@github.com:6tail/lunar-java.git</developerConnection>
|
||||
<url>git@github.com:6tail/lunar-java.git</url>
|
||||
</scm>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>sonatype-nexus-snapshots</id>
|
||||
<name>Sonatype Nexus snapshot repository</name>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>sonatype-nexus-staging</id>
|
||||
<name>Sonatype Nexus release repository</name>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<properties>
|
||||
<encoding>UTF-8</encoding>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -49,30 +37,29 @@
|
||||
<source-version>1.5</source-version>
|
||||
<target-version>1.5</target-version>
|
||||
<creator>6tail</creator>
|
||||
<junit-version>4.13.2</junit-version>
|
||||
<maven-compiler-plugin-version>3.3</maven-compiler-plugin-version>
|
||||
<maven-jar-plugin-version>3.3.0</maven-jar-plugin-version>
|
||||
<maven-surefire-plugin-version>2.5</maven-surefire-plugin-version>
|
||||
<maven-javadoc-plugin-version>2.9</maven-javadoc-plugin-version>
|
||||
<maven-source-plugin-version>2.4</maven-source-plugin-version>
|
||||
<maven-release-plugin-version>2.2.2</maven-release-plugin-version>
|
||||
<maven-gpg-plugin-version>1.6</maven-gpg-plugin-version>
|
||||
<maven-deploy-plugin-version>3.1.2</maven-deploy-plugin-version>
|
||||
<maven-assembly-plugin-version>2.2-beta-5</maven-assembly-plugin-version>
|
||||
<central-publishing-maven-plugin-version>0.7.0</central-publishing-maven-plugin-version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<testSourceDirectory>src/test/java</testSourceDirectory>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>src/test/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -84,6 +71,23 @@
|
||||
<encoding>${encoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>${maven-jar-plugin-version}</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<index>true</index>
|
||||
<manifest>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Created-By>${creator}</Created-By>
|
||||
<Built-By>${creator}</Built-By>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
@@ -99,11 +103,11 @@
|
||||
<version>${maven-javadoc-plugin-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable>
|
||||
<additionalparam>-Xdoclint:none</additionalparam>
|
||||
<source>${source-version}</source>
|
||||
</configuration>
|
||||
@@ -116,7 +120,6 @@
|
||||
<version>${maven-source-plugin-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
@@ -140,7 +143,6 @@
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
@@ -151,7 +153,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2-beta-5</version>
|
||||
<version>${maven-assembly-plugin-version}</version>
|
||||
<configuration>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
@@ -166,6 +168,33 @@
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>${maven-deploy-plugin-version}</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>${central-publishing-maven-plugin-version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<autoPublish>true</autoPublish>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
<deploymentName>${project.groupId}-${project.artifactId}-${project.version}</deploymentName>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>deploy</phase>
|
||||
<goals>
|
||||
<goal>publish</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
</build>
|
||||
|
||||
@@ -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,17 @@ 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;
|
||||
if (offset > 12) {
|
||||
offset -= 12;
|
||||
}
|
||||
int zhiIndex = 2 + monthZhiIndex + timeZhiIndex;
|
||||
if (zhiIndex > 12) {
|
||||
zhiIndex -= 12;
|
||||
int ganIndex = (lunar.getYearGanIndexExact() + 1) * 2 + offset;
|
||||
while (ganIndex > 10) {
|
||||
ganIndex -= 10;
|
||||
}
|
||||
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];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 = "兑";
|
||||
@@ -1889,7 +1889,7 @@ public class Lunar {
|
||||
* @return 日吉神
|
||||
*/
|
||||
public List<String> getDayJiShen() {
|
||||
return LunarUtil.getDayJiShen(getMonth(), getDayInGanZhi());
|
||||
return LunarUtil.getDayJiShen(getMonthZhiIndex(), getDayInGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1898,7 +1898,7 @@ public class Lunar {
|
||||
* @return 日凶煞
|
||||
*/
|
||||
public List<String> getDayXiongSha() {
|
||||
return LunarUtil.getDayXiongSha(getMonth(), getDayInGanZhi());
|
||||
return LunarUtil.getDayXiongSha(getMonthZhiIndex(), getDayInGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class LunarMonth {
|
||||
this.dayCount = dayCount;
|
||||
this.firstJulianDay = firstJulianDay;
|
||||
this.index = index;
|
||||
this.zhiIndex = (index - 1 + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
|
||||
this.zhiIndex = (Math.abs(lunarMonth) - 1 + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ public class LunarMonth {
|
||||
|
||||
public int getGanIndex() {
|
||||
int offset = (LunarYear.fromYear(year).getGanIndex() + 1) % 5 * 2;
|
||||
return (index - 1 + offset) % 10;
|
||||
return (Math.abs(month) - 1 + offset) % 10;
|
||||
}
|
||||
|
||||
public String getGan() {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class NineStar {
|
||||
/**
|
||||
* 七色
|
||||
*/
|
||||
public static final String[] COLOR = {"白", "黒", "碧", "绿", "黄", "白", "赤", "白", "紫"};
|
||||
public static final String[] COLOR = {"白", "黑", "碧", "绿", "黄", "白", "赤", "白", "紫"};
|
||||
|
||||
/**
|
||||
* 五行
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
@@ -296,49 +300,75 @@ 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);
|
||||
if (d == 30) {
|
||||
solar = solar.nextHour(-1);
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -358,26 +388,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -602,6 +613,7 @@ public class Solar {
|
||||
|
||||
/**
|
||||
* 阳历日期相减,获得相差天数
|
||||
*
|
||||
* @param solar 阳历
|
||||
* @return 天数
|
||||
*/
|
||||
@@ -611,6 +623,7 @@ public class Solar {
|
||||
|
||||
/**
|
||||
* 阳历日期相减,获得相差分钟数
|
||||
*
|
||||
* @param solar 阳历
|
||||
* @return 分钟数
|
||||
*/
|
||||
@@ -629,6 +642,7 @@ public class Solar {
|
||||
|
||||
/**
|
||||
* 是否在指定日期之后
|
||||
*
|
||||
* @param solar 阳历
|
||||
* @return true/false
|
||||
*/
|
||||
@@ -668,6 +682,7 @@ public class Solar {
|
||||
|
||||
/**
|
||||
* 是否在指定日期之前
|
||||
*
|
||||
* @param solar 阳历
|
||||
* @return true/false
|
||||
*/
|
||||
@@ -707,6 +722,7 @@ public class Solar {
|
||||
|
||||
/**
|
||||
* 年推移
|
||||
*
|
||||
* @param years 年数
|
||||
* @return 阳历
|
||||
*/
|
||||
@@ -730,6 +746,7 @@ public class Solar {
|
||||
|
||||
/**
|
||||
* 月推移
|
||||
*
|
||||
* @param months 月数
|
||||
* @return 阳历
|
||||
*/
|
||||
@@ -790,7 +807,7 @@ public class Solar {
|
||||
d += days;
|
||||
}
|
||||
if (1582 == y && 10 == m) {
|
||||
if (d > 4 ) {
|
||||
if (d > 4) {
|
||||
d += 10;
|
||||
}
|
||||
}
|
||||
@@ -805,7 +822,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);
|
||||
@@ -834,6 +851,7 @@ public class Solar {
|
||||
|
||||
/**
|
||||
* 小时推移
|
||||
*
|
||||
* @param hours 小时数
|
||||
* @return 阳历
|
||||
*/
|
||||
@@ -853,6 +871,7 @@ public class Solar {
|
||||
|
||||
/**
|
||||
* 获取薪资比例(感谢 https://gitee.com/smr1987)
|
||||
*
|
||||
* @return 薪资比例:1/2/3
|
||||
*/
|
||||
public int getSalaryRate() {
|
||||
|
||||
@@ -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
@@ -6,7 +6,7 @@ import com.nlf.calendar.Solar;
|
||||
* 寿星天文历工具
|
||||
*
|
||||
* @author 6tail
|
||||
* @link http://www.nongli.net/sxwnl/
|
||||
* @link https://github.com/sxwnl/sxwnl
|
||||
*/
|
||||
public class ShouXingUtil {
|
||||
/**
|
||||
@@ -56,8 +56,18 @@ public class ShouXingUtil {
|
||||
2000, 63.87, 0.1, 0, 0,
|
||||
2005, 64.7, 0.21, 0, 0,
|
||||
2012, 66.8, 0.22, 0, 0,
|
||||
2018, 69.0, 0.36, 0, 0,
|
||||
2028, 72.6
|
||||
// 2018, 69.0, 0.36, 0, 0,
|
||||
// 使用skyfeild的DE440s△T预测数据拟合
|
||||
2016, 68.1024, 0.5456, -0.0542, -0.001172,
|
||||
2020, 69.3612, 0.0422, -0.0502, 0.006216,
|
||||
2024, 69.1752, -0.0335, -0.0048, 0.000811,
|
||||
2028, 69.0206, -0.0275, 0.0055, -0.000014,
|
||||
2032, 68.9981, 0.0163, 0.0054, 0.000006,
|
||||
2036, 69.1498, 0.0599, 0.0053, 0.000026,
|
||||
2040, 69.4751, 0.1035, 0.0051, 0.000046,
|
||||
2044, 69.9737, 0.1469, 0.0050, 0.000066,
|
||||
2048, 70.6451, 0.1903, 0.0049, 0.000085,
|
||||
2050, 71.0457
|
||||
};
|
||||
private static final double[] XL0 = {
|
||||
10000000000D,
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,168 @@ 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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test50() {
|
||||
List<Solar> solarTimes = Solar.fromBaZi("壬申", "壬寅", "庚辰", "甲申", 1, 1801);
|
||||
List<String> actual = new ArrayList<String>();
|
||||
for (Solar solarTime : solarTimes) {
|
||||
actual.add(solarTime.toYmdHms());
|
||||
}
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1812-02-18 16:00:00");
|
||||
expected.add("1992-03-05 15:00:00");
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test51() {
|
||||
Solar solar = new Solar(2013, 8, 8, 9, 30, 0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("时柱", "癸巳", eightChar.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,30 +21,30 @@ public class JieQiTest {
|
||||
Map<String,String> jieQi = new HashMap<String, String>(){
|
||||
private static final long serialVersionUID = 1L;
|
||||
{
|
||||
put("冬至","2021-12-21 23:59:18");
|
||||
put("小寒","2022-01-05 17:14:03");
|
||||
put("大寒","2022-01-20 10:39:05");
|
||||
put("立春","2022-02-04 04:50:45");
|
||||
put("雨水","2022-02-19 00:43:00");
|
||||
put("惊蛰","2022-03-05 22:43:43");
|
||||
put("春分","2022-03-20 23:33:24");
|
||||
put("清明","2022-04-05 03:20:13");
|
||||
put("谷雨","2022-04-20 10:24:16");
|
||||
put("立夏","2022-05-05 20:25:56");
|
||||
put("小满","2022-05-21 09:22:35");
|
||||
put("芒种","2022-06-06 00:25:47");
|
||||
put("夏至","2022-06-21 17:13:50");
|
||||
put("小暑","2022-07-07 10:37:59");
|
||||
put("大暑","2022-07-23 04:06:58");
|
||||
put("立秋","2022-08-07 20:29:07");
|
||||
put("处暑","2022-08-23 11:16:09");
|
||||
put("白露","2022-09-07 23:32:17");
|
||||
put("秋分","2022-09-23 09:03:41");
|
||||
put("寒露","2022-10-08 15:22:26");
|
||||
put("霜降","2022-10-23 18:35:41");
|
||||
put("立冬","2022-11-07 18:45:28");
|
||||
put("小雪","2022-11-22 16:20:28");
|
||||
put("大雪","2022-12-07 11:46:15");
|
||||
put("冬至","2021-12-21 23:59:19");
|
||||
put("小寒","2022-01-05 17:14:04");
|
||||
put("大寒","2022-01-20 10:39:06");
|
||||
put("立春","2022-02-04 04:50:47");
|
||||
put("雨水","2022-02-19 00:43:01");
|
||||
put("惊蛰","2022-03-05 22:43:45");
|
||||
put("春分","2022-03-20 23:33:26");
|
||||
put("清明","2022-04-05 03:20:14");
|
||||
put("谷雨","2022-04-20 10:24:18");
|
||||
put("立夏","2022-05-05 20:25:57");
|
||||
put("小满","2022-05-21 09:22:36");
|
||||
put("芒种","2022-06-06 00:25:49");
|
||||
put("夏至","2022-06-21 17:13:51");
|
||||
put("小暑","2022-07-07 10:38:01");
|
||||
put("大暑","2022-07-23 04:07:00");
|
||||
put("立秋","2022-08-07 20:29:08");
|
||||
put("处暑","2022-08-23 11:16:11");
|
||||
put("白露","2022-09-07 23:32:18");
|
||||
put("秋分","2022-09-23 09:03:43");
|
||||
put("寒露","2022-10-08 15:22:28");
|
||||
put("霜降","2022-10-23 18:35:43");
|
||||
put("立冬","2022-11-07 18:45:30");
|
||||
put("小雪","2022-11-22 16:20:30");
|
||||
put("大雪","2022-12-07 11:46:16");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -183,7 +183,7 @@ public class JieQiTest {
|
||||
@Test
|
||||
public void test8() {
|
||||
Lunar lunar = Lunar.fromYmd(2050, 12, 1);
|
||||
Assert.assertEquals("2050-12-07 06:41:13", lunar.getJieQiTable().get("DA_XUE").toYmdHms());
|
||||
Assert.assertEquals("2050-12-07 06:41:54", lunar.getJieQiTable().get("DA_XUE").toYmdHms());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -197,7 +197,13 @@ public class JieQiTest {
|
||||
@Test
|
||||
public void test10() {
|
||||
Lunar lunar = Solar.fromYmd(2023, 6, 1).getLunar();
|
||||
Assert.assertEquals("2022-12-22 05:48:11", lunar.getJieQiTable().get("冬至").toYmdHms());
|
||||
Assert.assertEquals("2022-12-22 05:48:12", lunar.getJieQiTable().get("冬至").toYmdHms());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test11() {
|
||||
Lunar lunar = Solar.fromYmd(2025, 3, 5).getLunar();
|
||||
Assert.assertEquals("2025-03-05 16:07:18", lunar.getJieQiTable().get("惊蛰").toYmdHms());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ public class LunarMonthTest {
|
||||
public void test1(){
|
||||
LunarMonth month = LunarMonth.fromYm(2023, -2);
|
||||
Assert.assertEquals(3, month.getIndex());
|
||||
Assert.assertEquals("丙辰", month.getGanZhi());
|
||||
Assert.assertEquals("乙卯", month.getGanZhi());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
LunarMonth month = LunarMonth.fromYm(2023, 3);
|
||||
Assert.assertEquals(4, month.getIndex());
|
||||
Assert.assertEquals("丁巳", month.getGanZhi());
|
||||
Assert.assertEquals("丙辰", month.getGanZhi());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +43,7 @@ public class LunarMonthTest {
|
||||
public void test4(){
|
||||
LunarMonth month = LunarMonth.fromYm(2023, 12);
|
||||
Assert.assertEquals(13, month.getIndex());
|
||||
Assert.assertEquals("丙寅", month.getGanZhi());
|
||||
Assert.assertEquals("乙丑", month.getGanZhi());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -645,4 +644,53 @@ public class LunarTest {
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test100() {
|
||||
Solar solar = new Solar(2025, 9, 16);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("[时德, 阳德, 民日, 玉宇, 司命]", lunar.getDayJiShen().toString());
|
||||
Assert.assertEquals("[河魁, 死神, 天吏, 致死, 往亡]", lunar.getDayXiongSha().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test101() {
|
||||
Solar solar = new Solar(2025, 12, 15);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("[阳德, 六仪, 续世, 解神, 司命]", lunar.getDayJiShen().toString());
|
||||
Assert.assertEquals("[月破, 大耗, 灾煞, 天火, 厌对, 招摇, 五虚, 血忌]", lunar.getDayXiongSha().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user