changeset 14585:d6eeea558b1f

8072746: LocalDate.isEra() should return IsoEra not Era Reviewed-by: rriggs, scolebourne
author ntv
date Tue, 17 Nov 2015 10:44:22 -0500
parents e18fa807dd59
children b38edf61b64c
files src/java.base/share/classes/java/time/LocalDate.java test/java/time/tck/java/time/TCKLocalDate.java
diffstat 2 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/time/LocalDate.java	Tue Nov 17 15:29:21 2015 +0100
+++ b/src/java.base/share/classes/java/time/LocalDate.java	Tue Nov 17 10:44:22 2015 -0500
@@ -81,7 +81,7 @@
 import java.io.ObjectInputStream;
 import java.io.Serializable;
 import java.time.chrono.ChronoLocalDate;
-import java.time.chrono.Era;
+import java.time.chrono.IsoEra;
 import java.time.chrono.IsoChronology;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
@@ -732,15 +732,12 @@
      * Users of this class should typically ignore this method as it exists primarily
      * to fulfill the {@link ChronoLocalDate} contract where it is necessary to support
      * the Japanese calendar system.
-     * <p>
-     * The returned era will be a singleton capable of being compared with the constants
-     * in {@link IsoChronology} using the {@code ==} operator.
      *
-     * @return the {@code IsoChronology} era constant applicable at this date, not null
+     * @return the IsoEra applicable at this date, not null
      */
     @Override // override for Javadoc
-    public Era getEra() {
-        return ChronoLocalDate.super.getEra();
+    public IsoEra getEra() {
+        return (getYear() >= 1 ? IsoEra.CE : IsoEra.BCE);
     }
 
     /**
--- a/test/java/time/tck/java/time/TCKLocalDate.java	Tue Nov 17 15:29:21 2015 +0100
+++ b/test/java/time/tck/java/time/TCKLocalDate.java	Tue Nov 17 10:44:22 2015 -0500
@@ -102,6 +102,7 @@
 import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 import java.time.chrono.IsoChronology;
+import java.time.chrono.IsoEra;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
 import java.time.temporal.ChronoField;
@@ -2326,4 +2327,13 @@
         return LocalDate.of(year, month, day);
     }
 
+    //-----------------------------------------------------------------
+    // getEra()
+    // ----------------------------------------------------------------
+    @Test
+    public void test_getEra() {
+        IsoEra isoEra = LocalDate.MAX.getEra();
+        assertSame(isoEra,IsoEra.CE);
+        assertSame(LocalDate.MIN.getEra(),IsoEra.BCE);
+    }
 }