Skip to content

Commit

Permalink
tweaken max-constraint on year-of-era
Browse files Browse the repository at this point in the history
  • Loading branch information
MenoData committed Sep 26, 2018
1 parent 7685d25 commit 61aeef6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ private boolean isOutOfRange(HistoricDate hd) {
} else if (this == PROLEPTIC_JULIAN) {
return (Math.abs(ad) > JULIAN_YMAX);
} else if (this == PROLEPTIC_GREGORIAN) {
return false;
return (Math.abs(ad) > GregorianMath.MAX_YEAR);
} else {
return ((ad < -44) || (ad > 9999));
}
Expand Down
21 changes: 6 additions & 15 deletions time4j-android/src/main/java/net/time4j/history/HistoricDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public final class HistoricDate
* YearDefinition.DUAL_DATING, NewYearRule.BEGIN_OF_JANUARY.until(Integer.MAX_VALUE))}. </p>
*
* @param era historic era
* @param yearOfEra year of related era ({@code 1 <= yearOfEra <= 999,999,999}) starting on January the first
* @param yearOfEra year of related era ({@code 1 <= yearOfEra}) starting on January the first
* @param month historic month (1-12)
* @param dom historic day of month (1-31)
* @return new historic date (not yet validated)
Expand All @@ -97,7 +97,7 @@ public final class HistoricDate
* YearDefinition.DUAL_DATING, NewYearRule.BEGIN_OF_JANUARY.until(Integer.MAX_VALUE))}. </p>
*
* @param era historic era
* @param yearOfEra year of related era ({@code 1 <= yearOfEra <= 999,999,999}) starting on January the first
* @param yearOfEra year of related era ({@code 1 <= yearOfEra}) starting on January the first
* @param month historic month (1-12)
* @param dom historic day of month (1-31)
* @return new historic date (not yet validated)
Expand All @@ -120,12 +120,10 @@ public static HistoricDate of(
* <p>Constructs a new tuple of given historic chronological components. </p>
*
* <p>Note: A detailed validation is not done. Such a validation is the responsibility
* of any {@code ChronoHistory}, however. The parameter year-of-era must not have
* more than 9 digits. </p>
* of any {@code ChronoHistory}, however. </p>
*
* @param era historic era
* @param yearOfEra year of era which will be interpreted according to given year definition,
* usually ({@code 1 <= yearOfEra <= 999,999,999})
* @param yearOfEra positive year of era which will be interpreted according to given year definition
* @param month historic month (1-12)
* @param dom historic day of month (1-31)
* @param yearDefinition defines a strategy how to interprete year of era
Expand All @@ -139,11 +137,10 @@ public static HistoricDate of(
* <p>Konstruiert ein neues Tupel aus den angegebenen historischen Zeitkomponenten. </p>
*
* <p>Hinweis: Eine detaillierte Validierung wird nicht gemacht. Das ist stattdessen Aufgabe
* der {@code ChronoHistory}. Der Parameter year-of-era darf nicht mehr als 9 Ziffern haben. </p>
* der {@code ChronoHistory}. </p>
*
* @param era historic era
* @param yearOfEra year of era which will be interpreted according to given year definition,
* usually ({@code 1 <= yearOfEra <= 999,999,999})
* @param yearOfEra positive year of era which will be interpreted according to given year definition
* @param month historic month (1-12)
* @param dom historic day of month (1-31)
* @param yearDefinition defines a strategy how to interprete year of era
Expand Down Expand Up @@ -180,12 +177,6 @@ public static HistoricDate of(
"Year of era must be positive: " + toString(era, yearOfEra, month, dom));
}

if (yearOfEra > 999999999) {
throw new IllegalArgumentException(
"Year of era must not have more than 9 digits: "
+ toString(era, yearOfEra, month, dom));
}

if (!yearDefinition.equals(YearDefinition.DUAL_DATING)) {
// here we interprete yearOfEra as yearOfDisplay and have to translate it to standard calendar year
NewYearRule rule = newYearStrategy.rule(era, yearOfEra);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package net.time4j.history;

import net.time4j.PlainDate;
import net.time4j.base.GregorianMath;
import net.time4j.engine.BasicElement;
import net.time4j.engine.ChronoElement;
import net.time4j.engine.ChronoEntity;
Expand All @@ -43,7 +44,6 @@ final class HistoricDateElement

//~ Statische Felder/Initialisierungen --------------------------------

private static final int YMAX = 999999999;
private static final long serialVersionUID = -5386613740709845550L;

//~ Instanzvariablen --------------------------------------------------
Expand Down Expand Up @@ -167,7 +167,7 @@ public HistoricDate getMinimum(C context) {
} else if (this.history == ChronoHistory.PROLEPTIC_JULIAN) {
return HistoricDate.of(HistoricEra.BC, ChronoHistory.JULIAN_YMAX + 1, 1, 1);
} else if (this.history == ChronoHistory.PROLEPTIC_GREGORIAN) {
return HistoricDate.of(HistoricEra.BC, YMAX, 1, 1);
return HistoricDate.of(HistoricEra.BC, GregorianMath.MAX_YEAR + 1, 1, 1);
} else {
return HistoricDate.of(HistoricEra.BC, 45, 1, 1);
}
Expand All @@ -182,7 +182,7 @@ public HistoricDate getMaximum(C context) {
} else if (this.history == ChronoHistory.PROLEPTIC_JULIAN) {
return HistoricDate.of(HistoricEra.AD, ChronoHistory.JULIAN_YMAX, 12, 31);
} else if (this.history == ChronoHistory.PROLEPTIC_GREGORIAN) {
return HistoricDate.of(HistoricEra.AD, YMAX, 12, 31);
return HistoricDate.of(HistoricEra.AD, GregorianMath.MAX_YEAR, 12, 31);
} else {
return HistoricDate.of(HistoricEra.AD, 9999, 12, 31);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.time4j.Month;
import net.time4j.PlainDate;
import net.time4j.base.GregorianDate;
import net.time4j.base.GregorianMath;
import net.time4j.base.MathUtils;
import net.time4j.engine.AttributeQuery;
import net.time4j.engine.BasicElement;
Expand Down Expand Up @@ -691,9 +692,12 @@ public Integer getMaximum(C context) {
max++;
}
} else if (this.history == ChronoHistory.PROLEPTIC_GREGORIAN) {
max = 999999999;
max = GregorianMath.MAX_YEAR;
if (current.getEra() == HistoricEra.BC) {
max++;
}
} else {
max = 9999;
max = ((current.getEra() == HistoricEra.BC) ? 45 : 9999);
}
if (this.index == CENTURY_INDEX) {
max = ((max - 1) / 100) + 1;
Expand Down

0 comments on commit 61aeef6

Please sign in to comment.