Skip to content

Commit

Permalink
fixed files form Time #6
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent 0d4a912 commit 2923dec
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions projects/Time/6/org/joda/time/chrono/GJChronology.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ public static synchronized GJChronology getInstance(
cutoverInstant = DEFAULT_CUTOVER;
} else {
cutoverInstant = gregorianCutover.toInstant();
LocalDate cutoverDate = new LocalDate(cutoverInstant.getMillis(), GregorianChronology.getInstance(zone));
if (cutoverDate.getYear() <= 0) {
throw new IllegalArgumentException("Cutover too early. Must be on or after 0001-01-01.");
}
}

GJChronology chrono;
Expand Down Expand Up @@ -976,6 +980,17 @@ public long add(long instant, int value) {
if (instant < iCutover) {
// Only adjust if gap fully crossed.
if (instant + iGapDuration < iCutover) {
if (iConvertByWeekyear) {
int wyear = iGregorianChronology.weekyear().get(instant);
if (wyear <= 0) {
instant = iGregorianChronology.weekyear().add(instant, -1);
}
} else {
int year = iGregorianChronology.year().get(instant);
if (year <= 0) {
instant = iGregorianChronology.year().add(instant, -1);
}
}
instant = gregorianToJulian(instant);
}
}
Expand All @@ -998,6 +1013,17 @@ public long add(long instant, long value) {
if (instant < iCutover) {
// Only adjust if gap fully crossed.
if (instant + iGapDuration < iCutover) {
if (iConvertByWeekyear) {
int wyear = iGregorianChronology.weekyear().get(instant);
if (wyear <= 0) {
instant = iGregorianChronology.weekyear().add(instant, -1);
}
} else {
int year = iGregorianChronology.year().get(instant);
if (year <= 0) {
instant = iGregorianChronology.year().add(instant, -1);
}
}
instant = gregorianToJulian(instant);
}
}
Expand Down

0 comments on commit 2923dec

Please sign in to comment.