http://issues.objectstyle.org/jira/browse/WONDER-425
>From Oct 7, 2009:
> I ran into this bug quite a while ago! I found this code somewhere ... I
> don't recall where ... I think it may have been the Houdah framework.
> Anyway, I'm not going to take credit for it, but it works!
>
> /** Adds time to a date.<BR>
> * This utility method replaces NSTimestamp.
> * timestampByAddingGregorianUnits() which does all its computations in
> the
> * GMT timezone. This leads to several problems. For one DST changes
> don't
> * happen as expected. Adding 1 month to a CET midnight of a first of a
> * month does not bring us to the first of the next month, but only as
> many
> * days further as there are days in the preceeding month.
> *
> * @param date the original
> timestamp or date
> * @param year number of years
> to add
> * @param month number of
> months to add
> * @param day number
> of days to add
> * @param hour number of hours
> to add
> * @param minute number of
> minutes to add
> * @param second number of
> seconds to add
> *
> * @return a new date corresponding to original date to
> which we add specified time.
> **/
> public static NSTimestamp timestampByAddingGregorianUnits(
> Date date,
> int year,
> int month,
> int day,
> int hour,
> int minute,
> int second)
> {
> GregorianCalendar calendar = new GregorianCalendar();
>
> calendar.setTime(date);
>
> return new NSTimestamp(
> calendar.get(GregorianCalendar.YEAR) + year,
> calendar.get(GregorianCalendar.MONTH) + month +
> 1,
> calendar.get(GregorianCalendar.DAY_OF_MONTH) +
> day,
> calendar.get(GregorianCalendar.HOUR_OF_DAY) +
> hour,
> calendar.get(GregorianCalendar.MINUTE) + minute,
> calendar.get(GregorianCalendar.SECOND) + second,
> TimeZone.getDefault());
> }
>
>
> Cheers,
> Michael.
Ramsey
On Oct 30, 2010, at 2:50 PM, James Cicenia wrote:
> Hello -
>
> Here is the code:
>
> weekStart = beginDate.timestampByAddingGregorianUnits(0,0,(k*7),0,0,0);
> weekAfterStart =
> beginDate.timestampByAddingGregorianUnits(0,0,((k+1)*7),0,0,0);
>
> System.out.println("weekStart = "+weekStart);
> System.out.println("weekAfterStart = "+weekAfterStart);
> System.out.println("converted weekAfterStart =
> "+TOSUtilities.formatTimestampToDay(weekAfterStart));
>
> OUTPUTS:
>
> weekStart = 2010-11-01 05:00:00 Etc/GMT
> weekAfterStart = 2010-11-08 05:00:00 Etc/GMT
> convertedWeekAfterStart = 11/07/10 <<=========== wrong?!
>
> Thanks
> James
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list ([email protected])
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/rgurley%40mac.com
>
> This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]