1
0
mirror of synced 2026-10-15 02:56:11 +08:00

v1.3.10 修复八字转阳历为空的问题;修复一处法定假日数据错误;十神优化。

This commit is contained in:
6tail
2024-01-03 19:31:09 +08:00
parent a17402241a
commit 1411d8017f
9 changed files with 73 additions and 118 deletions

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);
}
}