OSDN Git Service

Fix incorrect leap year logic
authorNeil Fuller <nfuller@google.com>
Wed, 17 Apr 2019 14:54:22 +0000 (15:54 +0100)
committerNeil Fuller <nfuller@google.com>
Wed, 17 Apr 2019 16:41:04 +0000 (17:41 +0100)
Fixing an issue for 2100 in SimpleMonthView.

Tweak the logic in DatePickerCalendarDelegate to optimize
for the common case and save a calculation.

Bug: 28784177
Test: build only
Change-Id: I7395ab9f3dc90ac4f7cef1edee6f7bc156f4ab76

core/java/android/widget/DatePickerCalendarDelegate.java
core/java/android/widget/SimpleMonthView.java

index 46edf47..53e145e 100755 (executable)
@@ -597,7 +597,7 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate {
             case Calendar.NOVEMBER:
                 return 30;
             case Calendar.FEBRUARY:
-                return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? 29 : 28;
+                return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 29 : 28;
             default:
                 throw new IllegalArgumentException("Invalid Month");
         }
index 9982732..80de6fc 100644 (file)
@@ -850,7 +850,7 @@ class SimpleMonthView extends View {
             case Calendar.NOVEMBER:
                 return 30;
             case Calendar.FEBRUARY:
-                return (year % 4 == 0) ? 29 : 28;
+                return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 29 : 28;
             default:
                 throw new IllegalArgumentException("Invalid Month");
         }