1
0
mirror of synced 2026-10-08 16:04:11 +08:00

Compare commits

...

4 Commits

20 changed files with 1021 additions and 444 deletions

View File

@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.3.3</version>
<version>1.3.7</version>
</dependency>
```
@@ -54,3 +54,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
## 文档
请移步至 [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=6tail/lunar-java&type=Date)](https://star-history.com/#6tail/lunar-java&Date)

View File

@@ -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.3</version>
<version>1.3.7</version>
</dependency>
```
@@ -50,3 +50,7 @@ Output:
## Documentation
Please visit [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=6tail/lunar-java&type=Date)](https://star-history.com/#6tail/lunar-java&Date)

View File

@@ -7,7 +7,7 @@
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<packaging>jar</packaging>
<version>1.3.3</version>
<version>1.3.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>

View File

@@ -152,7 +152,7 @@ public class EightChar {
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_ZHI.get(getDayGan() + gan));
}
return l;
}
@@ -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;
}

View File

@@ -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;
}
/**
* 是否月斋
*

View File

@@ -1776,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];
}
/**
@@ -1787,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];
}
/**

View File

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

View File

@@ -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];
}
/**

View File

@@ -4,9 +4,7 @@ import com.nlf.calendar.util.LunarUtil;
import com.nlf.calendar.util.ShouXingUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 农历年
@@ -28,24 +26,15 @@ public class LunarYear {
/**
* 闰冬月年份
*/
private static final int[] LEAP_11 = {75, 94, 170, 238, 265, 322, 389, 469, 553, 583, 610, 678, 735, 754, 773, 849, 887, 936, 1050, 1069, 1126, 1145, 1164, 1183, 1259, 1278, 1308, 1373, 1403, 1441, 1460, 1498, 1555, 1593, 1612, 1631, 1642, 2033, 2128, 2147, 2242, 2614, 2728, 2910, 3062, 3244, 3339, 3616, 3711, 3730, 3825, 4007, 4159, 4197, 4322, 4341, 4379, 4417, 4531, 4599, 4694, 4713, 4789, 4808, 4971, 5085, 5104, 5161, 5180, 5199, 5294, 5305, 5476, 5677, 5696, 5772, 5791, 5848, 5886, 6049, 6068, 6144, 6163, 6258, 6402, 6440, 6497, 6516, 6630, 6641, 6660, 6679, 6736, 6774, 6850, 6869, 6899, 6918, 6994, 7013, 7032, 7051, 7070, 7089, 7108, 7127, 7146, 7222, 7271, 7290, 7309, 7366, 7385, 7404, 7442, 7461, 7480, 7491, 7499, 7594, 7624, 7643, 7662, 7681, 7719, 7738, 7814, 7863, 7882, 7901, 7939, 7958, 7977, 7996, 8034, 8053, 8072, 8091, 8121, 8159, 8186, 8216, 8235, 8254, 8273, 8311, 8330, 8341, 8349, 8368, 8444, 8463, 8474, 8493, 8531, 8569, 8588, 8626, 8664, 8683, 8694, 8702, 8713, 8721, 8751, 8789, 8808, 8816, 8827, 8846, 8884, 8903, 8922, 8941, 8971, 9036, 9066, 9085, 9104, 9123, 9142, 9161, 9180, 9199, 9218, 9256, 9294, 9313, 9324, 9343, 9362, 9381, 9419, 9438, 9476, 9514, 9533, 9544, 9552, 9563, 9571, 9582, 9601, 9639, 9658, 9666, 9677, 9696, 9734, 9753, 9772, 9791, 9802, 9821, 9886, 9897, 9916, 9935, 9954, 9973, 9992};
private static final int[] LEAP_11 = {75, 94, 170, 265, 322, 398, 469, 553, 583, 610, 678, 735, 754, 773, 849, 887, 936, 1050, 1069, 1126, 1145, 1164, 1183, 1259, 1278, 1308, 1373, 1403, 1441, 1460, 1498, 1555, 1593, 1612, 1631, 1642, 2033, 2128, 2147, 2242, 2614, 2728, 2910, 3062, 3244, 3339, 3616, 3711, 3730, 3825, 4007, 4159, 4197, 4322, 4341, 4379, 4417, 4531, 4599, 4694, 4713, 4789, 4808, 4971, 5085, 5104, 5161, 5180, 5199, 5294, 5305, 5476, 5677, 5696, 5772, 5791, 5848, 5886, 6049, 6068, 6144, 6163, 6258, 6402, 6440, 6497, 6516, 6630, 6641, 6660, 6679, 6736, 6774, 6850, 6869, 6899, 6918, 6994, 7013, 7032, 7051, 7070, 7089, 7108, 7127, 7146, 7222, 7271, 7290, 7309, 7366, 7385, 7404, 7442, 7461, 7480, 7491, 7499, 7594, 7624, 7643, 7662, 7681, 7719, 7738, 7814, 7863, 7882, 7901, 7939, 7958, 7977, 7996, 8034, 8053, 8072, 8091, 8121, 8159, 8186, 8216, 8235, 8254, 8273, 8311, 8330, 8341, 8349, 8368, 8444, 8463, 8474, 8493, 8531, 8569, 8588, 8626, 8664, 8683, 8694, 8702, 8713, 8721, 8751, 8789, 8808, 8816, 8827, 8846, 8884, 8903, 8922, 8941, 8971, 9036, 9066, 9085, 9104, 9123, 9142, 9161, 9180, 9199, 9218, 9256, 9294, 9313, 9324, 9343, 9362, 9381, 9419, 9438, 9476, 9514, 9533, 9544, 9552, 9563, 9571, 9582, 9601, 9639, 9658, 9666, 9677, 9696, 9734, 9753, 9772, 9791, 9802, 9821, 9886, 9897, 9916, 9935, 9954, 9973, 9992};
/**
* 闰腊月年份
*/
private static final int[] LEAP_12 = {37, 56, 113, 132, 151, 189, 208, 227, 246, 284, 303, 341, 360, 379, 417, 436, 458, 477, 496, 515, 534, 572, 591, 629, 648, 667, 697, 716, 792, 811, 830, 868, 906, 925, 944, 963, 982, 1001, 1020, 1039, 1058, 1088, 1153, 1202, 1221, 1240, 1297, 1335, 1392, 1411, 1422, 1430, 1517, 1525, 1536, 1574, 3358, 3472, 3806, 3988, 4751, 4941, 5066, 5123, 5275, 5343, 5438, 5457, 5495, 5533, 5552, 5715, 5810, 5829, 5905, 5924, 6421, 6535, 6793, 6812, 6888, 6907, 7002, 7184, 7260, 7279, 7374, 7556, 7746, 7757, 7776, 7833, 7852, 7871, 7966, 8015, 8110, 8129, 8148, 8224, 8243, 8338, 8406, 8425, 8482, 8501, 8520, 8558, 8596, 8607, 8615, 8645, 8740, 8778, 8835, 8865, 8930, 8960, 8979, 8998, 9017, 9055, 9074, 9093, 9112, 9150, 9188, 9237, 9275, 9332, 9351, 9370, 9408, 9427, 9446, 9457, 9465, 9495, 9560, 9590, 9628, 9647, 9685, 9715, 9742, 9780, 9810, 9818, 9829, 9848, 9867, 9905, 9924, 9943, 9962, 10000};
private static final Map<Integer, Integer> LEAP = new HashMap<Integer, Integer>();
private static final int[] YMC = {11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
private static final Map<Integer, LunarYear> CACHE = new HashMap<Integer, LunarYear>();
static {
for (int y : LEAP_11) {
LEAP.put(y, 13);
}
for (int y : LEAP_12) {
LEAP.put(y, 14);
}
}
private static LunarYear CACHE_YEAR = null;
/**
* 农历年
@@ -93,101 +82,127 @@ public class LunarYear {
compute();
}
private static boolean contains(int[] arr, int n) {
for (int o : arr) {
if (n == o) {
return true;
}
}
return false;
}
/**
* 通过农历年初始化
*
* @param lunarYear 农历年
* @return 农历年
*/
public static LunarYear fromYear(int lunarYear) {
LunarYear obj = CACHE.get(lunarYear);
if (null == obj) {
obj = new LunarYear(lunarYear);
CACHE.put(lunarYear, obj);
public synchronized static LunarYear fromYear(int lunarYear) {
LunarYear y;
if (null == LunarYear.CACHE_YEAR || LunarYear.CACHE_YEAR.getYear() != lunarYear) {
y = new LunarYear(lunarYear);
LunarYear.CACHE_YEAR = y;
} else {
y = LunarYear.CACHE_YEAR;
}
return obj;
return y;
}
private void compute() {
// 节气(中午12点)
// 节气
double[] jq = new double[27];
// 合朔,即每月初一(中午12点)
// 合朔,即每月初一
double[] hs = new double[16];
// 每月天数
int[] dayCounts = new int[hs.length - 1];
int[] dayCounts = new int[15];
int[] months = new int[15];
int currentYear = this.year;
int year = currentYear - 2000;
double jd = Math.floor((currentYear - 2000) * 365.2422 + 180);
// 355是2000.12冬至,得到较靠近jd的冬至估计值
double w = Math.floor((jd - 355 + 183) / 365.2422) * 365.2422 + 355;
if (ShouXingUtil.calcQi(w) > jd) {
w -= 365.2422;
}
// 25个节气时刻(北京时间),从冬至开始到下一个冬至以后
for (int i = 0; i < 26; i++) {
jq[i] = ShouXingUtil.calcQi(w + 15.2184 * i);
}
// 从上年的大雪到下年的立春
for (int i = 0, j = Lunar.JIE_QI_IN_USE.length; i < j; i++) {
// 精确的节气
double t = 36525 * ShouXingUtil.saLonT((year + (17 + i) * 15d / 360) * ShouXingUtil.PI_2);
t += ShouXingUtil.ONE_THIRD - ShouXingUtil.dtT(t);
jieQiJulianDays.add(t + Solar.J2000);
// 按中午12点算的节气
if (i > 0 && i < 28) {
jq[i - 1] = Math.round(t);
if (i == 0) {
jd = ShouXingUtil.qiAccurate2(jq[0] - 15.2184);
} else if (i <= 26) {
jd = ShouXingUtil.qiAccurate2(jq[i - 1]);
} else {
jd = ShouXingUtil.qiAccurate2(jq[25] + 15.2184 * (i - 26));
}
jieQiJulianDays.add(jd + Solar.J2000);
}
// 冬至前的初一
double w = ShouXingUtil.calcShuo(jq[0]);
// 冬至前的初一,今年"首朔"的日月黄经差w
w = ShouXingUtil.calcShuo(jq[0]);
if (w > jq[0]) {
if (currentYear != 41 && currentYear != 193 && currentYear != 288 && currentYear != 345 && currentYear != 918 && currentYear != 1013) {
w -= 29.5306;
}
w -= 29.53;
}
// 递推每月初一
for (int i = 0, j = hs.length; i < j; i++) {
for (int i = 0; i < 16; i++) {
hs[i] = ShouXingUtil.calcShuo(w + 29.5306 * i);
}
// 每月天数
for (int i = 0, j = dayCounts.length; i < j; i++) {
dayCounts[i] = (int) (hs[i + 1] - hs[i]);
// 每月
for (int i = 0; i < 15; i++) {
dayCounts[i] = (int)(hs[i + 1] - hs[i]);
months[i] = i;
}
int prevYear = currentYear - 1;
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;
int leapIndex = 16;
if (contains(LEAP_11, currentYear)) {
leapIndex = 13;
} else if (contains(LEAP_12, currentYear)) {
leapIndex = 14;
} else if (hs[13] <= jq[24]) {
int i = 1;
while (hs[i + 1] > jq[2 * i] && i < 13) {
i++;
}
} else {
leapYear = currentYear;
leapIndex = leap;
leapIndex = i;
}
for (int i = leapIndex; i < 15; i++) {
months[i] -= 1;
}
int fm = -1;
int index = -1;
int y = prevYear;
int m = 11;
for (int i = 0, j = dayCounts.length; i < j; i++) {
int cm = m;
if (y == leapYear && i == leapIndex) {
cm = -cm;
for (int i = 0; i < 15; i++) {
double dm = hs[i] + Solar.J2000;
int v2 = months[i];
int mc = YMC[v2 % 12];
if (1724360 <= dm && dm < 1729794) {
mc = YMC[(v2 + 1) % 12];
} else if (1807724 <= dm && dm < 1808699) {
mc = YMC[(v2 + 1) % 12];
} else if (dm == 1729794 || dm == 1808699) {
mc = 12;
}
this.months.add(new LunarMonth(y, cm, dayCounts[i], hs[i] + Solar.J2000));
if (y != leapYear || i + 1 != leapIndex) {
m++;
if (fm == -1) {
fm = mc;
index = mc;
}
if (m == 13) {
m = 1;
y++;
if (mc < fm) {
y += 1;
index = 1;
}
fm = mc;
if (i == leapIndex) {
mc = -mc;
} else if (dm == 1729794 || dm == 1808699) {
mc = -11;
}
this.months.add(new LunarMonth(y, mc, dayCounts[i], hs[i] + Solar.J2000, index));
index++;
}
}

View File

@@ -186,6 +186,10 @@ public class Solar {
minute -= 60;
hour++;
}
if (hour > 23) {
hour -= 24;
day += 1;
}
this.year = year;
this.month = month;
this.day = day;
@@ -306,9 +310,10 @@ public class Solar {
}
List<Integer> hours = new ArrayList<Integer>(2);
String timeZhi = timeGanZhi.substring(1);
for(int i = 0, j = LunarUtil.ZHI.length; i < j; i++){
for(int i = 1, j = LunarUtil.ZHI.length; i < j; i++){
if(LunarUtil.ZHI[i].equals(timeZhi)){
hours.add((i - 1) * 2);
break;
}
}
if ("子".equals(timeZhi)) {
@@ -709,19 +714,17 @@ public class Solar {
int y = year + years;
int m = month;
int d = day;
// 2月处理
if (2 == m) {
if (1582 == y && 10 == m) {
if (d > 4 && d < 15) {
d += 10;
}
} else if (2 == m) {
if (d > 28) {
if (!SolarUtil.isLeapYear(y)) {
d = 28;
}
}
}
if (1582 == y && 10 == m) {
if (d > 4 && d < 15) {
d += 10;
}
}
return fromYmdHms(y, m, d, hour, minute, second);
}
@@ -735,18 +738,15 @@ public class Solar {
int y = month.getYear();
int m = month.getMonth();
int d = day;
// 2月处理
if (2 == m) {
if (d > 28) {
if (!SolarUtil.isLeapYear(y)) {
d = 28;
}
}
}
if (1582 == y && 10 == m) {
if (d > 4 && d < 15) {
d += 10;
}
} else {
int maxDay = SolarUtil.getDaysOfMonth(y, m);
if (d > maxDay) {
d = maxDay;
}
}
return fromYmdHms(y, m, d, hour, minute, second);
}
@@ -851,4 +851,54 @@ public class Solar {
return fromYmdHms(solar.getYear(), solar.getMonth(), solar.getDay(), hour, solar.getMinute(), solar.getSecond());
}
/**
* 获取薪资比例(感谢 https://gitee.com/smr1987)
* @return 薪资比例:1/2/3
*/
public int getSalaryRate() {
// 元旦节
if (month == 1 && day == 1) {
return 3;
}
// 劳动节
if (month == 5 && day == 1) {
return 3;
}
// 国庆
if (month == 10 && day >= 1 && day <= 3) {
return 3;
}
Lunar lunar = getLunar();
// 春节
if (lunar.getMonth() == 1 && lunar.getDay() >= 1 && lunar.getDay() <= 3) {
return 3;
}
// 端午
if (lunar.getMonth() == 5 && lunar.getDay() == 5) {
return 3;
}
// 中秋
if (lunar.getMonth() == 8 && lunar.getDay() == 15) {
return 3;
}
// 清明
if ("清明".equals(lunar.getJieQi())) {
return 3;
}
Holiday holiday = HolidayUtil.getHoliday(year, month, day);
if (null != holiday) {
// 法定假日非上班
if (!holiday.isWork()) {
return 2;
}
} else {
// 周末
int week = getWeek();
if (week == 6 || week == 0) {
return 2;
}
}
// 工作日
return 1;
}
}

View File

@@ -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星宿,把牛宿(牛金牛)纳入了女宿(女土蝠)。
*/

File diff suppressed because one or more lines are too long

View File

@@ -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;
@@ -159,7 +159,7 @@ public class LunarUtil{
put("6-6",Collections.nCopies(1,"天贶节"));
put("6-24",Collections.nCopies(1,"观莲节"));
put("6-25",Collections.nCopies(1,"五谷母节"));
put("7-14",Collections.nCopies(1,"中元节"));
put("7-15",Collections.nCopies(1,"中元节"));
put("7-22",Collections.nCopies(1,"财神节"));
put("7-29",Collections.nCopies(1,"地藏节"));
put("8-1",Collections.nCopies(1,"天灸日"));
@@ -709,286 +709,106 @@ public class LunarUtil{
public static final Map<String,String> SHI_SHEN_ZHI = new HashMap<String,String>() {
private static final long serialVersionUID = -1;
{
put("甲子癸","正印");
put("甲丑癸","正印");
put("甲丑己","正财");
put("甲丑辛","正官");
put("甲寅丙","食神");
put("甲寅甲","比肩");
put("甲寅戊","偏财");
put("甲卯乙","劫财");
put("甲辰乙","劫财");
put("甲辰戊","偏财");
put("甲辰癸","正印");
put("甲巳戊","偏财");
put("甲巳丙","食神");
put("甲巳庚","七杀");
put("甲午丁","伤官");
put("甲午己","正财");
put("甲未乙","劫财");
put("甲未己","正财");
put("甲未丁","伤官");
put("甲申戊","偏财");
put("甲申庚","七杀");
put("甲申壬","偏印");
put("甲酉辛","正官");
put("甲戌辛","正官");
put("甲戌戊","偏财");
put("甲戌丁","伤官");
put("甲亥壬","偏印");
put("甲亥甲","比肩");
put("乙子癸","偏印");
put("乙丑癸","偏印");
put("乙丑己","偏财");
put("乙丑辛","七杀");
put("乙寅丙","伤官");
put("乙寅甲","劫财");
put("乙寅戊","正财");
put("乙卯乙","比肩");
put("乙辰乙","比肩");
put("乙辰戊","正财");
put("乙辰癸","偏印");
put("乙巳戊","正财");
put("乙巳丙","伤官");
put("乙巳庚","正官");
put("乙午丁","食神");
put("乙午己","偏财");
put("乙未乙","比肩");
put("乙未己","偏财");
put("乙未丁","食神");
put("乙申戊","正财");
put("乙申庚","正官");
put("乙申壬","正印");
put("乙酉辛","七杀");
put("乙戌辛","七杀");
put("乙戌戊","正财");
put("乙戌丁","食神");
put("乙亥壬","正印");
put("乙亥甲","劫财");
put("丙子癸","正官");
put("丙丑癸","正官");
put("丙丑己","伤官");
put("丙丑辛","正财");
put("丙寅丙","比肩");
put("丙寅甲","偏印");
put("丙寅戊","食神");
put("丙卯乙","正印");
put("丙辰乙","正印");
put("丙辰戊","食神");
put("丙辰癸","正官");
put("丙巳戊","食神");
put("丙巳丙","比肩");
put("丙巳庚","偏财");
put("丙午丁","劫财");
put("丙午己","伤官");
put("丙未乙","正印");
put("丙未己","伤官");
put("丙未丁","劫财");
put("丙申戊","食神");
put("丙申庚","偏财");
put("丙申壬","七杀");
put("丙酉辛","正财");
put("丙戌辛","正财");
put("丙戌戊","食神");
put("丙戌丁","劫财");
put("丙亥壬","七杀");
put("丙亥甲","偏印");
put("丁子癸","七杀");
put("丁丑癸","七杀");
put("丁丑己","食神");
put("丁丑辛","偏财");
put("丁寅丙","劫财");
put("丁寅甲","正印");
put("丁寅戊","伤官");
put("丁卯乙","偏印");
put("丁辰乙","偏印");
put("丁辰戊","伤官");
put("丁辰癸","七杀");
put("丁巳戊","伤官");
put("丁巳丙","劫财");
put("丁巳庚","正财");
put("丁午丁","比肩");
put("丁午己","食神");
put("丁未乙","偏印");
put("丁未己","食神");
put("丁未丁","比肩");
put("丁申戊","伤官");
put("丁申庚","正财");
put("丁申壬","正官");
put("丁酉辛","偏财");
put("丁戌辛","偏财");
put("丁戌戊","伤官");
put("丁戌丁","比肩");
put("丁亥壬","正官");
put("丁亥甲","正印");
put("戊子癸","正财");
put("戊丑癸","正财");
put("戊丑己","劫财");
put("戊丑辛","伤官");
put("戊寅丙","偏印");
put("戊寅甲","七杀");
put("戊寅戊","比肩");
put("戊卯乙","正官");
put("戊辰乙","正官");
put("戊辰戊","比肩");
put("戊辰癸","正财");
put("戊巳戊","比肩");
put("戊巳丙","偏印");
put("戊巳庚","食神");
put("戊午丁","正印");
put("戊午己","劫财");
put("戊未乙","正官");
put("戊未己","劫财");
put("戊未丁","正印");
put("戊申戊","比肩");
put("戊申庚","食神");
put("戊申壬","偏财");
put("戊酉辛","伤官");
put("戊戌辛","伤官");
put("戊戌戊","比肩");
put("戊戌丁","正印");
put("戊亥壬","偏财");
put("戊亥甲","七杀");
put("己子癸","偏财");
put("己丑癸","偏财");
put("己丑己","比肩");
put("己丑辛","食神");
put("己寅丙","正印");
put("己寅甲","正官");
put("己寅戊","劫财");
put("己卯乙","七杀");
put("己辰乙","七杀");
put("己辰戊","劫财");
put("己辰癸","偏财");
put("己巳戊","劫财");
put("己巳丙","正印");
put("己巳庚","伤官");
put("己午丁","偏印");
put("己午己","比肩");
put("己未乙","七杀");
put("己未己","比肩");
put("己未丁","偏印");
put("己申戊","劫财");
put("己申庚","伤官");
put("己申壬","正财");
put("己酉辛","食神");
put("己戌辛","食神");
put("己戌戊","劫财");
put("己戌丁","偏印");
put("己亥壬","正财");
put("己亥甲","正官");
put("庚子癸","伤官");
put("庚丑癸","伤官");
put("庚丑己","正印");
put("庚丑辛","劫财");
put("庚寅丙","七杀");
put("庚寅甲","偏财");
put("庚寅戊","偏印");
put("庚卯乙","正财");
put("庚辰乙","正财");
put("庚辰戊","偏印");
put("庚辰癸","伤官");
put("庚巳戊","偏印");
put("庚巳丙","七杀");
put("庚巳庚","比肩");
put("庚午丁","正官");
put("庚午己","正印");
put("庚未乙","正财");
put("庚未己","正印");
put("庚未丁","正官");
put("庚申戊","偏印");
put("庚申庚","比肩");
put("庚申壬","食神");
put("庚酉辛","劫财");
put("庚戌辛","劫财");
put("庚戌戊","偏印");
put("庚戌丁","正官");
put("庚亥壬","食神");
put("庚亥甲","偏财");
put("辛子癸","食神");
put("辛丑癸","食神");
put("辛丑己","偏印");
put("辛丑辛","比肩");
put("辛寅丙","正官");
put("辛寅甲","正财");
put("辛寅戊","正印");
put("辛卯乙","偏财");
put("辛辰乙","偏财");
put("辛辰戊","正印");
put("辛辰癸","食神");
put("辛巳戊","正印");
put("辛巳丙","正官");
put("辛巳庚","劫财");
put("辛午丁","七杀");
put("辛午己","偏印");
put("辛未乙","偏财");
put("辛未己","偏印");
put("辛未丁","七杀");
put("辛申戊","正印");
put("辛申庚","劫财");
put("辛申壬","伤官");
put("辛酉辛","比肩");
put("辛戌辛","比肩");
put("辛戌戊","正印");
put("辛戌丁","七杀");
put("辛亥壬","伤官");
put("辛亥甲","正财");
put("壬子癸","劫财");
put("壬丑癸","劫财");
put("壬丑己","正官");
put("壬丑辛","正印");
put("壬寅丙","偏财");
put("壬寅甲","食神");
put("壬寅戊","七杀");
put("壬卯乙","伤官");
put("壬辰乙","伤官");
put("壬辰戊","七杀");
put("壬辰癸","劫财");
put("壬巳戊","七杀");
put("壬巳丙","偏财");
put("壬巳庚","偏印");
put("壬午丁","正财");
put("壬午己","正官");
put("壬未乙","伤官");
put("壬未己","正官");
put("壬未丁","正财");
put("壬申戊","七杀");
put("壬申庚","偏印");
put("壬申壬","比肩");
put("壬酉辛","正印");
put("壬戌辛","正印");
put("壬戌戊","七杀");
put("壬戌丁","正财");
put("壬亥壬","比肩");
put("壬亥甲","食神");
put("癸子癸","比肩");
put("癸丑癸","比肩");
put("癸丑己","七杀");
put("癸丑辛","偏印");
put("癸寅丙","正财");
put("癸寅甲","伤官");
put("癸寅戊","正官");
put("癸卯乙","食神");
put("癸辰乙","食神");
put("癸辰戊","正官");
put("癸辰癸","比肩");
put("癸巳戊","正官");
put("癸巳丙","正财");
put("癸巳庚","正印");
put("癸午丁","偏财");
put("癸午己","七杀");
put("癸未乙","食神");
put("癸未己","七杀");
put("癸未丁","偏财");
put("癸申戊","正官");
put("癸申庚","正印");
put("癸申壬","劫财");
put("癸酉辛","偏印");
put("癸戌辛","偏印");
put("癸戌戊","正官");
put("癸戌丁","偏财");
put("癸亥壬","劫财");
put("癸亥甲","伤官");
put("甲癸","正印");
put("甲己","正财");
put("甲辛","正官");
put("甲丙","食神");
put("甲甲","比肩");
put("甲戊","偏财");
put("甲乙","劫财");
put("甲庚","七杀");
put("甲丁","伤官");
put("甲壬","偏印");
put("乙癸","偏印");
put("乙己","偏财");
put("乙辛","七杀");
put("乙丙","伤官");
put("乙甲","劫财");
put("乙戊","正财");
put("乙乙","比肩");
put("乙庚","正官");
put("乙丁","食神");
put("乙壬","正印");
put("丙癸","正官");
put("丙己","伤官");
put("丙辛","正财");
put("丙丙","比肩");
put("丙甲","偏印");
put("丙戊","食神");
put("丙乙","正印");
put("丙庚","偏财");
put("丙丁","劫财");
put("丙壬","七杀");
put("丁癸","七杀");
put("丁己","食神");
put("丁辛","偏财");
put("丁丙","劫财");
put("丁甲","正印");
put("丁戊","伤官");
put("丁乙","偏印");
put("丁庚","正财");
put("丁丁","比肩");
put("丁壬","正官");
put("戊癸","正财");
put("戊己","劫财");
put("戊辛","伤官");
put("戊丙","偏印");
put("戊甲","七杀");
put("戊戊","比肩");
put("戊乙","正官");
put("戊庚","食神");
put("戊丁","正印");
put("戊壬","偏财");
put("己癸","偏财");
put("己己","比肩");
put("己辛","食神");
put("己丙","正印");
put("己甲","正官");
put("己戊","劫财");
put("己乙","七杀");
put("己庚","伤官");
put("己丁","偏印");
put("己壬","正财");
put("庚癸","伤官");
put("庚己","正印");
put("庚辛","劫财");
put("庚丙","七杀");
put("庚甲","偏财");
put("庚戊","偏印");
put("庚乙","正财");
put("庚庚","比肩");
put("庚丁","正官");
put("庚壬","食神");
put("辛癸","食神");
put("辛己","偏印");
put("辛辛","比肩");
put("辛丙","正官");
put("辛甲","正财");
put("辛戊","正印");
put("辛乙","偏财");
put("辛庚","劫财");
put("辛丁","七杀");
put("辛壬","伤官");
put("壬癸","劫财");
put("壬己","正官");
put("壬辛","正印");
put("壬丙","偏财");
put("壬甲","食神");
put("壬戊","七杀");
put("壬乙","伤官");
put("壬庚","偏印");
put("壬丁","正财");
put("壬壬","比肩");
put("癸癸","比肩");
put("癸己","七杀");
put("癸辛","偏印");
put("癸丙","正财");
put("癸甲","伤官");
put("癸戊","正官");
put("癸乙","食神");
put("癸庚","正印");
put("癸丁","偏财");
put("癸壬","劫财");
}
};
@@ -1118,8 +938,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 +947,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;
}

File diff suppressed because one or more lines are too long

View File

@@ -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, "毛泽东诞辰纪念日"));
}
};
@@ -147,6 +218,9 @@ public class SolarUtil {
* @return true/false 闰年/非闰年
*/
public static boolean isLeapYear(int year) {
if (year < 1600) {
return year % 4 == 0;
}
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}

View File

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

View File

@@ -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:09");
put("小寒","2022-01-05 17:13:54");
put("大寒","2022-01-20 10:38:56");
put("立春","2022-02-04 04:50:36");
put("雨水","2022-02-19 00:42:50");
put("惊蛰","2022-03-05 22:43:34");
put("春分","2022-03-20 23:33:15");
put("清明","2022-04-05 03:20:03");
put("谷雨","2022-04-20 10:24:07");
put("立夏","2022-05-05 20:25:46");
put("小满","2022-05-21 09:22:25");
put("芒种","2022-06-06 00:25:37");
put("夏至","2022-06-21 17:13:40");
put("小暑","2022-07-07 10:37:49");
put("大暑","2022-07-23 04:06:49");
put("立秋","2022-08-07 20:28:57");
put("处暑","2022-08-23 11:15:59");
put("白露","2022-09-07 23:32:07");
put("秋分","2022-09-23 09:03:31");
put("寒露","2022-10-08 15:22:16");
put("霜降","2022-10-23 18:35:31");
put("立冬","2022-11-07 18:45:18");
put("小雪","2022-11-22 16:20:18");
put("大雪","2022-12-07 11:46:04");
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");
}
};
@@ -177,13 +177,13 @@ public class JieQiTest {
@Test
public void test7() {
Lunar lunar = Lunar.fromYmd(2012, 9, 1);
Assert.assertEquals("2012-09-07 13:29:00", lunar.getJieQiTable().get("白露").toYmdHms());
Assert.assertEquals("2012-09-07 13:29:01", lunar.getJieQiTable().get("白露").toYmdHms());
}
@Test
public void test8() {
Lunar lunar = Lunar.fromYmd(2050, 12, 1);
Assert.assertEquals("2050-12-07 06:41:00", lunar.getJieQiTable().get("DA_XUE").toYmdHms());
Assert.assertEquals("2050-12-07 06:41:13", lunar.getJieQiTable().get("DA_XUE").toYmdHms());
}
@Test
@@ -194,4 +194,10 @@ public class JieQiTest {
Assert.assertEquals("冬至", solar.getLunar().getQi());
}
@Test
public void test10() {
Lunar lunar = Solar.fromYmd(2023, 6, 1).getLunar();
Assert.assertEquals("2022-12-22 05:48:11", lunar.getJieQiTable().get("冬至").toYmdHms());
}
}

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

View File

@@ -627,4 +627,22 @@ public class LunarTest {
Assert.assertEquals("1537-02-10", lunar.getSolar().toString());
}
@Test
public void test92() {
Lunar lunar = Solar.fromYmd(917, 12, 1).getLunar();
Assert.assertEquals("九一七年闰十月十四", lunar.toString());
}
@Test
public void test93() {
Lunar lunar = Solar.fromYmd(917, 12, 31).getLunar();
Assert.assertEquals("九一七年冬月十五", lunar.toString());
}
@Test
public void test94() {
Lunar lunar = Solar.fromYmd(918, 1, 1).getLunar();
Assert.assertEquals("九一七年冬月十六", lunar.toString());
}
}

View File

@@ -48,7 +48,7 @@ public class SolarTest {
@Test
public void test10(){
Assert.assertFalse(SolarUtil.isLeapYear(1500));
Assert.assertTrue(SolarUtil.isLeapYear(1500));
}
@Test
@@ -171,4 +171,28 @@ public class SolarTest {
Assert.assertEquals("1582-09-29", solar.next(-6).toYmd());
}
@Test
public void test27(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2023-09-30", solar.nextMonth(1).toYmd());
}
@Test
public void test28(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2023-10-31", solar.nextMonth(2).toYmd());
}
@Test
public void test29(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2025-08-31", solar.nextYear(2).toYmd());
}
@Test
public void test30(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2024-02-29", solar.nextMonth(6).toYmd());
}
}