Skip to content

Commit

Permalink
新增旬、旬空(空亡)。
Browse files Browse the repository at this point in the history
  • Loading branch information
6tail committed Nov 19, 2020
1 parent 72c4d0d commit 135d39b
Show file tree
Hide file tree
Showing 8 changed files with 491 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/main/java/com/nlf/calendar/EightChar.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,67 @@ public Yun getYun(int gender) {
return new Yun(this, gender);
}

/**
* 获取年柱所在旬
* @return 旬
*/
public String getYearXun(){
return lunar.getYearXunExact();
}

/**
* 获取年柱旬空(空亡)
* @return 旬空(空亡)
*/
public String getYearXunKong(){
return lunar.getYearXunKongExact();
}

/**
* 获取月柱所在旬
* @return 旬
*/
public String getMonthXun(){
return lunar.getMonthXunExact();
}

/**
* 获取月柱旬空(空亡)
* @return 旬空(空亡)
*/
public String getMonthXunKong(){
return lunar.getMonthXunKongExact();
}

/**
* 获取日柱所在旬
* @return 旬
*/
public String getDayXun(){
return lunar.getDayXunExact();
}

/**
* 获取日柱旬空(空亡)
* @return 旬空(空亡)
*/
public String getDayXunKong(){
return lunar.getDayXunKongExact();
}

/**
* 获取时柱所在旬
* @return 旬
*/
public String getTimeXun(){
return lunar.getTimeXun();
}

/**
* 获取时柱旬空(空亡)
* @return 旬空(空亡)
*/
public String getTimeXunKong(){
return lunar.getTimeXunKong();
}
}
128 changes: 128 additions & 0 deletions src/main/java/com/nlf/calendar/Lunar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2389,4 +2389,132 @@ public Lunar next(int days){
}
return new Lunar(y,m,d,hour,minute,second);
}

/**
* 获取年所在旬(以正月初一作为新年的开始)
* @return 旬
*/
public String getYearXun(){
return LunarUtil.getXun(getYearInGanZhi());
}

/**
* 获取年所在旬(以立春当天作为新年的开始)
* @return 旬
*/
public String getYearXunByLiChun(){
return LunarUtil.getXun(getYearInGanZhiByLiChun());
}

/**
* 获取年所在旬(以立春交接时刻作为新年的开始)
* @return 旬
*/
public String getYearXunExact(){
return LunarUtil.getXun(getYearInGanZhiExact());
}

/**
* 获取值年空亡(以正月初一作为新年的开始)
* @return 空亡(旬空)
*/
public String getYearXunKong(){
return LunarUtil.getXunKong(getYearInGanZhi());
}

/**
* 获取值年空亡(以立春当天作为新年的开始)
* @return 空亡(旬空)
*/
public String getYearXunKongByLiChun(){
return LunarUtil.getXunKong(getYearInGanZhiByLiChun());
}

/**
* 获取值年空亡(以立春交接时刻作为新年的开始)
* @return 空亡(旬空)
*/
public String getYearXunKongExact(){
return LunarUtil.getXunKong(getYearInGanZhiExact());
}

/**
* 获取月所在旬(以节交接当天起算)
* @return 旬
*/
public String getMonthXun(){
return LunarUtil.getXun(getMonthInGanZhi());
}

/**
* 获取月所在旬(以节交接时刻起算)
* @return 旬
*/
public String getMonthXunExact(){
return LunarUtil.getXun(getMonthInGanZhiExact());
}

/**
* 获取值月空亡(以节交接当天起算)
* @return 空亡(旬空)
*/
public String getMonthXunKong(){
return LunarUtil.getXunKong(getMonthInGanZhi());
}

/**
* 获取值月空亡(以节交接时刻起算)
* @return 空亡(旬空)
*/
public String getMonthXunKongExact(){
return LunarUtil.getXunKong(getMonthInGanZhiExact());
}

/**
* 获取日所在旬(以节交接当天起算)
* @return 旬
*/
public String getDayXun(){
return LunarUtil.getXun(getDayInGanZhi());
}

/**
* 获取日所在旬(晚子时算第二天)
* @return 旬
*/
public String getDayXunExact(){
return LunarUtil.getXun(getDayInGanZhiExact());
}

/**
* 获取值日空亡
* @return 空亡(旬空)
*/
public String getDayXunKong(){
return LunarUtil.getXunKong(getDayInGanZhi());
}

