Search
Categories
Tags
Latest Comments
« QuickTip: HTML Element Selection Using Dojo | Main | Embedding Contextual Data for Client-Side Logic in XPages »
Friday
Mar052010

SSJS @Adjust on Javascript Dates - Be Backwarned!

The following code will generate results that you may not expect:

var myDate = new Date(2010,2,15);  //this is MARCH 15th, months for JSDate is zero based
myDate = @Adjust(myDate,0,-1,0,0,0,0);

You might expect myDate to now be 2/15/2010 ... its what the classic @Adjust @Formula would output.  But there is a little more than meets the eye going on here.

new Date(2010,2,15) creates a new Date in the local time zone... In SSJS @Adjust() by default treats the date as a UTC timezone, so the results you will actually get is:

2/14/2010

Why you ask? Because we didnt specify a time in the date object, it's set to 12 Midnight, and going from March back to February crosses the line for Daylight savings, and the adjusted time changes from 12:00:00 midnight to 11:00:00 PM the previous day as you cross back.

The key is to specify the "[InLocalTime]" keyword to the @Adjust function, so the correct call would be:

@Adjust(myDate,0,-1,0,0,0,0,"[InLocalTime]")

Thanks to Dave Connelly and the IBM Team for chasing this one down!

 

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (1)

Ah, daylight savings, what fun it causes us all!

March 5, 2010 | Unregistered CommenterPaul Withers

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>