Skip to content

Commit 54da2cc

Browse files
author
lucaijun
committed
AJ-447: fix negative number build month
1 parent 8804cb8 commit 54da2cc

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/com/xxdb/data/Utils.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
import java.nio.ByteBuffer;
44
import java.nio.ByteOrder;
5-
import java.text.DecimalFormat;
6-
import java.text.NumberFormat;
7-
import java.time.LocalDate;
8-
import java.time.LocalDateTime;
9-
import java.time.LocalTime;
10-
import java.time.YearMonth;
5+
import java.time.*;
116
import java.util.ArrayList;
127
import java.util.Calendar;
138
import java.util.HashMap;
@@ -74,20 +69,10 @@ public static int countMonths(int days){
7469

7570

7671
public static YearMonth parseMonth(int value){
77-
int year = value / 12;
78-
int month = value % 12 + 1;
7972
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-
}
73+
throw new DateTimeException(String.format("number %d is invalid, it must be non-negative integer",value));
8974
}
90-
return YearMonth.of(year, month);
75+
return YearMonth.of(value/12, value % 12 + 1);
9176
}
9277

9378
public static int countDays(LocalDate date){

0 commit comments

Comments
 (0)