[threeten-dev] some problems in java.time.YearMonth and java.time.Year
Patrick Zhang
patrick.zhang at oracle.com
Mon Mar 11 18:38:10 PDT 2013
Hi,
Any suggestion about it?
Regards
Patrick
On 3/9/13 3:14 PM, patrick zhang wrote:
> Hi Team,
>
> During investigation for java.time.YearMonth and java.time.Year, I
> have found some problems in it.
>
> 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:
> ===========
> Exception in thread "main" java.time.DateTimeException: Unsupported
> unit: Months
> at java.time.Year.plus(Year.java:660)
> at java.time.Year.minus(Year.java:727)
> at java.time.Year.minus(Year.java:123)
> at java.time.Period.subtractFrom(Period.java:823)
> at java.time.Year.minus(Year.java:704)
> at mytest.TestEra.main(TestEra.java:18)
> ============
>
> 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:
> ====================
>
> Returns:
> a |YearMonth| based on this year-month with the specified amount
> subtracted, not null
> ====================
>
> 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
>
>
> |====================
> 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......
>
> Regards
> Patrick
More information about the threeten-dev
mailing list