Skip to content

Commit 7dba2ae

Browse files
author
lucaijun
committed
AJ-447: support negative number build month
1 parent 53f630b commit 7dba2ae

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/com/xxdb/data/Utils.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,22 @@ public static int countMonths(int days){
7272
return year * 12 + month -1;
7373
}
7474

75-
75+
7676
public static YearMonth parseMonth(int value){
77-
return YearMonth.of(value/12, value % 12 +1);
77+
int year = value / 12;
78+
int month = value % 12 + 1;
79+
if (value < 0){
80+
Calendar c = Calendar.getInstance();
81+
int curYear = c.get(Calendar.YEAR);
82+
int curMonth = c.get(Calendar.MONTH) + 1;
83+
month = curMonth - Math.abs(month);
84+
year = curYear - (Math.abs(year % curYear));
85+
if (month <= 0 ){
86+
month = 12 - Math.abs(month);
87+
year--;
88+
}
89+
}
90+
return YearMonth.of(year, month);
7891
}
7992

8093
public static int countDays(LocalDate date){

0 commit comments

Comments
 (0)