• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Possible Bug in ERXTimestampUtility
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Possible Bug in ERXTimestampUtility


  • Subject: Possible Bug in ERXTimestampUtility
  • From: Louis Demers <email@hidden>
  • Date: Mon, 10 Dec 2012 16:20:16 -0500

Hi,

I tried using ERXTimestampUtility.firstDateInNextMonth() and ERXTimestampUtility.firstDateInSameMonth() and didn't get what I expected. Either it's a bug or, the name is less than ideal. I started testing other calls in like firstDateInSameWeek() and discovered problems as well.

If anybody is using those calls, please explain what they are supposed to do ...


Here are some test I ran on the 2012-11-20 22:33:13 Etc/GMT

Wonders result as is

Nov 20 17:33:13  com.obzerv.Experiments  - ERXTimestampUtility 
Nov 20 17:33:13  com.obzerv.Experiments  - ERXTimestampUtility.monthOfYear = 10 <--- Wow we are in november, 11 for NSTimstamp
Nov 20 17:33:13  com.obzerv.Experiments  -  ERXTimestampUtility.dayOfMonth = 20
Nov 20 17:33:13  com.obzerv.Experiments  -   ERXTimestampUtility.dayOfWeek = 3
Nov 20 17:33:13  com.obzerv.Experiments  - ______________________________ 
Nov 20 17:33:13  com.obzerv.Experiments  - ERXTimestampUtility  inWonder 
Nov 20 17:33:13  com.obzerv.Experiments  -                  now 2012-11-20 22:33:13 Etc/GMT
Nov 20 17:33:13  com.obzerv.Experiments  - firstDateInSameMonth 2012-09-11 04:00:00 Etc/GMT <--- Wrong
Nov 20 17:33:13  com.obzerv.Experiments  -  firstDateInSameWeek 2012-09-28 04:00:00 Etc/GMT <--- Wrong
Nov 20 17:33:13  com.obzerv.Experiments  - firstDateInNextMonth 2012-10-11 04:00:00 Etc/GMT <--- Wrong
Nov 20 17:33:13  com.obzerv.Experiments  - ______________________________ 
Nov 20 17:33:13  com.obzerv.Experiments  - Proposed Patched Versions 
Nov 20 17:33:13  com.obzerv.Experiments  -                  now 2012-11-20 22:33:13 Etc/GMT
Nov 20 17:33:13  com.obzerv.Experiments  - firstDateInSameMonth 2012-11-01 04:00:00 Etc/GMT
Nov 20 17:33:13  com.obzerv.Experiments  -  firstDateInSameWeek 2012-11-18 05:00:00 Etc/GMT
Nov 20 17:33:13  com.obzerv.Experiments  - firstDateInNextMonth 2012-12-01 04:00:00 Etc/GMT


and for another date that does not straddle the daylight change

Nov 20 17:35:21  com.obzerv.Experiments  - ERXTimestampUtility 
Nov 20 17:35:21  com.obzerv.Experiments  - ERXTimestampUtility.monthOfYear = 6 <--- Wrong
Nov 20 17:35:21  com.obzerv.Experiments  -  ERXTimestampUtility.dayOfMonth = 13
Nov 20 17:35:21  com.obzerv.Experiments  -   ERXTimestampUtility.dayOfWeek = 6
Nov 20 17:35:21  com.obzerv.Experiments  - ______________________________ 
Nov 20 17:35:21  com.obzerv.Experiments  - ERXTimestampUtility  inWonder 
Nov 20 17:35:21  com.obzerv.Experiments  -                  now 2012-07-13 18:12:45 Etc/GMT
Nov 20 17:35:21  com.obzerv.Experiments  - firstDateInSameMonth 2012-05-19 04:00:00 Etc/GMT <--- Wrong
Nov 20 17:35:21  com.obzerv.Experiments  -  firstDateInSameWeek 2012-05-26 04:00:00 Etc/GMT <--- Wrong
Nov 20 17:35:21  com.obzerv.Experiments  - firstDateInNextMonth 2012-06-19 04:00:00 Etc/GMT <--- Wrong
Nov 20 17:35:21  com.obzerv.Experiments  - ______________________________ 
Nov 20 17:35:21  com.obzerv.Experiments  - Proposed Patched Versions 
Nov 20 17:35:21  com.obzerv.Experiments  -                  now 2012-07-13 18:12:45 Etc/GMT
Nov 20 17:35:21  com.obzerv.Experiments  - firstDateInSameMonth 2012-07-01 04:00:00 Etc/GMT
Nov 20 17:35:21  com.obzerv.Experiments  -  firstDateInSameWeek 2012-07-08 04:00:00 Etc/GMT
Nov 20 17:35:21  com.obzerv.Experiments  - firstDateInNextMonth 2012-08-01 04:00:00 Etc/GMT

