From 2923dec2e70e44d3381ff93cc5ccbc69674ccbce Mon Sep 17 00:00:00 2001 From: tdurieux Date: Tue, 7 Mar 2017 13:13:46 +0100 Subject: [PATCH] fixed files form Time #6 --- .../6/org/joda/time/chrono/GJChronology.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/projects/Time/6/org/joda/time/chrono/GJChronology.java b/projects/Time/6/org/joda/time/chrono/GJChronology.java index b970403..d1556f5 100644 --- a/projects/Time/6/org/joda/time/chrono/GJChronology.java +++ b/projects/Time/6/org/joda/time/chrono/GJChronology.java @@ -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; @@ -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); } } @@ -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); } }