Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ef8d0c657 | ||
|
|
586a8d3f1e | ||
|
|
60dde2c619 |
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.3.1</version>
|
||||
<version>1.3.4</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.1</version>
|
||||
<version>1.3.4</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.3.1</version>
|
||||
<version>1.3.4</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>
|
||||
|
||||
@@ -185,8 +185,7 @@ public class EightChar {
|
||||
}
|
||||
|
||||
private String getDiShi(int zhiIndex) {
|
||||
int offset = CHANG_SHENG_OFFSET.get(getDayGan());
|
||||
int index = offset + (getDayGanIndex() % 2 == 0 ? zhiIndex : -zhiIndex);
|
||||
int index = CHANG_SHENG_OFFSET.get(getDayGan()) + (getDayGanIndex() % 2 == 0 ? zhiIndex : -zhiIndex);
|
||||
if (index >= 12) {
|
||||
index -= 12;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,10 @@ public class Foto {
|
||||
return lunar.getDayInChinese();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取因果犯忌
|
||||
* @return 因果犯忌
|
||||
*/
|
||||
public List<FotoFestival> getFestivals() {
|
||||
List<FotoFestival> l = new ArrayList<FotoFestival>();
|
||||
List<FotoFestival> fs = FotoUtil.FESTIVAL.get(getMonth() + "-" + getDay());
|
||||
@@ -83,6 +87,19 @@ public class Foto {
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取纪念日
|
||||
* @return 纪念日
|
||||
*/
|
||||
public List<String> getOtherFestivals() {
|
||||
List<String> l = new ArrayList<String>();
|
||||
List<String> fs = FotoUtil.OTHER_FESTIVAL.get(getMonth() + "-" + getDay());
|
||||
if (null != fs) {
|
||||
l.addAll(fs);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否月斋
|
||||
*
|
||||
|
||||
@@ -197,9 +197,7 @@ public class Lunar {
|
||||
public Lunar(Solar solar) {
|
||||
LunarYear ly = LunarYear.fromYear(solar.getYear());
|
||||
for (LunarMonth m : ly.getMonths()) {
|
||||
// 初一
|
||||
Solar firstDay = Solar.fromJulianDay(m.getFirstJulianDay());
|
||||
int days = solar.subtract(firstDay);
|
||||
int days = solar.subtract(Solar.fromJulianDay(m.getFirstJulianDay()));
|
||||
if (days < m.getDayCount()) {
|
||||
year = m.getYear();
|
||||
month = m.getMonth();
|
||||
@@ -1778,9 +1776,7 @@ public class Lunar {
|
||||
* @return 值日天神
|
||||
*/
|
||||
public String getDayTianShen() {
|
||||
String monthZhi = getMonthZhi();
|
||||
int offset = LunarUtil.ZHI_TIAN_SHEN_OFFSET.get(monthZhi);
|
||||
return LunarUtil.TIAN_SHEN[(dayZhiIndex + offset) % 12 + 1];
|
||||
return LunarUtil.TIAN_SHEN[(dayZhiIndex + LunarUtil.ZHI_TIAN_SHEN_OFFSET.get(getMonthZhi())) % 12 + 1];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1789,9 +1785,7 @@ public class Lunar {
|
||||
* @return 值时天神
|
||||
*/
|
||||
public String getTimeTianShen() {
|
||||
String dayZhi = getDayZhiExact();
|
||||
int offset = LunarUtil.ZHI_TIAN_SHEN_OFFSET.get(dayZhi);
|
||||
return LunarUtil.TIAN_SHEN[(timeZhiIndex + offset) % 12 + 1];
|
||||
return LunarUtil.TIAN_SHEN[(timeZhiIndex + LunarUtil.ZHI_TIAN_SHEN_OFFSET.get(getDayZhiExact())) % 12 + 1];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2899,8 +2893,7 @@ public class Lunar {
|
||||
start = Solar.fromYmd(start.getYear(), start.getMonth(), start.getDay());
|
||||
}
|
||||
|
||||
Solar end = Solar.fromYmd(start.getYear(), start.getMonth(), start.getDay());
|
||||
end = end.next(81);
|
||||
Solar end = Solar.fromYmd(start.getYear(), start.getMonth(), start.getDay()).next(81);
|
||||
|
||||
if (current.isBefore(start) || !current.isBefore(end)) {
|
||||
return null;
|
||||
|
||||
@@ -31,6 +31,10 @@ public class LunarMonth {
|
||||
*/
|
||||
private final double firstJulianDay;
|
||||
|
||||
private final int index;
|
||||
|
||||
private final int zhiIndex;
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
@@ -39,11 +43,13 @@ public class LunarMonth {
|
||||
* @param dayCount 天数
|
||||
* @param firstJulianDay 初一的儒略日
|
||||
*/
|
||||
public LunarMonth(int lunarYear, int lunarMonth, int dayCount, double firstJulianDay) {
|
||||
public LunarMonth(int lunarYear, int lunarMonth, int dayCount, double firstJulianDay, int index) {
|
||||
this.year = lunarYear;
|
||||
this.month = lunarMonth;
|
||||
this.dayCount = dayCount;
|
||||
this.firstJulianDay = firstJulianDay;
|
||||
this.index = index;
|
||||
this.zhiIndex = (index - 1 + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,6 +99,31 @@ public class LunarMonth {
|
||||
return dayCount;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public int getZhiIndex() {
|
||||
return zhiIndex;
|
||||
}
|
||||
|
||||
public int getGanIndex() {
|
||||
int offset = (LunarYear.fromYear(year).getGanIndex() + 1) % 5 * 2;
|
||||
return (index - 1 + offset) % 10;
|
||||
}
|
||||
|
||||
public String getGan() {
|
||||
return LunarUtil.GAN[getGanIndex() + 1];
|
||||
}
|
||||
|
||||
public String getZhi() {
|
||||
return LunarUtil.ZHI[zhiIndex + 1];
|
||||
}
|
||||
|
||||
public String getGanZhi() {
|
||||
return getGan() + getZhi();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取初一的儒略日
|
||||
*
|
||||
@@ -102,6 +133,46 @@ public class LunarMonth {
|
||||
return firstJulianDay;
|
||||
}
|
||||
|
||||
public String getPositionXi() {
|
||||
return LunarUtil.POSITION_XI[getGanIndex() + 1];
|
||||
}
|
||||
|
||||
public String getPositionXiDesc() {
|
||||
return LunarUtil.POSITION_DESC.get(getPositionXi());
|
||||
}
|
||||
|
||||
public String getPositionYangGui() {
|
||||
return LunarUtil.POSITION_YANG_GUI[getGanIndex() + 1];
|
||||
}
|
||||
|
||||
public String getPositionYangGuiDesc() {
|
||||
return LunarUtil.POSITION_DESC.get(getPositionYangGui());
|
||||
}
|
||||
|
||||
public String getPositionYinGui() {
|
||||
return LunarUtil.POSITION_YIN_GUI[getGanIndex() + 1];
|
||||
}
|
||||
|
||||
public String getPositionYinGuiDesc() {
|
||||
return LunarUtil.POSITION_DESC.get(getPositionYinGui());
|
||||
}
|
||||
|
||||
public String getPositionFu(int sect) {
|
||||
return (1 == sect ? LunarUtil.POSITION_FU : LunarUtil.POSITION_FU_2)[getGanIndex() + 1];
|
||||
}
|
||||
|
||||
public String getPositionFuDesc(int sect) {
|
||||
return LunarUtil.POSITION_DESC.get(getPositionFu(sect));
|
||||
}
|
||||
|
||||
public String getPositionCai() {
|
||||
return LunarUtil.POSITION_CAI[getGanIndex() + 1];
|
||||
}
|
||||
|
||||
public String getPositionCaiDesc() {
|
||||
return LunarUtil.POSITION_DESC.get(getPositionCai());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取太岁方位
|
||||
*
|
||||
@@ -121,7 +192,7 @@ public class LunarMonth {
|
||||
p = "坤";
|
||||
break;
|
||||
default:
|
||||
p = LunarUtil.POSITION_GAN[Solar.fromJulianDay(this.getFirstJulianDay()).getLunar().getMonthGanIndex()];
|
||||
p = LunarUtil.POSITION_GAN[Solar.fromJulianDay(getFirstJulianDay()).getLunar().getMonthGanIndex()];
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -206,9 +206,7 @@ public class LunarTime {
|
||||
* @return 值时天神
|
||||
*/
|
||||
public String getTianShen() {
|
||||
String dayZhi = lunar.getDayZhiExact();
|
||||
int offset = LunarUtil.ZHI_TIAN_SHEN_OFFSET.get(dayZhi);
|
||||
return LunarUtil.TIAN_SHEN[(zhiIndex + offset) % 12 + 1];
|
||||
return LunarUtil.TIAN_SHEN[(zhiIndex + LunarUtil.ZHI_TIAN_SHEN_OFFSET.get(lunar.getDayZhiExact())) % 12 + 1];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -134,7 +134,9 @@ public class LunarYear {
|
||||
// 冬至前的初一
|
||||
double w = ShouXingUtil.calcShuo(jq[0]);
|
||||
if (w > jq[0]) {
|
||||
w -= 29.5306;
|
||||
if (currentYear != 41 && currentYear != 193 && currentYear != 288 && currentYear != 345 && currentYear != 918 && currentYear != 1013) {
|
||||
w -= 29.5306;
|
||||
}
|
||||
}
|
||||
// 递推每月初一
|
||||
for (int i = 0, j = hs.length; i < j; i++) {
|
||||
@@ -145,43 +147,48 @@ public class LunarYear {
|
||||
dayCounts[i] = (int) (hs[i + 1] - hs[i]);
|
||||
}
|
||||
|
||||
Integer currentYearLeap = LEAP.get(currentYear);
|
||||
if (null == currentYearLeap) {
|
||||
currentYearLeap = -1;
|
||||
if (hs[13] <= jq[24]) {
|
||||
int i = 1;
|
||||
while (hs[i + 1] > jq[2 * i] && i < 13) {
|
||||
i++;
|
||||
}
|
||||
currentYearLeap = i;
|
||||
}
|
||||
}
|
||||
|
||||
int prevYear = currentYear - 1;
|
||||
Integer prevYearLeap = LEAP.get(prevYear);
|
||||
prevYearLeap = null == prevYearLeap ? -1 : prevYearLeap - 12;
|
||||
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
leapYear = currentYear;
|
||||
leapIndex = leap;
|
||||
}
|
||||
|
||||
int y = prevYear;
|
||||
int m = 11;
|
||||
int index = m;
|
||||
for (int i = 0, j = dayCounts.length; i < j; i++) {
|
||||
int cm = m;
|
||||
boolean isNextLeap = false;
|
||||
if (y == currentYear && i == currentYearLeap) {
|
||||
cm = -cm;
|
||||
} else if (y == prevYear && i == prevYearLeap) {
|
||||
if (y == leapYear && i == leapIndex) {
|
||||
cm = -cm;
|
||||
}
|
||||
if (y == currentYear && i + 1 == currentYearLeap) {
|
||||
isNextLeap = true;
|
||||
} else if (y == prevYear && i + 1 == prevYearLeap) {
|
||||
isNextLeap = true;
|
||||
}
|
||||
this.months.add(new LunarMonth(y, cm, dayCounts[i], hs[i] + Solar.J2000));
|
||||
if (!isNextLeap) {
|
||||
this.months.add(new LunarMonth(y, cm, dayCounts[i], hs[i] + Solar.J2000, index));
|
||||
if (y != leapYear || i + 1 != leapIndex) {
|
||||
m++;
|
||||
}
|
||||
index++;
|
||||
if (m == 13) {
|
||||
m = 1;
|
||||
index = 1;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
@@ -196,6 +203,35 @@ public class LunarYear {
|
||||
return year;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取总天数
|
||||
* @return 天数
|
||||
*/
|
||||
public int getDayCount() {
|
||||
int n = 0;
|
||||
for (LunarMonth m : months) {
|
||||
if (m.getYear() == year) {
|
||||
n += m.getDayCount();
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当年的农历月们
|
||||
*
|
||||
* @return 农历月们
|
||||
*/
|
||||
public List<LunarMonth> getMonthsInYear() {
|
||||
List<LunarMonth> l = new ArrayList<LunarMonth>();
|
||||
for (LunarMonth m : months) {
|
||||
if (m.getYear() == year) {
|
||||
l.add(m);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取农历月们
|
||||
*
|
||||
|
||||
@@ -86,6 +86,12 @@ public class Solar {
|
||||
throw new IllegalArgumentException(String.format("wrong solar year %d month %d day %d", year, month, day));
|
||||
}
|
||||
}
|
||||
if (month < 1 || month > 12) {
|
||||
throw new IllegalArgumentException(String.format("wrong month %d", month));
|
||||
}
|
||||
if (day < 1 || day > 31) {
|
||||
throw new IllegalArgumentException(String.format("wrong day %d", day));
|
||||
}
|
||||
if (hour < 0 || hour > 23) {
|
||||
throw new IllegalArgumentException(String.format("wrong hour %d", hour));
|
||||
}
|
||||
@@ -293,31 +299,38 @@ public class Solar {
|
||||
offsetYear += 60;
|
||||
}
|
||||
int startYear = today.getYear() - offsetYear - 1;
|
||||
while (true) {
|
||||
int minYear = baseYear - 2;
|
||||
while (startYear >= minYear) {
|
||||
years.add(startYear);
|
||||
startYear -= 60;
|
||||
if (startYear < baseYear) {
|
||||
years.add(baseYear);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
int hour = 0;
|
||||
String timeZhi = timeGanZhi.substring(1);
|
||||
for(int i = 0, j = LunarUtil.ZHI.length; i < j; i++){
|
||||
if(LunarUtil.ZHI[i].equals(timeZhi)){
|
||||
hour = (i - 1) * 2;
|
||||
}
|
||||
if ("子".equals(timeZhi)) {
|
||||
hours.add(23);
|
||||
}
|
||||
for (Integer y : years) {
|
||||
inner: for (int x = 0; x < 3; x++) {
|
||||
int year = y + x;
|
||||
Solar solar = fromYmdHms(year, 1, 1, hour, 0, 0);
|
||||
while (solar.getYear() == year) {
|
||||
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 inner;
|
||||
break;
|
||||
}
|
||||
solar = solar.next(1);
|
||||
}
|
||||
@@ -618,30 +631,35 @@ public class Solar {
|
||||
public boolean isAfter(Solar solar) {
|
||||
if (year > solar.getYear()) {
|
||||
return true;
|
||||
} else if (year < solar.getYear()) {
|
||||
}
|
||||
if (year < solar.getYear()) {
|
||||
return false;
|
||||
}
|
||||
if (month > solar.getMonth()) {
|
||||
return true;
|
||||
} else if (month < solar.getMonth()) {
|
||||
}
|
||||
if (month < solar.getMonth()) {
|
||||
return false;
|
||||
}
|
||||
if (day > solar.getDay()) {
|
||||
return true;
|
||||
} else if (day < solar.getDay()) {
|
||||
}
|
||||
if (day < solar.getDay()) {
|
||||
return false;
|
||||
}
|
||||
if (hour > solar.getHour()) {
|
||||
return true;
|
||||
} else if (hour < solar.getHour()) {
|
||||
}
|
||||
if (hour < solar.getHour()) {
|
||||
return false;
|
||||
}
|
||||
if (minute > solar.getMinute()) {
|
||||
return true;
|
||||
} else if (minute < solar.getMinute()) {
|
||||
}
|
||||
if (minute < solar.getMinute()) {
|
||||
return false;
|
||||
}
|
||||
return second > solar.second;
|
||||
return second > solar.getSecond();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -652,30 +670,35 @@ public class Solar {
|
||||
public boolean isBefore(Solar solar) {
|
||||
if (year > solar.getYear()) {
|
||||
return false;
|
||||
} else if (year < solar.getYear()) {
|
||||
}
|
||||
if (year < solar.getYear()) {
|
||||
return true;
|
||||
}
|
||||
if (month > solar.getMonth()) {
|
||||
return false;
|
||||
} else if (month < solar.getMonth()) {
|
||||
}
|
||||
if (month < solar.getMonth()) {
|
||||
return true;
|
||||
}
|
||||
if (day > solar.getDay()) {
|
||||
return false;
|
||||
} else if (day < solar.getDay()) {
|
||||
}
|
||||
if (day < solar.getDay()) {
|
||||
return true;
|
||||
}
|
||||
if (hour > solar.getHour()) {
|
||||
return false;
|
||||
} else if (hour < solar.getHour()) {
|
||||
}
|
||||
if (hour < solar.getHour()) {
|
||||
return true;
|
||||
}
|
||||
if (minute > solar.getMinute()) {
|
||||
return false;
|
||||
} else if (minute < solar.getMinute()) {
|
||||
}
|
||||
if (minute < solar.getMinute()) {
|
||||
return true;
|
||||
}
|
||||
return second < solar.second;
|
||||
return second < solar.getSecond();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -691,8 +714,7 @@ public class Solar {
|
||||
if (2 == m) {
|
||||
if (d > 28) {
|
||||
if (!SolarUtil.isLeapYear(y)) {
|
||||
d -= 28;
|
||||
m++;
|
||||
d = 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -710,8 +732,7 @@ public class Solar {
|
||||
* @return 阳历
|
||||
*/
|
||||
public Solar nextMonth(int months) {
|
||||
SolarMonth month = SolarMonth.fromYm(year, this.month);
|
||||
month = month.next(months);
|
||||
SolarMonth month = SolarMonth.fromYm(year, this.month).next(months);
|
||||
int y = month.getYear();
|
||||
int m = month.getMonth();
|
||||
int d = day;
|
||||
@@ -719,8 +740,7 @@ public class Solar {
|
||||
if (2 == m) {
|
||||
if (d > 28) {
|
||||
if (!SolarUtil.isLeapYear(y)) {
|
||||
d -= 28;
|
||||
m++;
|
||||
d = 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -742,33 +762,36 @@ public class Solar {
|
||||
int y = year;
|
||||
int m = month;
|
||||
int d = day;
|
||||
if (1582 == y && 10 == m) {
|
||||
if (d > 4) {
|
||||
d -= 10;
|
||||
}
|
||||
}
|
||||
if (days > 0) {
|
||||
d = day + days;
|
||||
d += days;
|
||||
int daysInMonth = SolarUtil.getDaysOfMonth(y, m);
|
||||
while (d > daysInMonth) {
|
||||
d -= daysInMonth;
|
||||
m++;
|
||||
if (m > 12) {
|
||||
m -= 12;
|
||||
m = 1;
|
||||
y++;
|
||||
}
|
||||
daysInMonth = SolarUtil.getDaysOfMonth(y, m);
|
||||
}
|
||||
} else if (days < 0) {
|
||||
int rest = -days;
|
||||
while (d <= rest) {
|
||||
rest -= d;
|
||||
while (d + days <= 0) {
|
||||
m--;
|
||||
if (m < 1) {
|
||||
m = 12;
|
||||
y--;
|
||||
}
|
||||
d = SolarUtil.getDaysOfMonth(y, m);
|
||||
d += SolarUtil.getDaysOfMonth(y, m);
|
||||
}
|
||||
d -= rest;
|
||||
d += days;
|
||||
}
|
||||
if (1582 == y && 10 == m) {
|
||||
if (d > 4 && d < 15) {
|
||||
if (d > 4 ) {
|
||||
d += 10;
|
||||
}
|
||||
}
|
||||
@@ -789,7 +812,7 @@ public class Solar {
|
||||
Solar solar = fromYmdHms(year, month, day, hour, minute, second);
|
||||
if (days != 0) {
|
||||
int rest = Math.abs(days);
|
||||
int add = days < 1 ? -1 : 1;
|
||||
int add = days < 0 ? -1 : 1;
|
||||
while (rest > 0) {
|
||||
solar = solar.next(add);
|
||||
boolean work = true;
|
||||
|
||||
@@ -214,10 +214,8 @@ public class SolarWeek {
|
||||
week = new SolarWeek(solar.getYear(), solar.getMonth(), solar.getDay(), start);
|
||||
}
|
||||
} else {
|
||||
int size = SolarUtil.getWeeksOfMonth(week.getYear(), week.getMonth(), start);
|
||||
if (size == index) {
|
||||
Solar firstDay = week.getFirstDay();
|
||||
Solar lastDay = firstDay.next(6);
|
||||
if (SolarUtil.getWeeksOfMonth(week.getYear(), week.getMonth(), start) == index) {
|
||||
Solar lastDay = week.getFirstDay().next(6);
|
||||
week = new SolarWeek(lastDay.getYear(), lastDay.getMonth(), lastDay.getDay(), start);
|
||||
weekMonth = week.getMonth();
|
||||
} else {
|
||||
|
||||
@@ -262,6 +262,46 @@ public class FotoUtil {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 纪念日
|
||||
*/
|
||||
public static final Map<String, List<String>> OTHER_FESTIVAL = new HashMap<String, List<String>>() {
|
||||
private static final long serialVersionUID = -1;
|
||||
|
||||
{
|
||||
put("1-1", Collections.nCopies(1, "弥勒菩萨圣诞"));
|
||||
put("1-6", Collections.nCopies(1, "定光佛圣诞"));
|
||||
put("2-8", Collections.nCopies(1, "释迦牟尼佛出家"));
|
||||
put("2-15", Collections.nCopies(1, "释迦牟尼佛涅槃"));
|
||||
put("2-19", Collections.nCopies(1, "观世音菩萨圣诞"));
|
||||
put("2-21", Collections.nCopies(1, "普贤菩萨圣诞"));
|
||||
put("3-16", Collections.nCopies(1, "准提菩萨圣诞"));
|
||||
put("4-4", Collections.nCopies(1, "文殊菩萨圣诞"));
|
||||
put("4-8", Collections.nCopies(1, "释迦牟尼佛圣诞"));
|
||||
put("4-15", Collections.nCopies(1, "佛吉祥日"));
|
||||
put("4-28", Collections.nCopies(1, "药王菩萨圣诞"));
|
||||
put("5-13", Collections.nCopies(1, "伽蓝菩萨圣诞"));
|
||||
put("6-3", Collections.nCopies(1, "韦驮菩萨圣诞"));
|
||||
put("6-19", Collections.nCopies(1, "观音菩萨成道"));
|
||||
put("7-13", Collections.nCopies(1, "大势至菩萨圣诞"));
|
||||
put("7-15", Collections.nCopies(1, "佛欢喜日"));
|
||||
put("7-24", Collections.nCopies(1, "龙树菩萨圣诞"));
|
||||
put("7-30", Collections.nCopies(1, "地藏菩萨圣诞"));
|
||||
put("8-15", Collections.nCopies(1, "月光菩萨圣诞"));
|
||||
put("8-22", Collections.nCopies(1, "燃灯佛圣诞"));
|
||||
put("9-9", Collections.nCopies(1, "摩利支天菩萨圣诞"));
|
||||
put("9-19", Collections.nCopies(1, "观世音菩萨出家"));
|
||||
put("9-30", Collections.nCopies(1, "药师琉璃光佛圣诞"));
|
||||
put("10-5", Collections.nCopies(1, "达摩祖师圣诞"));
|
||||
put("10-20", Collections.nCopies(1, "文殊菩萨出家"));
|
||||
put("11-17", Collections.nCopies(1, "阿弥陀佛圣诞"));
|
||||
put("11-19", Collections.nCopies(1, "日光菩萨圣诞"));
|
||||
put("12-8", Collections.nCopies(1, "释迦牟尼佛成道"));
|
||||
put("12-23", Collections.nCopies(1, "监斋菩萨圣诞"));
|
||||
put("12-29", Collections.nCopies(1, "华严菩萨圣诞"));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 27星宿,佛教从印度传入中国,印度把28星宿改为27星宿,把牛宿(牛金牛)纳入了女宿(女土蝠)。
|
||||
*/
|
||||
|
||||
@@ -90,12 +90,11 @@ public class HolidayUtil {
|
||||
private static List<Holiday> findHolidaysForward(String key){
|
||||
List<Holiday> l = new ArrayList<Holiday>();
|
||||
String s = findForward(key);
|
||||
if(null==s) {
|
||||
return l;
|
||||
}
|
||||
while(s.startsWith(key)){
|
||||
l.add(buildHolidayForward(s));
|
||||
s = s.substring(SIZE);
|
||||
if(null!=s) {
|
||||
while (s.startsWith(key)) {
|
||||
l.add(buildHolidayForward(s));
|
||||
s = s.substring(SIZE);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
@@ -103,14 +102,12 @@ public class HolidayUtil {
|
||||
private static List<Holiday> findHolidaysBackward(String key){
|
||||
List<Holiday> l = new ArrayList<Holiday>();
|
||||
String s = findBackward(key);
|
||||
if(null==s) {
|
||||
return l;
|
||||
if(null!=s) {
|
||||
while (s.endsWith(key)) {
|
||||
l.add(0, buildHolidayBackward(s));
|
||||
s = s.substring(0, s.length() - SIZE);
|
||||
}
|
||||
}
|
||||
while(s.endsWith(key)){
|
||||
l.add(buildHolidayBackward(s));
|
||||
s = s.substring(0,s.length()-SIZE);
|
||||
}
|
||||
Collections.reverse(l);
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class LunarUtil{
|
||||
public static final String[] WU_HOU = {"蚯蚓结","麋角解","水泉动","雁北乡","鹊始巢","雉始雊","鸡始乳","征鸟厉疾","水泽腹坚","东风解冻","蛰虫始振","鱼陟负冰","獭祭鱼","候雁北","草木萌动","桃始华","仓庚鸣","鹰化为鸠","玄鸟至","雷乃发声","始电","桐始华","田鼠化为鴽","虹始见","萍始生","鸣鸠拂奇羽","戴胜降于桑","蝼蝈鸣","蚯蚓出","王瓜生","苦菜秀","靡草死","麦秋至","螳螂生","鵙始鸣","反舌无声","鹿角解","蜩始鸣","半夏生","温风至","蟋蟀居壁","鹰始挚","腐草为萤","土润溽暑","大雨行时","凉风至","白露降","寒蝉鸣","鹰乃祭鸟","天地始肃","禾乃登","鸿雁来","玄鸟归","群鸟养羞","雷始收声","蛰虫坯户","水始涸","鸿雁来宾","雀入大水为蛤","菊有黄花","豺乃祭兽","草木黄落","蛰虫咸俯","水始冰","地始冻","雉入大水为蜃","虹藏不见","天气上升地气下降","闭塞而成冬","鹖鴠不鸣","虎始交","荔挺出"};
|
||||
/** 天干 */
|
||||
public static final String[] GAN = {"","甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
|
||||
/** 喜神方位,《喜神方位歌》:甲己在艮乙庚乾,丙辛坤位喜神安. 丁壬只在离宫坐,戊癸原在在巽间。 */
|
||||
/** 喜神方位,《喜神方位歌》:甲己在艮乙庚乾,丙辛坤位喜神安。丁壬只在离宫坐,戊癸原在在巽间。 */
|
||||
public static final String[] POSITION_XI = {"","艮","乾","坤","离","巽","艮","乾","坤","离","巽"};
|
||||
/** 阳贵方位,《阳贵神歌》:甲戊坤艮位,乙己是坤坎,庚辛居离艮,丙丁兑与乾,震巽属何日,壬癸贵神安。 */
|
||||
public static final String[] POSITION_YANG_GUI = {"","坤","坤","兑","乾","艮","坎","离","艮","震","巽"};
|
||||
@@ -33,7 +33,7 @@ public class LunarUtil{
|
||||
public static final String[] POSITION_FU = {"","巽","巽","震","震","坎","离","坤","坤","乾","兑"};
|
||||
/** 流派2《福神方位歌》:甲己正北是福神,丙辛西北乾宫存,乙庚坤位戊癸艮,丁壬巽上好追寻。 */
|
||||
public static final String[] POSITION_FU_2 = {"","坎","坤","乾","巽","艮","坎","坤","乾","巽","艮"};
|
||||
/** 财神方位,《财神方位歌》:甲乙东北是财神,丙丁向在西南寻,戊己正北坐方位, 庚辛正东去安身,壬癸原来正南坐,便是财神方位真。 */
|
||||
/** 财神方位,《财神方位歌》:甲乙东北是财神,丙丁向在西南寻,戊己正北坐方位,庚辛正东去安身,壬癸原来正南坐,便是财神方位真。 */
|
||||
public static final String[] POSITION_CAI = {"","艮","艮","坤","坤","坎","坎","震","震","离","离"};
|
||||
/** 年太岁方位 */
|
||||
public static final String[] POSITION_TAI_SUI_YEAR = {"坎","艮","艮","震","巽","巽","离","坤","坤","兑","坎","坎"};
|
||||
@@ -123,7 +123,7 @@ public class LunarUtil{
|
||||
/** 日 */
|
||||
public static final String[] DAY = {"","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"};
|
||||
/** 月相,朔月也叫新月,望月也叫满月 */
|
||||
public static final String[] YUE_XIANG = {"","朔","既朔","蛾眉新","蛾眉新","蛾眉","夕月","上弦","上弦","九夜","宵","宵","宵","渐盈凸","小望","望","既望","立待","居待","寝待","更待","渐亏凸","下弦","下弦","有明","有明","蛾眉残","蛾眉残","残","晓","晦"};
|
||||
public static final String[] YUE_XIANG = {"","朔","既朔","蛾眉新","蛾眉新","蛾眉","夕","上弦","上弦","九夜","宵","宵","宵","渐盈凸","小望","望","既望","立待","居待","寝待","更待","渐亏凸","下弦","下弦","有明","有明","蛾眉残","蛾眉残","残","晓","晦"};
|
||||
/** 农历日期对应的节日 */
|
||||
public static final Map<String,String> FESTIVAL = new HashMap<String,String>(){
|
||||
private static final long serialVersionUID = -1;
|
||||
@@ -1118,8 +1118,7 @@ public class LunarUtil{
|
||||
boolean matched = false;
|
||||
String months = left.substring(0, left.indexOf(":"));
|
||||
for (int i = 0, j = months.length(); i < j; i += 2) {
|
||||
String m = months.substring(i, i + 2);
|
||||
if (m.equals(month)) {
|
||||
if (month.equals(months.substring(i, i + 2))) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
@@ -1128,8 +1127,7 @@ public class LunarUtil{
|
||||
String ys = left.substring(left.indexOf(":") + 1);
|
||||
ys = ys.substring(0, ys.indexOf(","));
|
||||
for (int i = 0, j = ys.length(); i < j; i += 2) {
|
||||
String m = ys.substring(i, i + 2);
|
||||
l.add(YI_JI[Integer.parseInt(m,16)]);
|
||||
l.add(YI_JI[Integer.parseInt(ys.substring(i, i + 2),16)]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -69,70 +69,141 @@ public class SolarUtil {
|
||||
|
||||
{
|
||||
put("1-8", Collections.nCopies(1, "周恩来逝世纪念日"));
|
||||
put("1-10", Arrays.asList("中国人民警察节", "中国公安110宣传日"));
|
||||
put("1-10", Collections.nCopies(1, "中国人民警察节"));
|
||||
put("1-14", Collections.nCopies(1, "日记情人节"));
|
||||
put("1-21", Collections.nCopies(1, "列宁逝世纪念日"));
|
||||
put("1-26", Collections.nCopies(1, "国际海关日"));
|
||||
put("1-27", Collections.nCopies(1, "国际大屠杀纪念日"));
|
||||
put("2-2", Collections.nCopies(1, "世界湿地日"));
|
||||
put("2-4", Collections.nCopies(1, "世界抗癌日"));
|
||||
put("2-7", Collections.nCopies(1, "京汉铁路罢工纪念"));
|
||||
put("2-7", Collections.nCopies(1, "京汉铁路罢工纪念日"));
|
||||
put("2-10", Collections.nCopies(1, "国际气象节"));
|
||||
put("2-19", Collections.nCopies(1, "邓小平逝世纪念日"));
|
||||
put("2-20", Collections.nCopies(1, "世界社会公正日"));
|
||||
put("2-21", Collections.nCopies(1, "国际母语日"));
|
||||
put("2-24", Collections.nCopies(1, "第三世界青年日"));
|
||||
put("3-1", Collections.nCopies(1, "国际海豹日"));
|
||||
put("3-3", Collections.nCopies(1, "全国爱耳日"));
|
||||
put("3-3", Arrays.asList("世界野生动植物日", "全国爱耳日"));
|
||||
put("3-5", Arrays.asList("周恩来诞辰纪念日", "中国青年志愿者服务日"));
|
||||
put("3-6", Collections.nCopies(1, "世界青光眼日"));
|
||||
put("3-7", Collections.nCopies(1, "女生节"));
|
||||
put("3-12", Collections.nCopies(1, "孙中山逝世纪念日"));
|
||||
put("3-14", Collections.nCopies(1, "马克思逝世纪念日"));
|
||||
put("3-14", Arrays.asList("马克思逝世纪念日", "白色情人节"));
|
||||
put("3-17", Collections.nCopies(1, "国际航海日"));
|
||||
put("3-18", Collections.nCopies(1, "全国科技人才活动日"));
|
||||
put("3-21", Arrays.asList("世界森林日", "世界睡眠日"));
|
||||
put("3-18", Arrays.asList("全国科技人才活动日", "全国爱肝日"));
|
||||
put("3-20", Collections.nCopies(1, "国际幸福日"));
|
||||
put("3-21", Arrays.asList("世界森林日", "世界睡眠日", "国际消除种族歧视日"));
|
||||
put("3-22", Collections.nCopies(1, "世界水日"));
|
||||
put("3-23", Collections.nCopies(1, "世界气象日"));
|
||||
put("3-24", Collections.nCopies(1, "世界防治结核病日"));
|
||||
put("4-2", Collections.nCopies(1, "国际儿童图书日"));
|
||||
put("3-29", Collections.nCopies(1, "中国黄花岗七十二烈士殉难纪念日"));
|
||||
put("4-2", Arrays.asList("国际儿童图书日", "世界自闭症日"));
|
||||
put("4-4", Collections.nCopies(1, "国际地雷行动日"));
|
||||
put("4-7", Collections.nCopies(1, "世界卫生日"));
|
||||
put("4-22", Collections.nCopies(1, "列宁诞辰纪念日"));
|
||||
put("4-23", Collections.nCopies(1, "世界图书和版权日"));
|
||||
put("4-26", Collections.nCopies(1, "世界知识产权日"));
|
||||
put("4-8", Collections.nCopies(1, "国际珍稀动物保护日"));
|
||||
put("4-12", Collections.nCopies(1, "世界航天日"));
|
||||
put("4-14", Collections.nCopies(1, "黑色情人节"));
|
||||
put("4-15", Collections.nCopies(1, "全民国家安全教育日"));
|
||||
put("4-22", Arrays.asList("世界地球日", "列宁诞辰纪念日"));
|
||||
put("4-23", Collections.nCopies(1, "世界读书日"));
|
||||
put("4-24", Collections.nCopies(1, "中国航天日"));
|
||||
put("4-25", Collections.nCopies(1, "儿童预防接种宣传日"));
|
||||
put("4-26", Arrays.asList("世界知识产权日", "全国疟疾日"));
|
||||
put("4-28", Collections.nCopies(1, "世界安全生产与健康日"));
|
||||
put("4-30", Collections.nCopies(1, "全国交通安全反思日"));
|
||||
put("5-2", Collections.nCopies(1, "世界金枪鱼日"));
|
||||
put("5-3", Collections.nCopies(1, "世界新闻自由日"));
|
||||
put("5-5", Collections.nCopies(1, "马克思诞辰纪念日"));
|
||||
put("5-8", Collections.nCopies(1, "世界红十字日"));
|
||||
put("5-11", Collections.nCopies(1, "世界肥胖日"));
|
||||
put("5-12", Arrays.asList("全国防灾减灾日", "护士节"));
|
||||
put("5-14", Collections.nCopies(1, "玫瑰情人节"));
|
||||
put("5-15", Collections.nCopies(1, "国际家庭日"));
|
||||
put("5-19", Collections.nCopies(1, "中国旅游日"));
|
||||
put("5-20", Collections.nCopies(1, "网络情人节"));
|
||||
put("5-22", Collections.nCopies(1, "国际生物多样性日"));
|
||||
put("5-25", Collections.nCopies(1, "525心理健康节"));
|
||||
put("5-27", Collections.nCopies(1, "上海解放日"));
|
||||
put("5-29", Collections.nCopies(1, "国际维和人员日"));
|
||||
put("5-30", Collections.nCopies(1, "中国五卅运动纪念日"));
|
||||
put("5-31", Collections.nCopies(1, "世界无烟日"));
|
||||
put("6-3", Collections.nCopies(1, "世界自行车日"));
|
||||
put("6-5", Collections.nCopies(1, "世界环境日"));
|
||||
put("6-6", Collections.nCopies(1, "全国爱眼日"));
|
||||
put("6-8", Collections.nCopies(1, "世界海洋日"));
|
||||
put("6-11", Collections.nCopies(1, "中国人口日"));
|
||||
put("6-14", Collections.nCopies(1, "世界献血日"));
|
||||
put("6-14", Arrays.asList("世界献血日", "亲亲情人节"));
|
||||
put("6-17", Collections.nCopies(1, "世界防治荒漠化与干旱日"));
|
||||
put("6-20", Collections.nCopies(1, "世界难民日"));
|
||||
put("6-21", Collections.nCopies(1, "国际瑜伽日"));
|
||||
put("6-25", Collections.nCopies(1, "全国土地日"));
|
||||
put("6-26", Arrays.asList("国际禁毒日", "联合国宪章日"));
|
||||
put("7-1", Collections.nCopies(1, "香港回归纪念日"));
|
||||
put("7-7", Collections.nCopies(1, "中国人民抗日战争纪念日"));
|
||||
put("7-11", Collections.nCopies(1, "世界人口日"));
|
||||
put("7-6", Arrays.asList("国际接吻日", "朱德逝世纪念日"));
|
||||
put("7-7", Collections.nCopies(1, "七七事变纪念日"));
|
||||
put("7-11", Arrays.asList("世界人口日", "中国航海日"));
|
||||
put("7-14", Collections.nCopies(1, "银色情人节"));
|
||||
put("7-18", Collections.nCopies(1, "曼德拉国际日"));
|
||||
put("7-30", Collections.nCopies(1, "国际友谊日"));
|
||||
put("8-3", Collections.nCopies(1, "男人节"));
|
||||
put("8-5", Collections.nCopies(1, "恩格斯逝世纪念日"));
|
||||
put("8-6", Collections.nCopies(1, "国际电影节"));
|
||||
put("8-12", Collections.nCopies(1, "国际青年日"));
|
||||
put("8-8", Collections.nCopies(1, "全民健身日"));
|
||||
put("8-9", Collections.nCopies(1, "国际土著人日"));
|
||||
put("8-12", Collections.nCopies(1, "国际青年节"));
|
||||
put("8-14", Collections.nCopies(1, "绿色情人节"));
|
||||
put("8-19", Arrays.asList("世界人道主义日", "中国医师节"));
|
||||
put("8-22", Collections.nCopies(1, "邓小平诞辰纪念日"));
|
||||
put("8-29", Collections.nCopies(1, "全国测绘法宣传日"));
|
||||
put("9-3", Collections.nCopies(1, "中国抗日战争胜利纪念日"));
|
||||
put("9-5", Collections.nCopies(1, "中华慈善日"));
|
||||
put("9-8", Collections.nCopies(1, "世界扫盲日"));
|
||||
put("9-9", Collections.nCopies(1, "毛泽东逝世纪念日"));
|
||||
put("9-14", Collections.nCopies(1, "世界清洁地球日"));
|
||||
put("9-9", Arrays.asList("毛泽东逝世纪念日", "全国拒绝酒驾日"));
|
||||
put("9-14", Arrays.asList("世界清洁地球日", "相片情人节"));
|
||||
put("9-15", Collections.nCopies(1, "国际民主日"));
|
||||
put("9-16", Collections.nCopies(1, "国际臭氧层保护日"));
|
||||
put("9-17", Collections.nCopies(1, "世界骑行日"));
|
||||
put("9-18", Collections.nCopies(1, "九一八事变纪念日"));
|
||||
put("9-20", Collections.nCopies(1, "全国爱牙日"));
|
||||
put("9-21", Collections.nCopies(1, "国际和平日"));
|
||||
put("9-27", Collections.nCopies(1, "世界旅游日"));
|
||||
put("9-30", Collections.nCopies(1, "中国烈士纪念日"));
|
||||
put("10-1", Collections.nCopies(1, "国际老年人日"));
|
||||
put("10-2", Collections.nCopies(1, "国际非暴力日"));
|
||||
put("10-4", Collections.nCopies(1, "世界动物日"));
|
||||
put("10-11", Collections.nCopies(1, "国际女童日"));
|
||||
put("10-10", Collections.nCopies(1, "辛亥革命纪念日"));
|
||||
put("10-13", Collections.nCopies(1, "中国少年先锋队诞辰日"));
|
||||
put("10-13", Arrays.asList("国际减轻自然灾害日", "中国少年先锋队诞辰日"));
|
||||
put("10-14", Collections.nCopies(1, "葡萄酒情人节"));
|
||||
put("10-16", Collections.nCopies(1, "世界粮食日"));
|
||||
put("10-17", Collections.nCopies(1, "全国扶贫日"));
|
||||
put("10-20", Collections.nCopies(1, "世界统计日"));
|
||||
put("10-24", Arrays.asList("世界发展信息日", "程序员节"));
|
||||
put("10-25", Collections.nCopies(1, "抗美援朝纪念日"));
|
||||
put("11-5", Collections.nCopies(1, "世界海啸日"));
|
||||
put("11-8", Collections.nCopies(1, "记者节"));
|
||||
put("11-9", Collections.nCopies(1, "全国消防日"));
|
||||
put("11-11", Collections.nCopies(1, "光棍节"));
|
||||
put("11-12", Collections.nCopies(1, "孙中山诞辰纪念日"));
|
||||
put("11-14", Collections.nCopies(1, "电影情人节"));
|
||||
put("11-16", Collections.nCopies(1, "国际宽容日"));
|
||||
put("11-17", Collections.nCopies(1, "国际大学生节"));
|
||||
put("11-19", Collections.nCopies(1, "世界厕所日"));
|
||||
put("11-28", Collections.nCopies(1, "恩格斯诞辰纪念日"));
|
||||
put("11-29", Collections.nCopies(1, "国际声援巴勒斯坦人民日"));
|
||||
put("12-1", Collections.nCopies(1, "世界艾滋病日"));
|
||||
put("12-2", Collections.nCopies(1, "全国交通安全日"));
|
||||
put("12-3", Collections.nCopies(1, "世界残疾人日"));
|
||||
put("12-4", Collections.nCopies(1, "全国法制宣传日"));
|
||||
put("12-5", Arrays.asList("世界弱能人士日", "国际志愿人员日"));
|
||||
put("12-7", Collections.nCopies(1, "国际民航日"));
|
||||
put("12-9", Arrays.asList("世界足球日", "国际反腐败日"));
|
||||
put("12-10", Collections.nCopies(1, "世界人权日"));
|
||||
put("12-11", Collections.nCopies(1, "国际山岳日"));
|
||||
put("12-12", Collections.nCopies(1, "西安事变纪念日"));
|
||||
put("12-13", Collections.nCopies(1, "国家公祭日"));
|
||||
put("12-14", Collections.nCopies(1, "拥抱情人节"));
|
||||
put("12-18", Collections.nCopies(1, "国际移徙者日"));
|
||||
put("12-26", Collections.nCopies(1, "毛泽东诞辰纪念日"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -365,4 +365,45 @@ public class BaZiTest {
|
||||
Assert.assertEquals("日柱", "戊子", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "甲寅", eightChar.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test14() {
|
||||
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");
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test15() {
|
||||
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("1960-01-15 16:00:00");
|
||||
expected.add("1900-01-29 16:00:00");
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test16() {
|
||||
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("1959-12-17 16:00:00");
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import com.nlf.calendar.Lunar;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 佛历测试
|
||||
*
|
||||
@@ -28,4 +31,12 @@ public class FotoTest {
|
||||
Assert.assertEquals("青龙", foto.getShou());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
Foto foto = Foto.fromLunar(Lunar.fromYmd(2021, 3, 16));
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("准提菩萨圣诞");
|
||||
Assert.assertEquals(expected, foto.getOtherFestivals());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
56
src/test/java/test/LunarMonthTest.java
Normal file
56
src/test/java/test/LunarMonthTest.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.LunarMonth;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 农历月测试
|
||||
*
|
||||
* @author 6tail
|
||||
*/
|
||||
public class LunarMonthTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
LunarMonth month = LunarMonth.fromYm(2023, 1);
|
||||
Assert.assertEquals(1, month.getIndex());
|
||||
Assert.assertEquals("甲寅", month.getGanZhi());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1(){
|
||||
LunarMonth month = LunarMonth.fromYm(2023, -2);
|
||||
Assert.assertEquals(3, month.getIndex());
|
||||
Assert.assertEquals("丙辰", month.getGanZhi());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
LunarMonth month = LunarMonth.fromYm(2023, 3);
|
||||
Assert.assertEquals(4, month.getIndex());
|
||||
Assert.assertEquals("丁巳", month.getGanZhi());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3(){
|
||||
LunarMonth month = LunarMonth.fromYm(2024, 1);
|
||||
Assert.assertEquals(1, month.getIndex());
|
||||
Assert.assertEquals("丙寅", month.getGanZhi());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4(){
|
||||
LunarMonth month = LunarMonth.fromYm(2023, 12);
|
||||
Assert.assertEquals(13, month.getIndex());
|
||||
Assert.assertEquals("丙寅", month.getGanZhi());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5(){
|
||||
LunarMonth month = LunarMonth.fromYm(2022, 1);
|
||||
Assert.assertEquals(1, month.getIndex());
|
||||
Assert.assertEquals("壬寅", month.getGanZhi());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -459,4 +459,172 @@ public class LunarTest {
|
||||
Assert.assertEquals("1582-10-15", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test64() {
|
||||
Lunar lunar = Lunar.fromYmd(1518, 1, 1);
|
||||
Assert.assertEquals("1518-02-10", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test65() {
|
||||
Lunar lunar = Lunar.fromYmd(793, 1, 1);
|
||||
Assert.assertEquals("0793-02-15", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test66() {
|
||||
Lunar lunar = Lunar.fromYmd(2025, -6, 1);
|
||||
Assert.assertEquals("2025-07-25", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test67() {
|
||||
Lunar lunar = Lunar.fromYmd(2025, 6, 1);
|
||||
Assert.assertEquals("2025-06-25", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test68() {
|
||||
Lunar lunar = Lunar.fromYmd(193, 1, 1);
|
||||
Assert.assertEquals("0193-02-19", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test69() {
|
||||
Lunar lunar = Lunar.fromYmd(288, 1, 1);
|
||||
Assert.assertEquals("0288-02-19", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test70() {
|
||||
Lunar lunar = Lunar.fromYmd(755, 1, 1);
|
||||
Assert.assertEquals("0755-02-16", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test71() {
|
||||
Lunar lunar = Lunar.fromYmd(41, 1, 1);
|
||||
Assert.assertEquals("0041-02-20", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test72() {
|
||||
Lunar lunar = Lunar.fromYmd(57, 1, 1);
|
||||
Assert.assertEquals("0057-02-23", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test73() {
|
||||
Lunar lunar = Lunar.fromYmd(345, 1, 1);
|
||||
Assert.assertEquals("0345-02-18", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test74() {
|
||||
Lunar lunar = Lunar.fromYmd(459, 1, 1);
|
||||
Assert.assertEquals("0459-02-18", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test75() {
|
||||
Lunar lunar = Lunar.fromYmd(497, 1, 1);
|
||||
Assert.assertEquals("0497-02-18", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test76() {
|
||||
Lunar lunar = Lunar.fromYmd(516, 1, 1);
|
||||
Assert.assertEquals("0516-02-18", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test77() {
|
||||
Lunar lunar = Lunar.fromYmd(554, 1, 1);
|
||||
Assert.assertEquals("0554-02-18", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test78() {
|
||||
Lunar lunar = Lunar.fromYmd(698, 1, 1);
|
||||
Assert.assertEquals("0698-02-16", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test79() {
|
||||
Lunar lunar = Lunar.fromYmd(793, 1, 1);
|
||||
Assert.assertEquals("0793-02-15", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test80() {
|
||||
Lunar lunar = Lunar.fromYmd(918, 1, 1);
|
||||
Assert.assertEquals("0918-02-14", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test81() {
|
||||
Lunar lunar = Lunar.fromYmd(1013, 1, 1);
|
||||
Assert.assertEquals("1013-02-13", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test82() {
|
||||
Lunar lunar = Lunar.fromYmd(1051, 1, 1);
|
||||
Assert.assertEquals("1051-02-14", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test83() {
|
||||
Lunar lunar = Lunar.fromYmd(1070, 1, 1);
|
||||
Assert.assertEquals("1070-02-14", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test84() {
|
||||
Lunar lunar = Lunar.fromYmd(1127, 1, 1);
|
||||
Assert.assertEquals("1127-02-13", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test85() {
|
||||
Lunar lunar = Lunar.fromYmd(1146, 1, 1);
|
||||
Assert.assertEquals("1146-02-13", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test86() {
|
||||
Lunar lunar = Lunar.fromYmd(1165, 1, 1);
|
||||
Assert.assertEquals("1165-02-13", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test87() {
|
||||
Lunar lunar = Lunar.fromYmd(1423, 1, 1);
|
||||
Assert.assertEquals("1423-02-11", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test88() {
|
||||
Lunar lunar = Lunar.fromYmd(1442, 1, 1);
|
||||
Assert.assertEquals("1442-02-11", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test89() {
|
||||
Lunar lunar = Lunar.fromYmd(1461, 1, 1);
|
||||
Assert.assertEquals("1461-02-10", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test90() {
|
||||
Lunar lunar = Lunar.fromYmd(1556, 1, 1);
|
||||
Assert.assertEquals("1556-02-11", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test91() {
|
||||
Lunar lunar = Lunar.fromYmd(1537, 1, 1);
|
||||
Assert.assertEquals("1537-02-10", lunar.getSolar().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Lunar;
|
||||
import com.nlf.calendar.Solar;
|
||||
import com.nlf.calendar.util.SolarUtil;
|
||||
import org.junit.Assert;
|
||||
@@ -145,4 +146,29 @@ public class SolarTest {
|
||||
Assert.assertEquals(355, days);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test23(){
|
||||
Solar solar = Solar.fromYmd(1991, 5, 12);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("壬午", lunar.getDayInGanZhi());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test24(){
|
||||
Solar solar = new Solar(1582, 10, 15);
|
||||
Assert.assertEquals("1582-09-30", solar.next(-5).toYmd());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test25(){
|
||||
Solar solar = new Solar(1582, 10, 15);
|
||||
Assert.assertEquals("1582-10-04", solar.next(-1).toYmd());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test26(){
|
||||
Solar solar = new Solar(1582, 10, 15);
|
||||
Assert.assertEquals("1582-09-29", solar.next(-6).toYmd());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -139,4 +139,34 @@ public class YearTest {
|
||||
Assert.assertEquals("八运",year.getYun());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test18(){
|
||||
LunarYear year = new LunarYear(2023);
|
||||
Assert.assertEquals(384, year.getDayCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test19(){
|
||||
LunarYear year = new LunarYear(1517);
|
||||
Assert.assertEquals(384, year.getDayCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test20(){
|
||||
LunarYear year = new LunarYear(1518);
|
||||
Assert.assertEquals(355, year.getDayCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test21(){
|
||||
LunarYear year = new LunarYear(2022);
|
||||
Assert.assertEquals(355, year.getDayCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test22(){
|
||||
LunarYear year = new LunarYear(2021);
|
||||
Assert.assertEquals(354, year.getDayCount());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user