Skip to content

Commit

Permalink
Avoid LocalDate.ofEpochDay() out of range
Browse files Browse the repository at this point in the history
Validate input and fix EPOCH_DAY boundaries
Fixes #39
  • Loading branch information
jodastephen committed Jun 30, 2016
1 parent 738158a commit 006216f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
!/src/main/
!/src/site/
!/src/test/

**/TempTest.java
1 change: 1 addition & 0 deletions src/main/java/org/threeten/bp/LocalDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public static LocalDate ofYearDay(int year, int dayOfYear) {
* @throws DateTimeException if the epoch days exceeds the supported date range
*/
public static LocalDate ofEpochDay(long epochDay) {
EPOCH_DAY.checkValidValue(epochDay);
long zeroDay = epochDay + DAYS_0000_TO_1970;
// find the march-based year
zeroDay -= 60; // adjust to 0000-03-01 so leap day is at end of four year cycle
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/threeten/bp/temporal/ChronoField.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public enum ChronoField implements TemporalField {
* This field is strictly defined to have the same meaning in all calendar systems.
* This is necessary to ensure interoperation between calendars.
*/
EPOCH_DAY("EpochDay", DAYS, FOREVER, ValueRange.of((long) (Year.MIN_VALUE * 365.25), (long) (Year.MAX_VALUE * 365.25))),
EPOCH_DAY("EpochDay", DAYS, FOREVER, ValueRange.of(-365243219162L, 365241780471L)),
/**
* The aligned week within a month.
* <p>
Expand Down

0 comments on commit 006216f

Please sign in to comment.