Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85d56e5c3b | ||
|
|
b7fac53a81 | ||
|
|
72c4d0df71 | ||
|
|
10beaefd34 | ||
|
|
f1be26456d | ||
|
|
cc9444aa03 | ||
|
|
df6119c19e | ||
|
|
c7cd454f2d | ||
|
|
5680eb8d44 |
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.1.7</version>
|
||||
<version>1.1.10</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.1.7</version>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.7</version>
|
||||
<version>1.1.10</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>
|
||||
|
||||
@@ -323,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){
|
||||
@@ -336,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;
|
||||
}
|
||||
@@ -381,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) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.nlf.calendar.util.HolidayUtil;
|
||||
import com.nlf.calendar.util.LunarUtil;
|
||||
import com.nlf.calendar.util.SolarUtil;
|
||||
|
||||
@@ -536,9 +537,36 @@ public class Solar{
|
||||
* @return 阳历日期
|
||||
*/
|
||||
public Solar next(int days){
|
||||
return next(days,false);
|
||||
}
|
||||
|
||||
public Solar next(int days, boolean onlyWorkday){
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(year,month-1,day,hour,minute,second);
|
||||
c.add(Calendar.DATE,days);
|
||||
if(0!=days) {
|
||||
if(!onlyWorkday){
|
||||
c.add(Calendar.DATE,days);
|
||||
}else {
|
||||
int rest = Math.abs(days);
|
||||
int add = days < 1 ? -1 : 1;
|
||||
while (rest > 0) {
|
||||
c.add(Calendar.DATE, add);
|
||||
boolean work = true;
|
||||
Holiday holiday = HolidayUtil.getHoliday(c.get(Calendar.YEAR), c.get(Calendar.MONTH)+1, c.get(Calendar.DAY_OF_MONTH));
|
||||
if(null==holiday){
|
||||
int week = c.get(Calendar.DAY_OF_WEEK);
|
||||
if(1==week||7==week){
|
||||
work = false;
|
||||
}
|
||||
}else{
|
||||
work = holiday.isWork();
|
||||
}
|
||||
if(work){
|
||||
rest--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Solar(c);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
49
src/test/java/test/HolidayTest.java
Normal file
49
src/test/java/test/HolidayTest.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.util.HolidayUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HolidayTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
Assert.assertEquals("2020-01-01 元旦节 2020-01-01",HolidayUtil.getHoliday("2020-01-01")+"");
|
||||
|
||||
// 将2020-01-01修改为春节
|
||||
HolidayUtil.fix("202001011120200101");
|
||||
Assert.assertEquals("2020-01-01 春节 2020-01-01",HolidayUtil.getHoliday("2020-01-01")+"");
|
||||
|
||||
// 追加2099-01-01为元旦节
|
||||
HolidayUtil.fix("209901010120990101");
|
||||
Assert.assertEquals("2099-01-01 元旦节 2099-01-01",HolidayUtil.getHoliday("2099-01-01")+"");
|
||||
|
||||
// 将2020-01-01修改为春节,并追加2099-01-01为元旦节
|
||||
HolidayUtil.fix("202001011120200101209901010120990101");
|
||||
Assert.assertEquals("2020-01-01 春节 2020-01-01",HolidayUtil.getHoliday("2020-01-01")+"");
|
||||
Assert.assertEquals("2099-01-01 元旦节 2099-01-01",HolidayUtil.getHoliday("2099-01-01")+"");
|
||||
|
||||
// 更改节假日名称
|
||||
String[] names = HolidayUtil.NAMES;
|
||||
names[0] = "元旦";
|
||||
names[1] = "大年初一";
|
||||
|
||||
HolidayUtil.fix(names, null);
|
||||
Assert.assertEquals("2020-01-01 大年初一 2020-01-01",HolidayUtil.getHoliday("2020-01-01")+"");
|
||||
Assert.assertEquals("2099-01-01 元旦 2099-01-01",HolidayUtil.getHoliday("2099-01-01")+"");
|
||||
|
||||
// 追加节假日名称和数据
|
||||
names = new String[12];
|
||||
for(int i=0,j=HolidayUtil.NAMES.length;i<j;i++){
|
||||
names[i] = HolidayUtil.NAMES[i];
|
||||
}
|
||||
names[9] = "我的生日";
|
||||
names[10] = "结婚纪念日";
|
||||
names[11] = "她的生日";
|
||||
|
||||
HolidayUtil.fix(names, "20210529912021052920211111:12021111120211201;120211201");
|
||||
Assert.assertEquals("2021-05-29 我的生日 2021-05-29",HolidayUtil.getHoliday("2021-05-29")+"");
|
||||
Assert.assertEquals("2021-11-11 结婚纪念日 2021-11-11",HolidayUtil.getHoliday("2021-11-11")+"");
|
||||
Assert.assertEquals("2021-12-01 她的生日 2021-12-01",HolidayUtil.getHoliday("2021-12-01")+"");
|
||||
}
|
||||
}
|
||||
@@ -20,4 +20,27 @@ public class SolarTest {
|
||||
Assert.assertEquals("二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 (七殿泰山王诞) 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[坎](正北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]",date.getLunar().toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNext(){
|
||||
Solar date = new Solar(2020,1,23);
|
||||
Assert.assertEquals("2020-01-24",date.next(1).toString());
|
||||
// 仅工作日,跨越春节假期
|
||||
Assert.assertEquals("2020-02-03",date.next(1,true).toString());
|
||||
|
||||
date = new Solar(2020,2,3);
|
||||
Assert.assertEquals("2020-01-31",date.next(-3).toString());
|
||||
// 仅工作日,跨越春节假期
|
||||
Assert.assertEquals("2020-01-21",date.next(-3,true).toString());
|
||||
|
||||
date = new Solar(2020,2,9);
|
||||
Assert.assertEquals("2020-02-15",date.next(6).toString());
|
||||
// 仅工作日,跨越周末
|
||||
Assert.assertEquals("2020-02-17",date.next(6,true).toString());
|
||||
|
||||
date = new Solar(2020,1,17);
|
||||
Assert.assertEquals("2020-01-18",date.next(1).toString());
|
||||
// 仅工作日,周日调休按上班算
|
||||
Assert.assertEquals("2020-01-19",date.next(1,true).toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user