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

v1.2.27 修复立春比春节早时年九星的错误;新增阳历月中获取周。

This commit is contained in:
6tail
2022-11-25 20:58:49 +08:00
parent 51afe36b4b
commit 12a8eec123
9 changed files with 79 additions and 23 deletions

View File

@@ -2049,13 +2049,16 @@ public class Lunar {
}
protected NineStar getYearNineStar(String yearInGanZhi) {
int index = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
int yearOffset = 0;
if (index != LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1) {
yearOffset = -1;
int indexExact = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
int index = LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1;
int yearOffset = indexExact - index;
if (yearOffset > 1) {
yearOffset -= 60;
} else if (yearOffset < -1) {
yearOffset += 60;
}
int yuan = ((this.year + yearOffset + 2696) / 60) % 3;
int offset = (62 + yuan * 3 - index) % 9;
int offset = (62 + yuan * 3 - indexExact) % 9;
if (0 == offset) {
offset = 9;
}

View File

@@ -122,6 +122,26 @@ public class SolarMonth {
return l;
}
/**
* 获取本月的阳历周列表
* @param start 星期几作为一周的开始,1234560分别代表星期一至星期天
* @return 周列表
*/
public List<SolarWeek> getWeeks(int start) {
List<SolarWeek> l = new ArrayList<SolarWeek>();
SolarWeek week = SolarWeek.fromYmd(year, month, 1, start);
Solar firstDay = week.getFirstDay();
while (true) {
l.add(week);
week = week.next(1, false);
firstDay = week.getFirstDay();
if (firstDay.getYear() > year || firstDay.getMonth() > month) {
break;
}
}
return l;
}
/**
* 获取往后推几个月的阳历月,如果要往前推,则月数用负数
*