JAN 22 2007

ColdFusion and 2007 DST changes

Related Categories: ColdFusion

The Energery Policy Act of 2005 officially changes the start and end dates for Daylight Savings Time (DST) in the US this year (2007). DST will start at 2:00AM on the 2nd Sunday in March (03/11/2007) and end the 1st Sunday in November (11/04/2007). These dates will affect all versions of ColdFusion (5.0-MX 7).

This will cause issues with date/time calculations in ColdFusion. Some blogs have already posted notes on this. Adobe has published technotes dealing with the DST changes for ColdFusion:

  • Technote kb400365, ColdFusion 5: How to ensure correct UTC Time Conversion for U.S. Daylight Saving Time changes in 2007
  • Technote d2ab4470, ColdFusion MX/JRun and U.S. Daylight Savings Time changes in 2007

Workarounds

For CFMX 6.x-7.x, you need to upgrade to Sun JVM 1.4.2_11 or later: see Sun's note. Download the dstDates.zip to verify your update.

For CF 5.0, you need to first apply the operating system DST-related patches. This will fix the issue for every date/time function except dateConvert(). UTC conversions will be off by an hour during the new DST periods --i.e. from March 11 (new DST start) - April 1 (old DST start), CF 5 is an hour ahead for Local2UTC and for the UTC2Local CF 5 is an hour behind; and from October 28 (old DST end) - November 4 (new DST end), CF 5 reverts to an hour ahead for Local2UTC, and an hour behind for UTC2Local. The technote has my work around code in it, here's the tag based version:

<cfset cfTZ = getTimeZoneInfo() />
<cfset dateObj = now() />
<cfif cfTZ.isDSTOn>
<cfset utcDate = dateAdd('h', -1, dateConvert("Local2UTC", dateObj)) />
<cfset localDate = dateAdd('h', 1, dateConvert("UTC2Local", dateObj)) />
<cfelse>
<cfset utcdate= dateConvert("Local2UTC", dateobj) />
<cfset localDate = dateConvert("UTC2Local", dateObj) />
</cfif>

Comments (18) | Print | Send | Download | del.icio.us | Digg It! | Linking Blogs
TweetBacks
There are no TweetBacks for this entry.
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

[Add Comment] [Subscribe to Comments]

Terry Schmitt's Gravatar Hi Sarge,
If my testing is correct, I have found a problem with this code.
I ran through 3 scenarios:
1. Original OS using standard CF dateConvert()
2. Patched OS using standard CF dateConvert()
3. Patched OS using this tag based code

I created a test matrix using server dates of: 2/15/2007, 3/15/2007 and 4/15/2007.
During each of those I then tested by inputing a UTC date of: 2/15/2007, 3/15/2007 and 4/15/2007.
This would capture Standard time, the new DST and the old DST.
I then looked for the correct offset when converting to local time (Pacific Time).

Scenario 1 and 2 had identical results where a UTC date of 3/15/2007 would not convert correctly. Makes sense, as we already know that DateCompare() has issues.
Scenaro 3 has some really strange results. Here are the results:
   Server: 2/15/2007
   UTC:   2/15    8hr diff normal
   UTC:   3/15   8hr diff did not adjust**************
   UTC:   4/15   7hr diff adjusted
   Server: 3/15/2007
   UTC:   2/15    7hr diff invalid adjust**************
   UTC:   3/15   7hr diff adjusted
   UTC:   4/15   6hr diff invalid adjust**************
   Server: 4/15/2007
   UTC:   2/15    7hr diff invalid adjust**************
   UTC:   3/15   7hr diff adjusted
   UTC:   4/15   6hr diff invalid adjust**************

I have the results from all 3 scenarios if needed.
Your code primarily tests if the server date is in DST and adjusts the math. I think the correct test is to test the input date and tweak the math if the input date is in the new DST 3 week periods.
I welcome your thoughts, as I'm still trying to get my head wrapped around this thing and maybe I goofed up somewhere. I did this real quick last night on a win2000 box and set up a VPS today just for this testing. Same results on both.

Thanks, Terry
# Posted By Terry Schmitt | 2/7/07 1:31 PM
Kirk's Gravatar Sarge, what is the prognosis for CF 4.5?
# Posted By Kirk | 2/7/07 1:31 PM
Plat's Gravatar I agree with Terry, something doesn't look right with this workaround.

For what it's worth, here's the workaround I'm planning to use. It assumes that you're in UTC-6 when not in daylight time, and that the clocks are adjusted by +1 hour when in daylight saving time. It also relies on some date functions from the great CFLib (http://www.cflib.org/library.cfm?ID=13).

It passed all my unit tests, but I make no warranties of accuracy :-).


function DF_UTCToLocal() {
var dUTC = Arguments[1];
   var iTimeZoneOffset = -6;
   var dDSTStartUTC = dateadd("h", 2 - iTimeZoneOffset, getDaylightSavingTimeStart(Year(dUTC)));
   var dDSTEndUTC = dateadd("h", 2 - iTimeZoneOffset - 1, getDaylightSavingTimeEnd(Year(dUTC)));
   if (dUTC gte dDSTStartUTC and dUTC lt dDSTEndUTC) {
    return dateadd("h", iTimeZoneOffset + 1, dUTC);
} else {
    return dateadd("h", iTimeZoneOffset, dUTC);
   }
}

