增加阳历和农历的其他非正式的节日或纪念日;增加农历干支纪月和纪日;增加农历彭祖百忌。
This commit is contained in:
@@ -71,10 +71,10 @@ If you will use jars in your projects, I suggest you to download latest snapshot
|
||||
Output:
|
||||
|
||||
|
||||
丙申年捌月初八 猴年 北方玄武 斗木獬
|
||||
2016-09-08 闰年 星期四 处女座
|
||||
丙申年捌月初八 猴年丁酉月癸巳日 北方玄武 斗木獬 彭祖[癸不词讼理弱敌强 巳不远行财物伏藏]
|
||||
2016-09-08 闰年 星期四 (世界扫盲日) 处女座
|
||||
|
||||
丙寅年肆月廿一 虎年 北方玄武 危月燕
|
||||
丙寅年肆月廿一 虎年癸巳月癸酉日 北方玄武 危月燕 彭祖[癸不词讼理弱敌强 酉不会客醉坐颠狂]
|
||||
1986-05-29 星期四 双子座
|
||||
|
||||
## Documentation
|
||||
|
||||
@@ -71,10 +71,10 @@ lunar是一个无依赖的支持阳历和阴历的日历工具库。
|
||||
输出结果:
|
||||
|
||||
|
||||
丙申年捌月初八 猴年 北方玄武 斗木獬
|
||||
2016-09-08 闰年 星期四 处女座
|
||||
丙申年捌月初八 猴年丁酉月癸巳日 北方玄武 斗木獬 彭祖[癸不词讼理弱敌强 巳不远行财物伏藏]
|
||||
2016-09-08 闰年 星期四 (世界扫盲日) 处女座
|
||||
|
||||
丙寅年肆月廿一 虎年 北方玄武 危月燕
|
||||
丙寅年肆月廿一 虎年癸巳月癸酉日 北方玄武 危月燕 彭祖[癸不词讼理弱敌强 酉不会客醉坐颠狂]
|
||||
1986-05-29 星期四 双子座
|
||||
|
||||
## 文档
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Lunar{
|
||||
* 通过农历年月日初始化
|
||||
*
|
||||
* @param year 年(农历)
|
||||
* @param month 月(农历),1到12
|
||||
* @param month 月(农历),1到12,闰月为负,即闰2月=-2
|
||||
* @param day 日(农历),1到31
|
||||
*/
|
||||
public Lunar(int year,int month,int day){
|
||||
@@ -110,7 +110,7 @@ public class Lunar{
|
||||
* 通过指定农历年月日获取农历
|
||||
*
|
||||
* @param year 年(农历)
|
||||
* @param month 月(农历),1到12
|
||||
* @param month 月(农历),1到12,闰月为负,即闰2月=-2
|
||||
* @param day 日(农历),1到31
|
||||
* @return 农历
|
||||
*/
|
||||
@@ -119,18 +119,18 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取干
|
||||
* 获取年份的天干
|
||||
*
|
||||
* @return 干,如辛
|
||||
* @return 天干,如辛
|
||||
*/
|
||||
public String getGan(){
|
||||
return LunarUtil.GAN[(year-4)%10+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支
|
||||
* 获取年份的地支
|
||||
*
|
||||
* @return 支,如亥
|
||||
* @return 地支,如亥
|
||||
*/
|
||||
public String getZhi(){
|
||||
return LunarUtil.ZHI[(year-4)%12+1];
|
||||
@@ -279,7 +279,7 @@ public class Lunar{
|
||||
/**
|
||||
* 获取节日,有可能一天会有多个节日
|
||||
*
|
||||
* @return 春节等
|
||||
* @return 节日列表,如春节
|
||||
*/
|
||||
public List<String> getFestivals(){
|
||||
List<String> l = new ArrayList<String>();
|
||||
@@ -290,45 +290,103 @@ public class Lunar{
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取非正式的节日,有可能一天会有多个节日
|
||||
*
|
||||
* @return 非正式的节日列表,如中元节
|
||||
*/
|
||||
public List<String> getOtherFestivals(){
|
||||
List<String> l = new ArrayList<String>();
|
||||
List<String> fs = LunarUtil.OTHER_FESTIVAL.get(month+"-"+day);
|
||||
if(null!=fs){
|
||||
l.addAll(fs);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为阳历日期
|
||||
*
|
||||
* @return 阳历日期
|
||||
*/
|
||||
private Solar toSolar(){
|
||||
int y = LunarUtil.BASE_YEAR;
|
||||
int m = LunarUtil.BASE_MONTH;
|
||||
int d = LunarUtil.BASE_DAY;
|
||||
int diff = LunarUtil.getDaysOfMonth(y,m)-d;
|
||||
m = LunarUtil.nextMonth(y,m);
|
||||
while(true){
|
||||
diff += LunarUtil.getDaysOfMonth(y,m);
|
||||
m = LunarUtil.nextMonth(y,m);
|
||||
if(m==1){
|
||||
y++;
|
||||
}
|
||||
if(y==year&&m==month){
|
||||
diff += day;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int diff = LunarUtil.computeAddDays(year,month,day);
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(SolarUtil.BASE_YEAR,SolarUtil.BASE_MONTH-1,SolarUtil.BASE_DAY);
|
||||
c.add(Calendar.DATE,diff);
|
||||
return new Solar(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取干支纪月
|
||||
* <p>月天干口诀:甲己丙寅首,乙庚戊寅头。丙辛从庚寅,丁壬壬寅求,戊癸甲寅居,周而复始流。</p>
|
||||
* <p>月地支:正月起寅</p>
|
||||
*
|
||||
* @return 干支纪月,如己卯
|
||||
*/
|
||||
public String getMonthInGanZhi(){
|
||||
int m = Math.abs(month)-1;
|
||||
int yearGanIndex = (year-4)%10;
|
||||
int offset = (yearGanIndex%5+1)*2;
|
||||
String monthGan = LunarUtil.GAN[(m+offset)%10+1];
|
||||
String monthZhi = LunarUtil.ZHI[(m+LunarUtil.BASE_MONTH_ZHI_INDEX)%12+1];
|
||||
return monthGan+monthZhi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取干支纪日
|
||||
*
|
||||
* @return 干支纪日,如己卯
|
||||
*/
|
||||
public String getDayInGanZhi(){
|
||||
int diff = LunarUtil.computeAddDays(year,month,day);
|
||||
diff += LunarUtil.BASE_DAY_GANZHI_INDEX;
|
||||
diff = diff%60;
|
||||
return LunarUtil.GAN[diff%10+1]+LunarUtil.ZHI[diff%12+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取彭祖百忌天干
|
||||
* @return 彭祖百忌天干
|
||||
*/
|
||||
public String getPengZuGan(){
|
||||
int diff = LunarUtil.computeAddDays(year,month,day);
|
||||
diff += LunarUtil.BASE_DAY_GANZHI_INDEX;
|
||||
diff = diff%60;
|
||||
return LunarUtil.PENGZU_GAN[diff%10+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取彭祖百忌地支
|
||||
* @return 彭祖百忌地支
|
||||
*/
|
||||
public String getPengZuZhi(){
|
||||
int diff = LunarUtil.computeAddDays(year,month,day);
|
||||
diff += LunarUtil.BASE_DAY_GANZHI_INDEX;
|
||||
diff = diff%60;
|
||||
return LunarUtil.PENGZU_ZHI[diff%12+1];
|
||||
}
|
||||
|
||||
public String toFullString(){
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(toString());
|
||||
s.append(" ");
|
||||
s.append(getShengxiao());
|
||||
s.append("年");
|
||||
s.append(getMonthInGanZhi());
|
||||
s.append("月");
|
||||
s.append(getDayInGanZhi());
|
||||
s.append("日");
|
||||
for(String f:getFestivals()){
|
||||
s.append(" (");
|
||||
s.append(f);
|
||||
s.append(")");
|
||||
}
|
||||
for(String f:getOtherFestivals()){
|
||||
s.append(" (");
|
||||
s.append(f);
|
||||
s.append(")");
|
||||
}
|
||||
String jq = getJie()+getQi();
|
||||
if(jq.length()>0){
|
||||
s.append(" [");
|
||||
@@ -343,6 +401,11 @@ public class Lunar{
|
||||
s.append(getXiu());
|
||||
s.append(getZheng());
|
||||
s.append(getAnimal());
|
||||
s.append(" 彭祖[");
|
||||
s.append(getPengZuGan());
|
||||
s.append(" ");
|
||||
s.append(getPengZuZhi());
|
||||
s.append("]");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -156,6 +156,20 @@ public class Solar{
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取非正式的节日,有可能一天会有多个节日
|
||||
*
|
||||
* @return 非正式的节日列表,如中元节
|
||||
*/
|
||||
public List<String> getOtherFestivals(){
|
||||
List<String> l = new ArrayList<String>();
|
||||
List<String> fs = SolarUtil.OTHER_FESTIVAL.get(month+"-"+day);
|
||||
if(null!=fs){
|
||||
l.addAll(fs);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取星座
|
||||
*
|
||||
@@ -254,6 +268,11 @@ public class Solar{
|
||||
s.append(f);
|
||||
s.append(")");
|
||||
}
|
||||
for(String f:getOtherFestivals()){
|
||||
s.append(" (");
|
||||
s.append(f);
|
||||
s.append(")");
|
||||
}
|
||||
s.append(" ");
|
||||
s.append(getXingzuo());
|
||||
s.append("座");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.nlf.calendar.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 农历工具,基准日期为1900年十一月十一,对应阳历1901年1月1日,最远仅支持到2099年
|
||||
@@ -18,16 +17,26 @@ public class LunarUtil{
|
||||
public static final int BASE_DAY = 11;
|
||||
/** 农历与阳历年偏移量 */
|
||||
public static final int BASE_INDEX = 0;
|
||||
/** 基准对应的干支偏移量 */
|
||||
public static final int BASE_DAY_GANZHI_INDEX = 15;
|
||||
/** 月份地支偏移量,因正月起寅 */
|
||||
public static final int BASE_MONTH_ZHI_INDEX = 2;
|
||||
/** 闰年表 */
|
||||
public static final int[] LEAP_MONTH_YEAR = {6,14,19,25,33,36,38,41,44,52,55,79,117,136,147,150,155,158,185,193};
|
||||
/** 闰月表 */
|
||||
public static final int[] LUNAR_MONTH = {0x00,0x04,0xad,0x08,0x5a,0x01,0xd5,0x54,0xb4,0x09,0x64,0x05,0x59,0x45,0x95,0x0a,0xa6,0x04,0x55,0x24,0xad,0x08,0x5a,0x62,0xda,0x04,0xb4,0x05,0xb4,0x55,0x52,0x0d,0x94,0x0a,0x4a,0x2a,0x56,0x02,0x6d,0x71,0x6d,0x01,0xda,0x02,0xd2,0x52,0xa9,0x05,0x49,0x0d,0x2a,0x45,0x2b,0x09,0x56,0x01,0xb5,0x20,0x6d,0x01,0x59,0x69,0xd4,0x0a,0xa8,0x05,0xa9,0x56,0xa5,0x04,0x2b,0x09,0x9e,0x38,0xb6,0x08,0xec,0x74,0x6c,0x05,0xd4,0x0a,0xe4,0x6a,0x52,0x05,0x95,0x0a,0x5a,0x42,0x5b,0x04,0xb6,0x04,0xb4,0x22,0x6a,0x05,0x52,0x75,0xc9,0x0a,0x52,0x05,0x35,0x55,0x4d,0x0a,0x5a,0x02,0x5d,0x31,0xb5,0x02,0x6a,0x8a,0x68,0x05,0xa9,0x0a,0x8a,0x6a,0x2a,0x05,0x2d,0x09,0xaa,0x48,0x5a,0x01,0xb5,0x09,0xb0,0x39,0x64,0x05,0x25,0x75,0x95,0x0a,0x96,0x04,0x4d,0x54,0xad,0x04,0xda,0x04,0xd4,0x44,0xb4,0x05,0x54,0x85,0x52,0x0d,0x92,0x0a,0x56,0x6a,0x56,0x02,0x6d,0x02,0x6a,0x41,0xda,0x02,0xb2,0xa1,0xa9,0x05,0x49,0x0d,0x0a,0x6d,0x2a,0x09,0x56,0x01,0xad,0x50,0x6d,0x01,0xd9,0x02,0xd1,0x3a,0xa8,0x05,0x29,0x85,0xa5,0x0c,0x2a,0x09,0x96,0x54,0xb6,0x08,0x6c,0x09,0x64,0x45,0xd4,0x0a,0xa4,0x05,0x51,0x25,0x95,0x0a,0x2a,0x72,0x5b,0x04,0xb6,0x04,0xac,0x52,0x6a,0x05,0xd2,0x0a,0xa2,0x4a,0x4a,0x05,0x55,0x94,0x2d,0x0a,0x5a,0x02,0x75,0x61,0xb5,0x02,0x6a,0x03,0x61,0x45,0xa9,0x0a,0x4a,0x05,0x25,0x25,0x2d,0x09,0x9a,0x68,0xda,0x08,0xb4,0x09,0xa8,0x59,0x54,0x03,0xa5,0x0a,0x91,0x3a,0x96,0x04,0xad,0xb0,0xad,0x04,0xda,0x04,0xf4,0x62,0xb4,0x05,0x54,0x0b,0x44,0x5d,0x52,0x0a,0x95,0x04,0x55,0x22,0x6d,0x02,0x5a,0x71,0xda,0x02,0xaa,0x05,0xb2,0x55,0x49,0x0b,0x4a,0x0a,0x2d,0x39,0x36,0x01,0x6d,0x80,0x6d,0x01,0xd9,0x02,0xe9,0x6a,0xa8,0x05,0x29,0x0b,0x9a,0x4c,0xaa,0x08,0xb6,0x08,0xb4,0x38,0x6c,0x09,0x54,0x75,0xd4,0x0a,0xa4,0x05,0x45,0x55,0x95,0x0a,0x9a,0x04,0x55,0x44,0xb5,0x04,0x6a,0x82,0x6a,0x05,0xd2,0x0a,0x92,0x6a,0x4a,0x05,0x55,0x0a,0x2a,0x4a,0x5a,0x02,0xb5,0x02,0xb2,0x31,0x69,0x03,0x31,0x73,0xa9,0x0a,0x4a,0x05,0x2d,0x55,0x2d,0x09,0x5a,0x01,0xd5,0x48,0xb4,0x09,0x68,0x89,0x54,0x0b,0xa4,0x0a,0xa5,0x6a,0x95,0x04,0xad,0x08,0x6a,0x44,0xda,0x04,0x74,0x05,0xb0,0x25,0x54,0x03};
|
||||
public static final int[][] JIE_YEAR = {{13,49,85,117,149,185,201,250,250},{13,45,81,117,149,185,201,250,250},{13,48,84,112,148,184,200,201,250},{13,45,76,108,140,172,200,201,250},{13,44,72,104,132,168,200,201,250},{5,33,68,96,124,152,188,200,201},{29,57,85,120,148,176,200,201,250},{13,48,76,104,132,168,196,200,201},{25,60,88,120,148,184,200,201,250},{16,44,76,108,144,172,200,201,250},{28,60,92,124,160,192,200,201,250},{17,53,85,124,156,188,200,201,250}};
|
||||
public static final int[][] JIE_MAP = {{7,6,6,6,6,6,6,6,6,5,6,6,6,5,5,6,6,5,5,5,5,5,5,5,5,4,5,5},{5,4,5,5,5,4,4,5,5,4,4,4,4,4,4,4,4,3,4,4,4,3,3,4,4,3,3,3},{6,6,6,7,6,6,6,6,5,6,6,6,5,5,6,6,5,5,5,6,5,5,5,5,4,5,5,5,5},{5,5,6,6,5,5,5,6,5,5,5,5,4,5,5,5,4,4,5,5,4,4,4,5,4,4,4,4,5},{6,6,6,7,6,6,6,6,5,6,6,6,5,5,6,6,5,5,5,6,5,5,5,5,4,5,5,5,5},{6,6,7,7,6,6,6,7,6,6,6,6,5,6,6,6,5,5,6,6,5,5,5,6,5,5,5,5,4,5,5,5,5},{7,8,8,8,7,7,8,8,7,7,7,8,7,7,7,7,6,7,7,7,6,6,7,7,6,6,6,7,7},{8,8,8,9,8,8,8,8,7,8,8,8,7,7,8,8,7,7,7,8,7,7,7,7,6,7,7,7,6,6,7,7,7},{8,8,8,9,8,8,8,8,7,8,8,8,7,7,8,8,7,7,7,8,7,7,7,7,6,7,7,7,7},{9,9,9,9,8,9,9,9,8,8,9,9,8,8,8,9,8,8,8,8,7,8,8,8,7,7,8,8,8},{8,8,8,8,7,8,8,8,7,7,8,8,7,7,7,8,7,7,7,7,6,7,7,7,6,6,7,7,7},{7,8,8,8,7,7,8,8,7,7,7,8,7,7,7,7,6,7,7,7,6,6,7,7,6,6,6,7,7}};
|
||||
public static final int[][] QI_YEAR = {{13,45,81,113,149,185,201},{21,57,93,125,161,193,201},{21,56,88,120,152,188,200,201},{21,49,81,116,144,176,200,201},{17,49,77,112,140,168,200,201},{28,60,88,116,148,180,200,201},{25,53,84,112,144,172,200,201},{29,57,89,120,148,180,200,201},{17,45,73,108,140,168,200,201},{28,60,92,124,160,192,200,201},{16,44,80,112,148,180,200,201},{17,53,88,120,156,188,200,201}};
|
||||
public static final int[][] QI_MAP = {{21,21,21,21,21,20,21,21,21,20,20,21,21,20,20,20,20,20,20,20,20,19,20,20,20,19,19,20},{20,19,19,20,20,19,19,19,19,19,19,19,19,18,19,19,19,18,18,19,19,18,18,18,18,18,18,18},{21,21,21,22,21,21,21,21,20,21,21,21,20,20,21,21,20,20,20,21,20,20,20,20,19,20,20,20,20},{20,21,21,21,20,20,21,21,20,20,20,21,20,20,20,20,19,20,20,20,19,19,20,20,19,19,19,20,20},{21,22,22,22,21,21,22,22,21,21,21,22,21,21,21,21,20,21,21,21,20,20,21,21,20,20,20,21,21},{22,22,22,22,21,22,22,22,21,21,22,22,21,21,21,22,21,21,21,21,20,21,21,21,20,20,21,21,21},{23,23,24,24,23,23,23,24,23,23,23,23,22,23,23,23,22,22,23,23,22,22,22,23,22,22,22,22,23},{23,24,24,24,23,23,24,24,23,23,23,24,23,23,23,23,22,23,23,23,22,22,23,23,22,22,22,23,23},{23,24,24,24,23,23,24,24,23,23,23,24,23,23,23,23,22,23,23,23,22,22,23,23,22,22,22,23,23},{24,24,24,24,23,24,24,24,23,23,24,24,23,23,23,24,23,23,23,23,22,23,23,23,22,22,23,23,23},{23,23,23,23,22,23,23,23,22,22,23,23,22,22,22,23,22,22,22,22,21,22,22,22,21,21,22,22,22},{22,22,23,23,22,22,22,23,22,22,22,22,21,22,22,22,21,21,22,22,21,21,21,22,21,21,21,21,22}};
|
||||
/** 干 */
|
||||
/** 天干 */
|
||||
public static final String[] GAN = {"","甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
|
||||
/** 支 */
|
||||
/** 地支 */
|
||||
public static final String[] ZHI = {"","子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};
|
||||
/** 彭祖百忌.天干 */
|
||||
public static final String[] PENGZU_GAN = {"","甲不开仓财物耗散","乙不栽植千株不长","丙不修灶必见灾殃","丁不剃头头必生疮","戊不受田田主不祥","己不破券二比并亡","庚不经络织机虚张","辛不合酱主人不尝","壬不泱水更难提防","癸不词讼理弱敌强"};
|
||||
/** 彭祖百忌.地支 */
|
||||
public static final String[] PENGZU_ZHI = {"","子不问卜自惹祸殃","丑不冠带主不还乡","寅不祭祀神鬼不尝","卯不穿井水泉不香","辰不哭泣必主重丧","巳不远行财物伏藏","午不苫盖屋主更张","未不服药毒气入肠","申不安床鬼祟入房","酉不会客醉坐颠狂","戌不吃犬作怪上床","亥不嫁娶不利新郎"};
|
||||
/** 月 */
|
||||
public static final String[] MONTH = {"","正","贰","叁","肆","伍","陆","柒","捌","玖","拾","冬","腊"};
|
||||
/** 季节 */
|
||||
@@ -52,6 +61,96 @@ public class LunarUtil{
|
||||
put("8-15","中秋节");
|
||||
put("9-9","重阳节");
|
||||
put("12-8","腊八节");
|
||||
put("12-30","除夕");
|
||||
}
|
||||
};
|
||||
/** 农历日期对应的非正式节日 */
|
||||
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-8",Collections.nCopies(1,"五殿阎罗天子诞"));
|
||||
put("1-9",Collections.nCopies(1,"玉皇上帝诞"));
|
||||
put("2-1",Collections.nCopies(1,"一殿秦广王诞"));
|
||||
put("2-2",Collections.nCopies(1,"福德土地正神诞"));
|
||||
put("2-3",Collections.nCopies(1,"文昌帝君诞"));
|
||||
put("2-6",Collections.nCopies(1,"东华帝君诞"));
|
||||
put("2-8",Collections.nCopies(1,"释迦牟尼佛出家"));
|
||||
put("2-15",Collections.nCopies(1,"释迦牟尼佛般涅槃"));
|
||||
put("2-17",Collections.nCopies(1,"东方杜将军诞"));
|
||||
put("2-18",Collections.nCopies(1,"至圣先师孔子讳辰"));
|
||||
put("2-19",Collections.nCopies(1,"观音大士诞"));
|
||||
put("2-21",Collections.nCopies(1,"普贤菩萨诞"));
|
||||
put("3-1",Collections.nCopies(1,"二殿楚江王诞"));
|
||||
put("3-3",Collections.nCopies(1,"玄天上帝诞"));
|
||||
put("3-8",Collections.nCopies(1,"六殿卞城王诞"));
|
||||
put("3-15",Collections.nCopies(1,"昊天上帝诞"));
|
||||
put("3-16",Collections.nCopies(1,"准提菩萨诞"));
|
||||
put("3-19",Collections.nCopies(1,"中岳大帝诞"));
|
||||
put("3-20",Collections.nCopies(1,"子孙娘娘诞"));
|
||||
put("3-27",Collections.nCopies(1,"七殿泰山王诞"));
|
||||
put("3-28",Collections.nCopies(1,"苍颉至圣先师诞"));
|
||||
put("4-1",Collections.nCopies(1,"八殿都市王诞"));
|
||||
put("4-4",Collections.nCopies(1,"文殊菩萨诞"));
|
||||
put("4-8",Collections.nCopies(1,"释迦牟尼佛诞"));
|
||||
put("4-14",Collections.nCopies(1,"纯阳祖师诞"));
|
||||
put("4-15",Collections.nCopies(1,"钟离祖师诞"));
|
||||
put("4-17",Collections.nCopies(1,"十殿转轮王诞"));
|
||||
put("4-18",Collections.nCopies(1,"紫徽大帝诞"));
|
||||
put("4-20",Collections.nCopies(1,"眼光圣母诞"));
|
||||
put("5-1",Collections.nCopies(1,"南极长生大帝诞"));
|
||||
put("5-8",Collections.nCopies(1,"南方五道诞"));
|
||||
put("5-11",Collections.nCopies(1,"天下都城隍诞"));
|
||||
put("5-12",Collections.nCopies(1,"炳灵公诞"));
|
||||
put("5-13",Collections.nCopies(1,"关圣降"));
|
||||
put("5-16",Collections.nCopies(1,"天地元气造化万物之辰"));
|
||||
put("5-18",Collections.nCopies(1,"张天师诞"));
|
||||
put("5-22",Collections.nCopies(1,"孝娥神诞"));
|
||||
put("6-19",Collections.nCopies(1,"观世音菩萨成道日"));
|
||||
put("6-24",Collections.nCopies(1,"关帝诞"));
|
||||
put("7-7",Collections.nCopies(1,"魁星诞"));
|
||||
put("7-13",Arrays.asList("长真谭真人诞","大势至菩萨诞"));
|
||||
put("7-15",Collections.nCopies(1,"中元节"));
|
||||
put("7-18",Collections.nCopies(1,"西王母诞"));
|
||||
put("7-19",Collections.nCopies(1,"太岁诞"));
|
||||
put("7-22",Collections.nCopies(1,"增福财神诞"));
|
||||
put("7-29",Collections.nCopies(1,"杨公忌"));
|
||||
put("7-30",Collections.nCopies(1,"地藏菩萨诞"));
|
||||
put("8-1",Collections.nCopies(1,"许真君诞"));
|
||||
put("8-3",Collections.nCopies(1,"司命灶君诞"));
|
||||
put("8-5",Collections.nCopies(1,"雷声大帝诞"));
|
||||
put("8-10",Collections.nCopies(1,"北斗大帝诞"));
|
||||
put("8-12",Collections.nCopies(1,"西方五道诞"));
|
||||
put("8-16",Collections.nCopies(1,"天曹掠刷真君降"));
|
||||
put("8-18",Collections.nCopies(1,"天人兴福之辰"));
|
||||
put("8-23",Collections.nCopies(1,"汉恒候张显王诞"));
|
||||
put("8-24",Collections.nCopies(1,"灶君夫人诞"));
|
||||
put("8-29",Collections.nCopies(1,"至圣先师孔子诞"));
|
||||
put("9-1",Collections.nCopies(1,"北斗九星降世"));
|
||||
put("9-3",Collections.nCopies(1,"五瘟神诞"));
|
||||
put("9-9",Collections.nCopies(1,"酆都大帝诞"));
|
||||
put("9-13",Collections.nCopies(1,"孟婆尊神诞"));
|
||||
put("9-17",Collections.nCopies(1,"金龙四大王诞"));
|
||||
put("9-19",Collections.nCopies(1,"观世音菩萨出家"));
|
||||
put("9-30",Collections.nCopies(1,"药师琉璃光佛诞"));
|
||||
put("10-1",Collections.nCopies(1,"寒衣节"));
|
||||
put("10-3",Collections.nCopies(1,"三茅诞"));
|
||||
put("10-5",Collections.nCopies(1,"达摩祖师诞"));
|
||||
put("10-8",Collections.nCopies(1,"佛涅槃日"));
|
||||
put("10-15",Collections.nCopies(1,"下元节"));
|
||||
put("11-4",Collections.nCopies(1,"至圣先师孔子诞"));
|
||||
put("11-6",Collections.nCopies(1,"西岳大帝诞"));
|
||||
put("11-11",Collections.nCopies(1,"太乙救苦天尊诞"));
|
||||
put("11-17",Collections.nCopies(1,"阿弥陀佛诞"));
|
||||
put("11-19",Collections.nCopies(1,"太阳日宫诞"));
|
||||
put("11-23",Collections.nCopies(1,"张仙诞"));
|
||||
put("11-26",Collections.nCopies(1,"北方五道诞"));
|
||||
put("12-8",Collections.nCopies(1,"释迦如来成佛之辰"));
|
||||
put("12-16",Collections.nCopies(1,"南岳大帝诞"));
|
||||
put("12-21",Collections.nCopies(1,"天猷上帝诞"));
|
||||
put("12-23",Collections.nCopies(1,"小年"));
|
||||
put("12-24",Collections.nCopies(1,"子时灶君上天朝玉帝"));
|
||||
put("12-29",Collections.nCopies(1,"华严菩萨诞"));
|
||||
}
|
||||
};
|
||||
/** 宿 */
|
||||
@@ -202,6 +301,32 @@ public class LunarUtil{
|
||||
|
||||
protected LunarUtil(){}
|
||||
|
||||
/**
|
||||
* 计算指定日期距离基准日期的天数
|
||||
* @param year 农历年
|
||||
* @param month 农历月
|
||||
* @param day 农历日
|
||||
* @return 距离天数
|
||||
*/
|
||||
public static int computeAddDays(int year,int month,int day){
|
||||
int y = BASE_YEAR;
|
||||
int m = BASE_MONTH;
|
||||
int diff = getDaysOfMonth(y,m)-BASE_DAY;
|
||||
m = nextMonth(y,m);
|
||||
while(true){
|
||||
diff += getDaysOfMonth(y,m);
|
||||
m = nextMonth(y,m);
|
||||
if(m==1){
|
||||
y++;
|
||||
}
|
||||
if(y==year&&m==month){
|
||||
diff += day;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定年月的下一个月是第几月
|
||||
* @param y 农历年
|
||||
@@ -211,8 +336,8 @@ public class LunarUtil{
|
||||
public static int nextMonth(int y,int m){
|
||||
int n = Math.abs(m)+1;
|
||||
if(m>0){
|
||||
int index = y-LunarUtil.BASE_YEAR+LunarUtil.BASE_INDEX;
|
||||
int v = LunarUtil.LUNAR_MONTH[2*index+1];
|
||||
int index = y-BASE_YEAR+BASE_INDEX;
|
||||
int v = LUNAR_MONTH[2*index+1];
|
||||
v = (v>>4)&0x0F;
|
||||
if(v==m){
|
||||
n = -m;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.nlf.calendar.util;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 阳历工具,基准日期为1901年1月1日,对应农历1900年十一月十一
|
||||
@@ -52,6 +50,77 @@ public class SolarUtil{
|
||||
put("11-4-4","感恩节");
|
||||
}
|
||||
};
|
||||
/** 日期对应的非正式节日 */
|
||||
public static final Map<String,List<String>> OTHER_FESTIVAL = new HashMap<String,List<String>>(){
|
||||
private static final long serialVersionUID = -1;
|
||||
{
|
||||
put("1-8",Collections.nCopies(1,"周恩来逝世纪念日"));
|
||||
put("1-10",Collections.nCopies(1,"中国公安110宣传日"));
|
||||
put("1-21",Collections.nCopies(1,"列宁逝世纪念日"));
|
||||
put("1-26",Collections.nCopies(1,"国际海关日"));
|
||||
put("2-2",Collections.nCopies(1,"世界湿地日"));
|
||||
put("2-4",Collections.nCopies(1,"世界抗癌日"));
|
||||
put("2-7",Collections.nCopies(1,"京汉铁路罢工纪念"));
|
||||
put("2-10",Collections.nCopies(1,"国际气象节"));
|
||||
put("2-19",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-5",Arrays.asList("周恩来诞辰纪念日","中国青年志愿者服务日"));
|
||||
put("3-6",Collections.nCopies(1,"世界青光眼日"));
|
||||
put("3-12",Collections.nCopies(1,"孙中山逝世纪念日"));
|
||||
put("3-14",Collections.nCopies(1,"马克思逝世纪念日"));
|
||||
put("3-17",Collections.nCopies(1,"国际航海日"));
|
||||
put("3-18",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("4-7",Collections.nCopies(1,"世界卫生日"));
|
||||
put("4-22",Collections.nCopies(1,"列宁诞辰纪念日"));
|
||||
put("4-23",Collections.nCopies(1,"世界图书和版权日"));
|
||||
put("4-26",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-23",Collections.nCopies(1,"世界读书日"));
|
||||
put("5-27",Collections.nCopies(1,"上海解放日"));
|
||||
put("5-31",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("7-1",Collections.nCopies(1,"香港回归纪念日"));
|
||||
put("7-7",Collections.nCopies(1,"中国人民抗日战争纪念日"));
|
||||
put("7-11",Collections.nCopies(1,"世界人口日"));
|
||||
put("8-5",Collections.nCopies(1,"恩格斯逝世纪念日"));
|
||||
put("8-6",Collections.nCopies(1,"国际电影节"));
|
||||
put("8-12",Collections.nCopies(1,"国际青年日"));
|
||||
put("8-22",Collections.nCopies(1,"邓小平诞辰纪念日"));
|
||||
put("9-3",Collections.nCopies(1,"中国抗日战争胜利纪念日"));
|
||||
put("9-8",Collections.nCopies(1,"世界扫盲日"));
|
||||
put("9-9",Collections.nCopies(1,"毛泽东逝世纪念日"));
|
||||
put("9-14",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("10-4",Collections.nCopies(1,"世界动物日"));
|
||||
put("10-10",Collections.nCopies(1,"辛亥革命纪念日"));
|
||||
put("10-13",Collections.nCopies(1,"中国少年先锋队诞辰日"));
|
||||
put("10-25",Collections.nCopies(1,"抗美援朝纪念日"));
|
||||
put("11-12",Collections.nCopies(1,"孙中山诞辰纪念日"));
|
||||
put("11-28",Collections.nCopies(1,"恩格斯诞辰纪念日"));
|
||||
put("12-1",Collections.nCopies(1,"世界艾滋病日"));
|
||||
put("12-12",Collections.nCopies(1,"西安事变纪念日"));
|
||||
put("12-13",Collections.nCopies(1,"南京大屠杀纪念日"));
|
||||
put("12-26",Collections.nCopies(1,"毛泽东诞辰纪念日"));
|
||||
}
|
||||
};
|
||||
|
||||
protected SolarUtil(){}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public class SolarTest {
|
||||
System.out.println(date.getLunar().toFullString());
|
||||
System.out.println();
|
||||
//指定某个阳历日期
|
||||
date = new Solar(1986,5,29);
|
||||
date = new Solar(2016,9,8);
|
||||
System.out.println(date.toFullString());
|
||||
System.out.println(date.getLunar().toFullString());
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class LunarTest {
|
||||
public void test(){
|
||||
Lunar date = new Lunar(2019,3,27);
|
||||
Assert.assertEquals("己亥年叁月廿七",date.toString());
|
||||
Assert.assertEquals("己亥年叁月廿七 猪年 西方白虎 娄金狗",date.toFullString());
|
||||
Assert.assertEquals("己亥年叁月廿七 猪年戊辰月戊戌日 (七殿泰山王诞) 西方白虎 娄金狗 彭祖[戊不受田田主不祥 戌不吃犬作怪上床]",date.toFullString());
|
||||
Assert.assertEquals("2019-05-01",date.getSolar().toString());
|
||||
Assert.assertEquals("2019-05-01 星期三 (劳动节) 金牛座",date.getSolar().toFullString());
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SolarTest {
|
||||
Assert.assertEquals("2019-05-01",date.toString());
|
||||
Assert.assertEquals("2019-05-01 星期三 (劳动节) 金牛座",date.toFullString());
|
||||
Assert.assertEquals("己亥年叁月廿七",date.getLunar().toString());
|
||||
Assert.assertEquals("己亥年叁月廿七 猪年 西方白虎 娄金狗",date.getLunar().toFullString());
|
||||
Assert.assertEquals("己亥年叁月廿七 猪年戊辰月戊戌日 (七殿泰山王诞) 西方白虎 娄金狗 彭祖[戊不受田田主不祥 戌不吃犬作怪上床]",date.getLunar().toFullString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user