and here another case where the week start into another month

Nov 20 17:37:28  com.obzerv.Experiments  - ERXTimestampUtility 
Nov 20 17:37:28  com.obzerv.Experiments  - ERXTimestampUtility.monthOfYear = 2 <--- Wow we are in november, 3 not 2 as for NSTimstamp
Nov 20 17:37:28  com.obzerv.Experiments  -  ERXTimestampUtility.dayOfMonth = 2
Nov 20 17:37:28  com.obzerv.Experiments  -   ERXTimestampUtility.dayOfWeek = 6
Nov 20 17:37:28  com.obzerv.Experiments  - ______________________________ 
Nov 20 17:37:28  com.obzerv.Experiments  - ERXTimestampUtility  inWonder 
Nov 20 17:37:28  com.obzerv.Experiments  -                  now 2012-03-02 18:12:45 Etc/GMT
Nov 20 17:37:28  com.obzerv.Experiments  - firstDateInSameMonth 2012-01-30 05:00:00 Etc/GMT <--- Wrong
Nov 20 17:37:28  com.obzerv.Experiments  -  firstDateInSameWeek 2012-01-26 05:00:00 Etc/GMT <--- Wrong
Nov 20 17:37:28  com.obzerv.Experiments  - firstDateInNextMonth 2012-02-29 05:00:00 Etc/GMT <--- Wrong
Nov 20 17:37:28  com.obzerv.Experiments  - ______________________________ 
Nov 20 17:37:28  com.obzerv.Experiments  - Proposed Patched Versions 
Nov 20 17:37:28  com.obzerv.Experiments  -                  now 2012-03-02 18:12:45 Etc/GMT
Nov 20 17:37:28  com.obzerv.Experiments  - firstDateInSameMonth 2012-03-01 05:00:00 Etc/GMT
Nov 20 17:37:28  com.obzerv.Experiments  -  firstDateInSameWeek 2012-02-26 05:00:00 Etc/GMT
Nov 20 17:37:28  com.obzerv.Experiments  - firstDateInNextMonth 2012-04-01 05:00:00 Etc/GMT


So here are what I would propose

// First we should correct the offset by one (making month 1 based instead of 0 base)

    public static int monthOfYear(NSTimestamp t) {
        return 1 + calendarForTimestamp(t).get(Calendar.MONTH);        
    }

Then correct the faulty methods

public  NSTimestamp firstDateInSameWeek(NSTimestamp value) {
        return new NSTimestamp( ERXTimestampUtility.yearOfCommonEra(value),
ERXTimestampUtility.monthOfYear(value) ,
ERXTimestampUtility.dayOfMonth(value) - ERXTimestampUtility.dayOfWeek(value) + 1,
0, 0, 0, NSTimeZone.defaultTimeZone()
);
    }

    public  NSTimestamp firstDateInSameMonth(NSTimestamp value) {
        return new NSTimestamp(ERXTimestampUtility.yearOfCommonEra(value), ERXTimestampUtility.monthOfYear(value), 1, 0, 0, 0, NSTimeZone.defaultTimeZone());
    }



Cheers


Louis Demers eng.
Vice-President, Co-Founder
Obzerv Technologies Inc.
400 Jean Lesage, suite 201
Quebec, QC, Canada
G1K 8W1
T    418.524.3522
F    418.524.6745
www.obzerv.com






Louis Demers eng.
www.obzerv.com


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: WOComponent Function Call Order
  • Next by Date: rawResults = EOUtilities.rawRowsForSQL();
  • Previous by thread: Re: WOComponent Function Call Order
  • Next by thread: rawResults = EOUtilities.rawRowsForSQL();
  • Index(es):
    • Date
    • Thread