[threeten-dev] some problems in java.time.YearMonth and java.time.Year
Stephen Colebourne
scolebourne at joda.org
Tue Mar 12 08:11:31 PDT 2013
On 9 March 2013 07:14, patrick zhang <patrick.zhang at oracle.com> wrote:
> 1. Year.minus(TemporalAmout) does not work properly.
> ===========
> Year year = Year.of(5);
> Year result = year.minus(Period.ofYears(2)) ;
> System.out.println(result);
> ===========
> Personally I think above code should work and return Year.of(3). But it
> throws exception:
This is a bug.
> 2. javadoc for Year.minus(long, TemporalUnit) is wrong.
> As you know the method will return Year same with minus(TemporalAmout) while
> it is "YearMonth" in current javadoc:
This is a bug.
3. javadoc for
> java.time.Temporal.ChronoUnit.ERAS is confused.
> Here there are 2 problems.
> ====================
> Unit that represents the concept of an era. The ISO calendar system doesn't
> have eras thus it is impossible to add an era to a date or date-time. The
> estimated duration of the era is artificially defined as 1,000,00,000 Years.
> ====================
> I guess it should be 1,000,000,000 years nor 1,000,00,000
This is a bug.
> ====================
> Year year = Year.of(-1);
> Year result = year.plus(1, ChronoUnit.ERAS);
>
> System.out.println(year.get(ChronoField.ERA) + " " +
> year.get(ChronoField.YEAR_OF_ERA) + " " + year.get(ChronoField.YEAR));
> System.out.println(result.get(ChronoField.ERA) + " " +
> result.get(ChronoField.YEAR_OF_ERA) + " " + result.get(ChronoField.YEAR));
>
> output:
> 0 2 -1
> 1 2 2
> ====================
> Since ERAS is not supported in ISO calendar, I think it should not return
> such a strange result.
> It looks it only plus 1 on ChronoField.ERAS field simply......
The ISO calendar system does support eras, see IsoEra. BCE is from
proleptic year 0 backwards and CE is from proleptic year 1 forwards,
just like AD/BC in GregorianCalendar.
The code above is therefore correct, as it changes 2BCE to 2CE.
Stephen
More information about the threeten-dev
mailing list