8072746: LocalDate.isEra() should return IsoEra not Era

Reviewed-by: rriggs, scolebourne
This commit is contained in:
Nadeesh TV 2015-11-17 10:44:22 -05:00
parent 42e4e0c06f
commit b6d29b4f0b
2 changed files with 14 additions and 7 deletions

View File

@ -81,7 +81,7 @@ import java.io.InvalidObjectException;
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 @@ public final class LocalDate
* 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);
}
/**

View File

@ -102,6 +102,7 @@ import java.time.ZoneId;
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 @@ public class TCKLocalDate extends AbstractDateTimeTest {
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);
}
}