8072746: LocalDate.isEra() should return IsoEra not Era
authorntv
Tue, 17 Nov 2015 10:44:22 -0500
changeset 33847 7857fc64d0c0
parent 33846 049daf20246e
child 33848 80c992df5d92
8072746: LocalDate.isEra() should return IsoEra not Era Reviewed-by: rriggs, scolebourne
jdk/src/java.base/share/classes/java/time/LocalDate.java
jdk/test/java/time/tck/java/time/TCKLocalDate.java
--- a/jdk/src/java.base/share/classes/java/time/LocalDate.java	Tue Nov 17 15:29:21 2015 +0100
+++ b/jdk/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/jdk/test/java/time/tck/java/time/TCKLocalDate.java	Tue Nov 17 15:29:21 2015 +0100
+++ b/jdk/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);
+    }
 }