Skip to content

Commit 94957fa

Browse files
committed
Improved feb29 formula
1 parent 23e0178 commit 94957fa

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/DayAxisValueFormatter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ private int getDaysForMonth(int month, int year) {
7373
// month is 0-based
7474

7575
if (month == 1) {
76-
int x400 = month % 400;
77-
if (x400 < 0)
78-
{
79-
x400 = -x400;
80-
}
81-
boolean is29 = (month % 4) == 0 && x400 != 100 && x400 != 200 && x400 != 300;
76+
boolean is29Feb = false;
77+
78+
if (year < 1582)
79+
is29Feb = (year < 1 ? year + 1 : year) % 4 == 0;
80+
else if (year > 1582)
81+
is29Feb = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
8282

83-
return is29 ? 29 : 28;
83+
return is29Feb ? 29 : 28;
8484
}
8585

8686
if (month == 3 || month == 5 || month == 8 || month == 10)

0 commit comments

Comments
 (0)