|
2 | 2 |
|
3 | 3 | import java.nio.ByteBuffer; |
4 | 4 | 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.*; |
11 | 6 | import java.util.ArrayList; |
12 | 7 | import java.util.Calendar; |
13 | 8 | import java.util.HashMap; |
@@ -74,20 +69,10 @@ public static int countMonths(int days){ |
74 | 69 |
|
75 | 70 |
|
76 | 71 | public static YearMonth parseMonth(int value){ |
77 | | - int year = value / 12; |
78 | | - int month = value % 12 + 1; |
79 | 72 | 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)); |
89 | 74 | } |
90 | | - return YearMonth.of(year, month); |
| 75 | + return YearMonth.of(value/12, value % 12 + 1); |
91 | 76 | } |
92 | 77 |
|
93 | 78 | public static int countDays(LocalDate date){ |
|
0 commit comments