/**
* 获取值日空亡(晚子时算第二天)
* @return 空亡(旬空)
*/
public String getDayXunKongExact(){
return LunarUtil.getXunKong(getDayInGanZhiExact());
}

/**
* 获取时辰所在旬
* @return 旬
*/
public String getTimeXun(){
return LunarUtil.getXun(getTimeInGanZhi());
}

/**
* 获取值时空亡
* @return 空亡(旬空)
*/
public String getTimeXunKong(){
return LunarUtil.getXunKong(getTimeInGanZhi());
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/nlf/calendar/eightchar/DaYun.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ public String getGanZhi() {
return LunarUtil.JIA_ZI[offset];
}

/**
* 获取所在旬
* @return 旬
*/
public String getXun(){
return LunarUtil.getXun(getGanZhi());
}

/**
* 获取旬空(空亡)
* @return 旬空(空亡)
*/
public String getXunKong(){
return LunarUtil.getXunKong(getGanZhi());
}

/**
* 获取流年
*
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/nlf/calendar/eightchar/LiuNian.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ public String getGanZhi() {
return LunarUtil.JIA_ZI[offset];
}

/**
* 获取所在旬
* @return 旬
*/
public String getXun(){
return LunarUtil.getXun(getGanZhi());
}

/**
* 获取旬空(空亡)
* @return 旬空(空亡)
*/
public String getXunKong(){
return LunarUtil.getXunKong(getGanZhi());
}

/**
* 获取流月
* @return 流月
*/
public LiuYue[] getLiuYue() {
int n = 12;
LiuYue[] l = new LiuYue[n];
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/nlf/calendar/eightchar/LiuYue.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,20 @@ public String getGanZhi() {
String zhi = LunarUtil.ZHI[(index + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12 + 1];
return gan + zhi;
}

/**
* 获取所在旬
* @return 旬
*/
public String getXun(){
return LunarUtil.getXun(getGanZhi());
}

/**
* 获取旬空(空亡)
* @return 旬空(空亡)
*/
public String getXunKong(){
return LunarUtil.getXunKong(getGanZhi());
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/nlf/calendar/eightchar/XiaoYun.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,20 @@ public String getGanZhi() {
offset %= size;
return LunarUtil.JIA_ZI[offset];
}

/**
* 获取所在旬
* @return 旬
*/
public String getXun(){
return LunarUtil.getXun(getGanZhi());
}

/**
* 获取旬空(空亡)
* @return 旬空(空亡)
*/
public String getXunKong(){
return LunarUtil.getXunKong(getGanZhi());
}
}
51 changes: 51 additions & 0 deletions src/main/java/com/nlf/calendar/util/LunarUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class LunarUtil{
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 String[] XUN = {"甲子","甲戌","甲申","甲午","甲辰","甲寅"};
/** 旬空 */
public static final String[] XUN_KONG = {"戌亥","申酉","午未","辰巳","寅卯","子丑"};
/** 天干 */
public static final String[] GAN = {"","甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
/** 喜神方位,《喜神方位歌》:甲己在艮乙庚乾,丙辛坤位喜神安.  丁壬只在离宫坐,戊癸原在在巽间。 */
Expand Down Expand Up @@ -1444,4 +1448,51 @@ public static List<String> getTimeJi(String dayGanZhi,String timeGanZhi){
}
return l;
}

/**
* 获取干支所在旬下标,0-5
* @param ganZhi 干支
* @return 旬下标,0-5
*/
protected static int getXunIndex(String ganZhi){
String gan = ganZhi.substring(0,1);
String zhi = ganZhi.substring(1);
int ganIndex = 0;
int zhiIndex = 0;
for(int i=0,j=GAN.length;i<j;i++){
if(GAN[i].equals(gan)){
ganIndex = i;
break;
}
}
for(int i=0,j=ZHI.length;i<j;i++){
if(ZHI[i].equals(zhi)){
zhiIndex = i;
break;
}
}
int diff = ganIndex - zhiIndex;
if(diff<0){
diff += 12;
}
return diff/2;
}

/**
* 获取干支所在旬
* @param ganZhi 干支
* @return 旬
*/
public static String getXun(String ganZhi){
return XUN[getXunIndex(ganZhi)];
}

/**
* 获取干支所在旬对应的旬空(空亡)
* @param ganZhi 干支
* @return 旬空(空亡)
*/
public static String getXunKong(String ganZhi){
return XUN_KONG[getXunIndex(ganZhi)];
}
}
Loading

0 comments on commit 135d39b

Please sign in to comment.