1
0
mirror of synced 2026-10-24 23:46:11 +08:00

Compare commits

...

3 Commits

Author SHA1 Message Date
6tail
4c39445ada 不建议使用非SNAPSHOT版本 2020-04-08 17:12:00 +08:00
6tail
6a2b395413 增加建除十二神;修复由闰月引起的月干支计算错误的问题。 2020-04-08 16:59:17 +08:00
6tail
bab9d93334 v1.1.0-SNAPSHOT 2020-04-08 11:00:10 +08:00
5 changed files with 54 additions and 21 deletions

View File

@@ -6,15 +6,7 @@ lunar是一款无第三方依赖的日历工具,支持公历和农历、星座
[English](https://github.com/6tail/lunar-java/blob/master/README_EN.md)
### 也许稳定版本
```xml
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.1.0</version>
</dependency>
```
非快照版本存在月干支的重大错误不建议使用,请使用快照版本。
### 快照版本

View File

@@ -6,15 +6,6 @@ lunar is a calendar library for Solar and Chinese Lunar.
[简体中文](https://github.com/6tail/lunar-java/blob/master/README.md)
### Pre Release
```xml
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.1.0</version>
</dependency>
```
### Snapshot

View File

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

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

View File

@@ -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 农历年