Hello there,

is it possible, that ERXTimestampUtilities.differenceByDay doesn't work 
correctly?

I have the following piece of code: 

> NSTimestamp dec312015 = new NSTimestamp(2015, 12, 31, 0, 0, 0, null);
> NSTimestamp jan012016 = new NSTimestamp(2016,  1,  1, 0, 0, 0, null);
>               
> NSLog.out.appendln("ERX 2015/2016: 
> "+ERXTimestampUtilities.differenceByDay(dec312015, jan012016));
> 
> NSTimestamp dec312016 = new NSTimestamp(2016, 12, 31, 0, 0, 0, null);
> NSTimestamp jan012017 = new NSTimestamp(2017,  1,  1, 0, 0, 0, null);
> 
> NSLog.out.appendln("ERX 2016/2017: 
> "+ERXTimestampUtilities.differenceByDay(dec312016, jan012017));

The output is:

ERX 2015/2016: 1
ERX 2016/2017: 0

This is obviously wrong because it should return 1 in both cases.

I think the culprit is 
ERXTimestampUtilities.offsetForDateInCommonEra(NSTimestamp t, int mode), 
because ERXTimestampUtilities.differenceByDay simply calculates 

> offsetForDateInCommonEra(t2, mode) - offsetForDateInCommonEra(t1, mode);


with mode=Calendar.DAY_OF_YEAR.

If you pass mode=Calendar.DAY_OF_YEAR and a timestamp to 
ERXTimestampUtilities.offsetForDateInCommonEra, it calculates

> case Calendar.DAY_OF_YEAR:
>     return calendar.get(Calendar.YEAR) * 365 + 
> calendar.get(Calendar.DAY_OF_YEAR);


So it simply takes the number of years times 365. But 365 is not the right 
value for leap years.

Can someone confirm that ERXTimestampUtilities.differenceByDay is buggy? Or am 
I completely wrong?

C.U.CW
-- 
The three great virtues of a programmer are Laziness, Impatience and Hubris. 
(Randal Schwartz)

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to