[threeten-dev] some problems in java.time.YearMonth and java.time.Year

Patrick Zhang patrick.zhang at oracle.com
Tue Mar 12 19:21:11 PDT 2013


Hi Stephen,

Thanks. I will update the repo and try again. :)

Regards
Patrick

On 3/12/13 11:32 PM, Stephen Colebourne wrote:
> Fixed in
> http://hg.openjdk.java.net/threeten/threeten/jdk/rev/97e8eb496b37
> http://hg.openjdk.java.net/threeten/threeten/jdk/rev/0e98b03f696a
> http://hg.openjdk.java.net/threeten/threeten/jdk/rev/0dcbfca54160
>
> Additional tests in
> http://hg.openjdk.java.net/threeten/threeten/jdk/rev/72bb5d877b83
>
> thanks
> Stephen
>
>
> On 12 March 2013 15:11, Stephen Colebourne<scolebourne at joda.org>  wrote:
>> 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