Reputation: 273
I'm playing with the new Date API and, just out of curiosity, I've tried to run the following code:
LocalDateTime timePoint = LocalDateTime.now(ZoneId.of("Australia/Canberra"));
System.err.println(timePoint.plus(1, ChronoUnit.ERAS));
And got the following error:
Exception in thread "main" java.time.DateTimeException: Invalid value for Era (valid values 0 - 1): 2
at java.time.temporal.ValueRange.checkValidValue(ValueRange.java:311)
at java.time.temporal.ChronoField.checkValidValue(ChronoField.java:703)
at java.time.LocalDate.with(LocalDate.java:1023)
at java.time.LocalDate.plus(LocalDate.java:1245)
at java.time.LocalDateTime.plus(LocalDateTime.java:1194)
at pt.sibs.epms.Tester.method6(Tester.java:79)
at pt.sibs.epms.Tester.main(Tester.java:59)
Is this a bug or I just am not using it correctly?
Upvotes: 0
Views: 204
Reputation: 207006
The documentation of the plus
method that you are calling says:
Throws:
DateTimeException
if the addition cannot be made
You are using the standard ISO chronology, which uses IsoEra
. The ISO chronology has two eras:
If you have a date which is in the CE and you try to go to the next era, you get a DateTimeException
because there is no next era, so the addition cannot be made and the exception is thrown, which is according to the documentation, so this is not a bug.
Upvotes: 1