1
0
mirror of synced 2026-10-14 18:46:13 +08:00

v1.2.20 支持获取当年第几周;支持2种流派获取起运。

This commit is contained in:
6tail
2022-03-12 20:05:14 +08:00
parent 1a15531fb4
commit 249aa36176
8 changed files with 148 additions and 26 deletions

View File

@@ -155,7 +155,6 @@ public class SolarWeek {
*
* @return 周序号,从1开始
*/
@SuppressWarnings("MagicConstant")
public int getIndex() {
Calendar c = ExactDate.fromYmd(year, month, 1);
int firstDayWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
@@ -166,6 +165,21 @@ public class SolarWeek {
return (int) Math.ceil((day + offset) / 7D);
}
/**
* 获取当前日期是在当年第几周
*
* @return 周序号,从1开始
*/
public int getIndexInYear() {
Calendar c = ExactDate.fromYmd(year, 1, 1);
int firstDayWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
int offset = firstDayWeek - start;
if(offset < 0) {
offset += 7;
}
return (int) Math.ceil((SolarUtil.getDaysInYear(year, month, day) + offset) / 7D);
}
/**
* 周推移
*
@@ -228,7 +242,6 @@ public class SolarWeek {
*
* @return 本周第一天的阳历日期
*/
@SuppressWarnings("MagicConstant")
public Solar getFirstDay() {
Calendar c = ExactDate.fromYmd(year, month, day);
int week = c.get(Calendar.DAY_OF_WEEK) - 1;
@@ -260,6 +273,7 @@ public class SolarWeek {
*
* @return 本周的阳历日期列表
*/
@SuppressWarnings("all")
public List<Solar> getDays() {
Solar firstDay = getFirstDay();
List<Solar> l = new ArrayList<Solar>();