Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10beaefd34 | ||
|
|
f1be26456d | ||
|
|
cc9444aa03 | ||
|
|
df6119c19e | ||
|
|
c7cd454f2d | ||
|
|
5680eb8d44 | ||
|
|
392ac5b00a | ||
|
|
9ec735cd4b | ||
|
|
e06c7a0532 | ||
|
|
bd18254834 | ||
|
|
28dbf8f45f | ||
|
|
0d1f64664e |
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.1.5</version>
|
||||
<version>1.1.9</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -44,7 +44,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
|
||||
|
||||
### 下载jar
|
||||
|
||||
如果使用jar,建议下载最新的SNAPSHOT版本,bug将得到及时的修复。
|
||||
如果使用jar,建议下载最新的版本,bug将得到及时的修复。
|
||||
|
||||
[Download](https://github.com/6tail/lunar-java/releases)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.1.5</version>
|
||||
<version>1.1.9</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -40,7 +40,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
|
||||
|
||||
### Download
|
||||
|
||||
If you will use jars in your projects, I suggest you to download latest snapshot versions with less bugs.
|
||||
If you will use jars in your projects, I suggest you to download latest versions with less bugs.
|
||||
|
||||
[Download](https://github.com/6tail/lunar-java/releases)
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.5</version>
|
||||
<version>1.1.9</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>
|
||||
|
||||
@@ -20,6 +20,14 @@ public class Lunar{
|
||||
public static final String JIE_QI_FIRST = "冬至";
|
||||
/** 农历年末节气名(节令:大雪) */
|
||||
public static final String JIE_QI_LAST = "大雪";
|
||||
/** 节气表尾部追加阳历下年初的第一个节气名(节令:小寒),以示区分 */
|
||||
public static final String JIE_APPEND_SOLAR_FIRST = "XIAO_HAN";
|
||||
/** 节气表尾部追加阳历下年初的第二个节气名(气令:大寒),以示区分 */
|
||||
public static final String QI_APPEND_SOLAR_SECOND = "DA_HAN";
|
||||
/** 阳历下年初的第一个节气名(节令:小寒) */
|
||||
public static final String JIE_SOLAR_FIRST = "小寒";
|
||||
/** 阳历下年初的第二个节气名(气令:大寒) */
|
||||
public static final String QI_SOLAR_SECOND = "大寒";
|
||||
/** 1弧度对应的角秒 */
|
||||
private static final double SECOND_PER_RAD = 180 * 3600 / Math.PI;
|
||||
/** 节气表,国标以冬至为首个节气 */
|
||||
@@ -315,7 +323,7 @@ public class Lunar{
|
||||
t -= (53 * t * t + 334116 * Math.cos(4.67 + 628.307585 * t) + 2061 * Math.cos(2.678 + 628.3076 * t) * t) / v / 10000000;
|
||||
l = 48950621.66 + 6283319653.318 * t + 53 * t * t + 334166 * Math.cos(4.669257 + 628.307585 * t) + 3489 * Math.cos(4.6261 + 1256.61517 * t) + 2060.6 * Math.cos(2.67823 + 628.307585 * t) * t - 994 - 834 * Math.sin(2.1824 - 33.75705 * t);
|
||||
t -= (l / 10000000 - w) / 628.332 + (32 * (t + 1.8) * (t + 1.8) - 20) / 86400 / 36525;
|
||||
return t * 36525 + 8 / 24;
|
||||
return t * 36525 + 8D / 24;
|
||||
}
|
||||
|
||||
private double saLonT2(double w){
|
||||
@@ -328,10 +336,10 @@ public class Lunar{
|
||||
|
||||
private double qiHigh(double w){
|
||||
double t = saLonT2(w) * 36525;
|
||||
t = t - dtT(t) + 8 / 24;
|
||||
t = t - dtT(t) + 8D / 24;
|
||||
double v = ((t + 0.5) % 1) * 86400;
|
||||
if (v < 1200 || v > 86400 - 1200){
|
||||
t = saLonT(w) * 36525 - dtT(t) + 8 / 24;
|
||||
t = saLonT(w) * 36525 - dtT(t) + 8D / 24;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
@@ -373,7 +381,7 @@ public class Lunar{
|
||||
|
||||
private double qiAccurate(double w){
|
||||
double t = saLonT(w) * 36525;
|
||||
return t - dtT(t) + 8 * 1D / 24;
|
||||
return t - dtT(t) + 8D / 24;
|
||||
}
|
||||
|
||||
private double qiAccurate2(double jd) {
|
||||
@@ -408,6 +416,16 @@ public class Lunar{
|
||||
//追加下一农历年初的冬至
|
||||
q = calcJieQi(w + 15.2184 * size);
|
||||
jieQi.put(JIE_QI_APPEND, Solar.fromJulianDay(qiAccurate2(q) + Solar.J2000));
|
||||
|
||||
//追加下一阳历年初的小寒
|
||||
size++;
|
||||
q = calcJieQi(w + 15.2184 * size);
|
||||
jieQi.put(JIE_APPEND_SOLAR_FIRST, Solar.fromJulianDay(qiAccurate2(q) + Solar.J2000));
|
||||
|
||||
//追加下一阳历年初的大寒
|
||||
size++;
|
||||
q = calcJieQi(w + 15.2184 * size);
|
||||
jieQi.put(QI_APPEND_SOLAR_SECOND, Solar.fromJulianDay(qiAccurate2(q) + Solar.J2000));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -979,6 +997,11 @@ public class Lunar{
|
||||
if(d.getYear()==solar.getYear()&&d.getMonth()==solar.getMonth()&&d.getDay()==solar.getDay()){
|
||||
return JIE_QI_LAST;
|
||||
}
|
||||
// 追加的节令:小寒
|
||||
d = jieQi.get(JIE_APPEND_SOLAR_FIRST);
|
||||
if(d.getYear()==solar.getYear()&&d.getMonth()==solar.getMonth()&&d.getDay()==solar.getDay()){
|
||||
return JIE_SOLAR_FIRST;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -999,6 +1022,11 @@ public class Lunar{
|
||||
if(d.getYear()==solar.getYear()&&d.getMonth()==solar.getMonth()&&d.getDay()==solar.getDay()){
|
||||
return JIE_QI_FIRST;
|
||||
}
|
||||
// 追加的气令:大寒
|
||||
d = jieQi.get(QI_APPEND_SOLAR_SECOND);
|
||||
if(d.getYear()==solar.getYear()&&d.getMonth()==solar.getMonth()&&d.getDay()==solar.getDay()){
|
||||
return QI_SOLAR_SECOND;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -1875,8 +1903,11 @@ public class Lunar{
|
||||
}
|
||||
// 寅月起,所以需要-2
|
||||
int monthIndex = monthZhiIndex-2;
|
||||
if(monthIndex<0){
|
||||
monthIndex += 12;
|
||||
}
|
||||
int index = start-monthIndex-1;
|
||||
if(index<0){
|
||||
while(index<0){
|
||||
index += 9;
|
||||
}
|
||||
return new NineStar(index);
|
||||
@@ -2030,6 +2061,12 @@ public class Lunar{
|
||||
if(JIE_QI_PREPEND.equals(jq)){
|
||||
jq = JIE_QI_LAST;
|
||||
}
|
||||
if(JIE_APPEND_SOLAR_FIRST.equals(jq)){
|
||||
jq = JIE_SOLAR_FIRST;
|
||||
}
|
||||
if(QI_APPEND_SOLAR_SECOND.equals(jq)){
|
||||
jq = QI_SOLAR_SECOND;
|
||||
}
|
||||
if(filter){
|
||||
if(!filters.contains(jq)){
|
||||
continue;
|
||||
@@ -2078,6 +2115,10 @@ public class Lunar{
|
||||
name = JIE_QI_FIRST;
|
||||
}else if(JIE_QI_PREPEND.equals(name)){
|
||||
name = JIE_QI_LAST;
|
||||
}else if(JIE_APPEND_SOLAR_FIRST.equals(name)){
|
||||
name = JIE_SOLAR_FIRST;
|
||||
}else if(QI_APPEND_SOLAR_SECOND.equals(name)){
|
||||
name = QI_SOLAR_SECOND;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -39,16 +39,17 @@ public class DaYun {
|
||||
this.yun = yun;
|
||||
this.lunar = yun.getLunar();
|
||||
this.index = index;
|
||||
int birthYear = lunar.getSolar().getYear();
|
||||
int year = yun.getStartSolar().getYear();
|
||||
if (index < 1) {
|
||||
this.startYear = lunar.getSolar().getYear();
|
||||
this.startYear = birthYear;
|
||||
this.startAge = 1;
|
||||
this.endYear = year - 1;
|
||||
this.endAge = yun.getStartYear();
|
||||
this.endAge = year - birthYear;
|
||||
} else {
|
||||
int add = (index - 1) * 10;
|
||||
this.startYear = year + add;
|
||||
this.startAge = yun.getStartYear() + add + 1;
|
||||
this.startAge = this.startYear - birthYear + 1;
|
||||
this.endYear = this.startYear + 9;
|
||||
this.endAge = this.startAge + 9;
|
||||
}
|
||||
|
||||
@@ -250,6 +250,54 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(years[i] + "年", ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
|
||||
solar = new Solar(1981, 8, 16, 9, 30, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
years = new int[]{1981, 1982, 1983};
|
||||
ages = new int[]{1, 2, 3};
|
||||
ganZhi = new String[]{"辛酉","壬戌","癸亥"};
|
||||
l = daYun[0].getLiuNian();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuNian liuNian = l[i];
|
||||
Assert.assertEquals(years[i], liuNian.getYear());
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
|
||||
years = new int[]{1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993};
|
||||
ages = new int[]{4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
|
||||
ganZhi = new String[]{"甲子","乙丑","丙寅","丁卯","戊辰","己巳","庚午","辛未","壬申","癸酉"};
|
||||
l = daYun[1].getLiuNian();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuNian liuNian = l[i];
|
||||
Assert.assertEquals(years[i], liuNian.getYear());
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
|
||||
solar = new Solar(1981, 8, 8, 1, 30, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
l = daYun[0].getLiuNian();
|
||||
Assert.assertEquals(0, l.length);
|
||||
|
||||
years = new int[]{1981,1982, 1983,1984, 1985, 1986, 1987, 1988, 1989, 1990};
|
||||
ages = new int[]{1,2,3,4,5,6,7,8,9,10};
|
||||
ganZhi = new String[]{"辛酉","壬戌","癸亥","甲子","乙丑","丙寅","丁卯","戊辰","己巳","庚午"};
|
||||
l = daYun[1].getLiuNian();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuNian liuNian = l[i];
|
||||
Assert.assertEquals(years[i], liuNian.getYear());
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -154,5 +154,23 @@ public class JieQiTest {
|
||||
Assert.assertEquals("小寒", lunar.getNextJie().getName());
|
||||
Assert.assertEquals("大寒", lunar.getNextQi().getName());
|
||||
Assert.assertEquals("小寒", lunar.getNextJieQi().getName());
|
||||
|
||||
|
||||
solar = Solar.fromYmd(2012,12,25);
|
||||
lunar = solar.getLunar();
|
||||
Assert.assertEquals("", lunar.getJie());
|
||||
Assert.assertEquals("", lunar.getQi());
|
||||
Assert.assertEquals("", lunar.getJieQi());
|
||||
Assert.assertNull(lunar.getCurrentJie());
|
||||
Assert.assertNull(lunar.getCurrentQi());
|
||||
Assert.assertNull(lunar.getCurrentJieQi());
|
||||
|
||||
Assert.assertEquals("小寒", lunar.getNextJie().getName());
|
||||
Assert.assertEquals("大寒", lunar.getNextQi().getName());
|
||||
Assert.assertEquals("小寒", lunar.getNextJieQi().getName());
|
||||
|
||||
Assert.assertEquals("大雪", lunar.getPrevJie().getName());
|
||||
Assert.assertEquals("冬至", lunar.getPrevQi().getName());
|
||||
Assert.assertEquals("冬至", lunar.getPrevJieQi().getName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user