function DF_LocalToUTC() {
var dLocal = Arguments[1];
   var iTimeZoneOffset = -6;
   var dDSTStartLocal = dateadd("h", 3, getDaylightSavingTimeStart(Year(dLocal)));
   var dDSTEndLocal = dateadd("h", 1, getDaylightSavingTimeEnd(Year(dLocal)));
   if (dLocal gte dDSTStartLocal and dLocal lt dDSTEndLocal) {
    return dateadd("h", -iTimeZoneOffset - 1, dLocal);
} else {
    return dateadd("h", -iTimeZoneOffset, dLocal);
   }
}
# Posted By Plat | 2/15/07 11:00 AM
David Sharpe's Gravatar Thanks for pointing this out. IT professionals worldwide need to be cognizant of the DST2007 problem, especially if your organization, your organizations customers, or your partners have a physical or electronic presence in the United States or Canada. There is a small but growing body of information available online to help address the DST2007 problem. For example, there is a tool available at sharpebusinesssolutions.com/dst2007.htm to help with one of the toughest parts of the problem - unsupported versions of Microsoft Windows.
# Posted By David Sharpe | 2/25/07 1:11 PM
Sarge's Gravatar Kirk, CF 4.5 is end-of-life and no longer supported. I would try it but unfortunately I don't even have an install available. My bet is it has the same dependancies on the OS DST information.
# Posted By Sarge | 3/5/07 12:41 PM
Sarge's Gravatar Terry/Plat,

Thanks for your input. I will revisit the code and the technote very shortly.
# Posted By Sarge | 3/5/07 12:44 PM
Dale Morgan's Gravatar Sarge, I think your code assumes that you're only interested in determining whether the machine on which the code is running will be in Daylight Savings Time on the dates and times in question. If the machine doesn't observe DST, "DST On" will always be No.

But what if the machine needs to determine if DST will be in effect on machines that DO observe it? Seems like you'd need to add a parameter here to do the calculations for another timezone.

Does that make sense?
# Posted By Dale Morgan | 3/5/07 2:45 PM
Eric Goetz's Gravatar Thanks for the information. I discovered an additional problem:

I've applied the jvm patch, but when I connect to oracle and do:

select LOCALTIMESTAMP from DUAL;

It returns the time in standard time. Apparently there is something in Cold Fusion's oracle driver that still thinks we're in standard time. I'm using ColdFusion Mx 6,1,0,83762, with sun JVM 1.4.2 with the DST patch applied.
# Posted By Eric Goetz | 3/14/07 5:06 PM
rollos's Gravatar Good explanation, it was very useful for understand.
# Posted By rollos | 11/8/07 1:47 AM
pete's Gravatar Kirk, CF 4.5 is end-of-life and no longer supported. I would try it but unfortunately I don't even have an install available. My bet is it has the same dependancies on the OS DST information.
http://www.dir-9.com
# Posted By pete | 11/22/07 6:05 PM
Flohmärkte's Gravatar Nice Codding ;)
# Posted By Flohmärkte | 11/28/07 2:47 AM
fee's Gravatar It returns the time in standard time. Apparently there is something in Cold Fusion's oracle driver that still thinks we're in standard time. I'm using ColdFusion Mx 6,1,0,83762, with sun JVM 1.4.2 with the DST patch applied

http://www.dir-9.com
# Posted By fee | 12/4/07 9:02 PM
Skulpturen's Gravatar There are many useful informations in this article. Thanks and greetings from Thuringia!
# Posted By Skulpturen | 1/10/08 3:40 AM
automotive repair manual's Gravatar Thanks for pointing this out. IT professionals worldwide need to be sensible of of the DST2007 blemish, in detail if your division, your configurations customers, or your partners think little of a physical or electronic confidence in the United States or Canada. There is a small but mature body of contact available online to help artisanship the DST2007 discomposure. For explanation, there is a treasure available at sharpebusinesssolutions.com/dst2007.htm to help with one of the toughest parts of the head - unascertained versions of Microsoft Windows.

http://www.automotive-repair-manual.net/
# Posted By automotive repair manual | 1/10/08 7:37 PM
Kunstforum's Gravatar Good stuff. Thanks and greetings!
# Posted By Kunstforum | 1/18/08 3:18 AM
Programy's Gravatar Thanks for help, Keep up the good work....
# Posted By Programy | 2/16/08 2:40 PM
Peter Edd's Gravatar Plat, thanks so much for your post. I've been searching for a solution to this issue, and yours works flawlessly.
# Posted By Peter Edd | 3/5/08 5:54 PM
oyun's Gravatar nice code man! thank you!
# Posted By oyun | 3/18/08 2:57 AM
Welcome to Sarge's personal blog A green acorn

Previous Month September 2010 Next Month

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    

Subscribe
Enter your email address to subscribe to this blog.