[threeten-dev] incompatibility issues between MinguoDate.minus(Period) and MinguoDate.periodUntil(MinguoDate)
patrick zhang
patrick.zhang at oracle.com
Thu Feb 28 00:25:49 PST 2013
Hi Team,
As you know, MinguoDate.minus(Period) will return one new MinguoDate
while MinguoDate.periodUntil(MinguoDate) will calculate the period
between 2 date.
so I think:
if
minguodate2 = minguodate1.minus(period) ;
then
minguodate2.periodUntil(minguodate1) = period.
I write sample code to check it. It looks sometime it works but
sometimes it fails.
You can see date3 and date4 work as expected while data1 and date2 look
strange.
I know it is caused by different length of months. And Period class will
do something to match it.
But I am really a bit confused by the output. Is it correct behavior?
Code:
=============================
MinguoDate date1 = MinguoDate.of(1970, 1, 1) ;
Period p = Period.of(1, 1, 1) ;
MinguoDate date2 = date1.minus(p) ;
System.out.println(p) ;
System.out.println(date2.periodUntil(date1)) ;
System.out.println("**************") ;
MinguoDate date3 = MinguoDate.of(1970, 5, 3) ;
MinguoDate date4 = date3.minus(p) ;
System.out.println(p) ;
System.out.println(date4.periodUntil(date3)) ;
===============================
Output:
===============================
P1Y1M1D
P1Y1M2D
**************
P1Y1M1D
P1Y1M1D
===============================
Regards
Patrick
More information about the threeten-dev
mailing list