增加建除十二神;修复由闰月引起的月干支计算错误的问题。
This commit is contained in:
@@ -553,7 +553,11 @@ public class Lunar{
|
||||
* @return 月天干,如己
|
||||
*/
|
||||
public String getMonthGan(){
|
||||
int m = Math.abs(month)-1;
|
||||
int m = Math.abs(month);
|
||||
int leapMonth = LunarUtil.getLeapMonth(year);
|
||||
if(0==leapMonth||m<leapMonth||month==leapMonth){
|
||||
m-=1;
|
||||
}
|
||||
int yearGanIndex = (year-4)%10;
|
||||
int offset = (yearGanIndex%5+1)*2;
|
||||
return LunarUtil.GAN[(m+offset)%10+1];
|
||||
@@ -564,7 +568,11 @@ public class Lunar{
|
||||
* @return 月地支,如卯
|
||||
*/
|
||||
public String getMonthZhi(){
|
||||
int m = Math.abs(month)-1;
|
||||
int m = Math.abs(month);
|
||||
int leapMonth = LunarUtil.getLeapMonth(year);
|
||||
if(0==leapMonth||m<leapMonth||month==leapMonth){
|
||||
m-=1;
|
||||
}
|
||||
return LunarUtil.ZHI[(m+LunarUtil.BASE_MONTH_ZHI_INDEX)%12+1];
|
||||
}
|
||||
|
||||
@@ -871,6 +879,34 @@ public class Lunar{
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取建除十二神,当月支与日支相同即为建,依次类推
|
||||
* @return 十二神
|
||||
*/
|
||||
public String getShiErShen(){
|
||||
String monthZhi = getMonthZhi();
|
||||
String dayZhi = getDayZhi();
|
||||
int indexMonthZhi = 0;
|
||||
int indexDayZhi = 0;
|
||||
for(int i=0,j=LunarUtil.ZHI.length;i<j;i++){
|
||||
String zhi = LunarUtil.ZHI[i];
|
||||
if(zhi.equals(monthZhi)){
|
||||
indexMonthZhi = i;
|
||||
}
|
||||
if(zhi.equals(dayZhi)){
|
||||
indexDayZhi = i;
|
||||
}
|
||||
if(indexMonthZhi>0&&indexDayZhi>0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
int add = indexDayZhi-indexMonthZhi;
|
||||
if(add<0){
|
||||
add = 12+add;
|
||||
}
|
||||
return LunarUtil.SHI_ER_SHEN[1+add];
|
||||
}
|
||||
|
||||
public String toFullString(){
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(toString());
|
||||
|
||||
@@ -47,6 +47,8 @@ public class LunarUtil{
|
||||
public static final String[] POSITION_CAI = {"","艮","艮","坤","坤","坎","坎","震","震","离","离"};
|
||||
/** 地支 */
|
||||
public static final String[] ZHI = {"","子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};
|
||||
/** 建除十二神 */
|
||||
public static final String[] SHI_ER_SHEN = {"","建","除","满","平","定","执","破","危","成","收","开","闭"};
|
||||
/** 彭祖百忌.天干 */
|
||||
public static final String[] PENGZU_GAN = {"","甲不开仓财物耗散","乙不栽植千株不长","丙不修灶必见灾殃","丁不剃头头必生疮","戊不受田田主不祥","己不破券二比并亡","庚不经络织机虚张","辛不合酱主人不尝","壬不泱水更难提防","癸不词讼理弱敌强"};
|
||||
/** 彭祖百忌.地支 */
|
||||
@@ -1095,6 +1097,18 @@ public class LunarUtil{
|
||||
return diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定年份的闰月
|
||||
* @param year 年份
|
||||
* @return 闰月数字,1代表闰1月,0代表无闰月
|
||||
*/
|
||||
public static int getLeapMonth(int year){
|
||||
int index = year-BASE_YEAR+BASE_INDEX;
|
||||
int v = LUNAR_MONTH[2*index+1];
|
||||
v = (v>>4)&0x0F;
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定年月的下一个月是第几月
|
||||
* @param y 农历年
|
||||
|
||||
Reference in New Issue
Block a user