• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

WDDX (de)serializes dateTime with wrong DST rules?

New Here ,
Apr 09, 2009 Apr 09, 2009

Copy link to clipboard

Copied

2006-Aug-20 00:00 is being translated to 2006-Aug-19 23:00.  That date was in Pacific Daylight Time (-7) but the result seems to be -8 (PST).

I created a Web Service in Lotus Domino 7 and consume it in Coldfusion 8.  I've always returned data to Coldfusion as strings and thought I'd try passing a dateTime.  My Java code uses a kludge to get the ISO8601 date right:

("sb_" = java.lang.StringBuffer; "s__" = java.lang.String; "ca_" = java.util.Calendar)

df_SimpleWddx = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" );
s__Kludge = df_SimpleWddx.format( ca_Began.getTime() );

sb_Wddx.append( "<var name='dt_Began'><dateTime>" + s__Kludge.substring( 0, 22 ) + ":" + s__Kludge.substring( 22 ) + "</dateTime></var>" );

My Coldfusion code:

("dx_" = WDDX data; "st_" = Coldfusion structure)

<cfwddx action="wddx2cfml" input="#dx_BadDates#" output="st_BadDates" />

<cfdump var="#st_BadDates#" />

Seeing {ts '2006-08-19 23:00:00'} in <cfdump>, I changed my Java code to:

sb_Wddx.append( "<var name='dt_Began'><string>" + s__Kludge.substring( 0, 22 ) + ":" + s__Kludge.substring( 22 ) + "</string></var>" );
and got "2006-08-20T00:00:00-07:00" (which is correct).

Unless I'm totally lost, Domino (running JVM 1.4.2_11) is sending the date correctly but <cfwddx> isn't turning it into a dateTime correctly.  I'm running the Developer version of Coldfusion (on my local XP machine) and Coldfusion's JVM is 1.6.0_04.

Has anyone else fought this battle but won?

TOPICS
Advanced techniques

Views

4.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Apr 21, 2009 Apr 21, 2009

sorry it was a test to show adobe that email replies w/quotes show up blank in

the forums.

i'll be submitting the wddx DST issue to adobe as a bug. in the meantime you'll

probably have to workaround it. i guess test if the date is in DST & adjust it

back once it's converted from wddx.

Votes

Translate

Translate
New Here ,
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

In fewer words, what date do you get with this code? (Change the two red sevens to your current offset from GMT.)

<cfwddx action = "wddx2cfml"
        input  = "<wddxPacket version='1.0'><header/><data><dateTime>2006-08-20T00:00:00-07</dateTime></data></wddxPacket>"
        output = "s__WddxDate" />
<cfoutput>WDDX: #s__WddxDate#</cfoutput><br/>


<cfset df_Simple = CreateObject( "java", "java.text.SimpleDateFormat" ) />
<cfset df_Simple.applyPattern( "yyyy-MM-dd'T'HH:mm:ssZ" ) />
<cfoutput>Java: #df_Simple.parse( "2006-08-20T00:00:00-0700" )#</cfoutput>

I get:

WDDX: {ts '2006-08-19 23:00:00'}
Java: {ts '2006-08-20 00:00:00'}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 12, 2009 Apr 12, 2009

Copy link to clipboard

Copied

this is from memory as the forums seem to have eaten my 1st reply:

i got a WDDX datetime parse error. when i sent a datetime from cf to WDDX & back again i get something like:

2009-4-15T10:29:53+7:0
{ts '2009-04-15 10:29:53'}

from this code (which was still on the dev box):

<cfwddx action = "cfml2wddx" input = #now()# output = "wddxText" useTimeZoneInfo="yes">
   
<cfoutput>#wddxText#</cfoutput>
<br>

<cfwddx action = "wddx2cfml"
        input  = "#wddxText#"
        output = "s__WddxDate" />

<cfoutput>#s__WddxDate#</cfoutput>
<br>

note the tz format, i think if you change your original format to include the minutes (the "+7:0" bits, i'm in thailand using indochina tz +7 UTC) you should be good to go. and before you ask, yes there are tz that use mnutes in their offsets.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 14, 2009 Apr 14, 2009

Copy link to clipboard

Copied

Paste this into a CFML page:

<cfset df_Simple = CreateObject( "java", "java.text.SimpleDateFormat" ) />
<cfset df_Simple.applyPattern( "yyyy-MM-dd" ) />

<cfset dt_Test = CreateDate( 2006, 8, 20 ) />
<cfoutput>#DateFormat( dt_Test, "yyyy-mm-dd" )# (original contents of the date variable; we'll add 7 directly to the variable)</cfoutput><br/>
<cfset dt_Test += 7 />
<cfoutput>#DateFormat( dt_Test, "yyyy-mm-dd" )# (new contents of the date variable, according to DateFormat)</cfoutput><br/>
<cfoutput>#df_Simple.format( dt_Test )# (new contents of the date variable, according to Java)</cfoutput><br/><br/>

<cfset dt_Test = CreateDate( 2006, 8, 20 ) />
<cfoutput>#DateFormat( dt_Test, "yyyy-mm-dd" )# (start over; will add 7 days via the DateAdd function)</cfoutput><br/>
<cfset dt_Test = DateAdd( "d", 7, dt_Test ) />
<cfoutput>#DateFormat( dt_Test, "yyyy-mm-dd" )# (new contents of the date variable, according to DateFormat)</cfoutput><br/>
<cfoutput>#df_Simple.format( dt_Test )# (new contents of the date variable, according to Java)</cfoutput>

Output:

2006-08-20 (original contents of the date variable; we'll add 7 directly to the variable)
2006-08-27 (new contents of the date variable, according to DateFormat)
1969-12-31 (new contents of the date variable, according to Java)


2006-08-20 (start over; will add 7 days via the DateAdd function)
2006-08-27 (new contents of the date variable, according to DateFormat)
2006-08-27 (new contents of the date variable, according to Java)

I would consider this a bug.  Either prevent such date math or be sure to update the Java object too.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 14, 2009 Apr 14, 2009

Copy link to clipboard

Copied

I think you are comparing apples and oranges here.  By using +=7 the dt_Test value is implicitly converted to a number (38956).  One the benefits / or negatives of a typeless language, depending on how you look at it.  Since CF is typeless, its date functions can convert 38956 back into a date/time object.  Java being more strict, the rules for SimpleDateFormat are different. It is expecting a java.util.Date or a locale specific date string.  Technically, you are passing in a java.lang.Double. So that is why SimpleDateFormat is returning different results than CF.

Yet, another reason I prefer using date functions. At least I know what the final output will be. Well ... unless it is daylight savings time or something. Then its anyone's guess ..

pbyhistorian wrote:

<cfset dt_Test += 7 />


I would consider this a bug.  Either prevent such date math or be sure to update the Java object too.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 14, 2009 Apr 14, 2009

Copy link to clipboard

Copied

actually i think he's comparing days & ms.

...i can't believe how lame this new forum s/w is. it doesn't seem to handle quoted email replies. i just noiced that all of my email replies have turned up blank, geez.

Message was edited by: PaulH

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 14, 2009 Apr 14, 2009

Copy link to clipboard

Copied

PaulH wrote:

actually i think he's comparing days & ms.

...i can't believe how lame this new forum s/w is. it doesn't seem to handle quoted email replies. i just noiced that all of my email replies have turned up blank, geez.

Message was edited by: PaulH

Probably.  I stopped after noticing the date/time got converted to a java.lang.Double, and that is what was passed to SDF.  My brain is too tired to do the rest of math today.

(Yes, I wondered about that blank message .. but figured it was a forum feature.  Joy, oh joy.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 15, 2009 Apr 15, 2009

Copy link to clipboard

Copied

I very much appreciate everyone's comments; I now know that CF is loosely-typed and that answers my aside on date math.

I think Paul is suggesting that using minutes in the timezone will correct my main problem.  I see that I didn't copy the entire "-07:00" into the shorter example (inside the <dateTime> tags), but including the minutes gave me the same error as the original (lengthy) example: WDDX used non-DST rules when turning the passed value back into a date.

I still have no idea why WDDX overlooks DST in this case; to me, it appears that WDDX is not 100% reliable with dates.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 15, 2009 Apr 15, 2009

Copy link to clipboard

Copied

when i tried to convert your datetime format i got a parsing error, so i'm

fairly sure that's the start of your problem.

what tz is your server in? cf doesn't do so well w/datetime data & tz, it only

knows the tz of the server.

...geez i wish i could quote...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 15, 2009 Apr 15, 2009

Copy link to clipboard

Copied

{smacks forehead} That is what I get for responding when my brain is half asleep.  (TZ's are Paul's forte. So I will leave that to him ; -)

pbyhistorian wrote:


I think Paul is suggesting that using minutes in the timezone will correct my main problem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 15, 2009 Apr 15, 2009

Copy link to clipboard

Copied

no, tz along with saddle sores are actually the bane of my existence

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 16, 2009 Apr 16, 2009

Copy link to clipboard

Copied

Yes, but we get to benefit from your pain. So I guess that makes it all worth it 😉

Now if only I could find the off switch for the forum's auto-emoticon feature ...

Edit:  Ahh.. I guess key to supressing the icons is the extra "-". 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 16, 2009 Apr 16, 2009

Copy link to clipboard

Copied

and who benefits from my saddle sores

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 19, 2009 Apr 19, 2009

Copy link to clipboard

Copied

PaulH wrote:

and who benefits from my saddle sores

Umm... I really could not say 😉  I think I will take the knowledge and leave the rest alone.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 19, 2009 Apr 19, 2009

Copy link to clipboard

Copied

actually here's a tip for saddle sores 😉

grease up your chamois too....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 16, 2009 Apr 16, 2009

Copy link to clipboard

Copied

Yes, I've seen this before: speak about something everyone avoids and you become the "expert" forever.  Thanks for volunteering!

The ColdFusion server (my desktop computer) is located a little south of San Francisco, -08:00 from GMT during standard time, -07:00 from GMT during daylight-savings (or "summer") time.  The second example contained a typo; here is the correct version:

<cfwddx action = "wddx2cfml"

        input  = "<wddxPacket version='1.0'><header/><data><dateTime>2006-08-20T00:00:00-07:00</dateTime></data></wddxPacket>"

        output = "s__WddxDate" />

<cfoutput>WDDX: #s__WddxDate#</cfoutput>

For me, it returns

WDDX: {ts '2006-08-19 23:00:00'}

which is wrong; WDDX is using -08:00 (standard time) for the GMT offset, turning midnight into 11PM.

I don't think I mentioned it before but WDDX works correctly if I change the month to be in standard time.  For example, 2006-11-20T00:00:00-08:00 works perfectly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 16, 2009 Apr 16, 2009

Copy link to clipboard

Copied

ok before we go any further lets confirm that your tz is actually PST, what's

the result of this snippet?

<cfscript>

tz=createObject("java","java.util.TimeZone").getDefault().getDisplayname(true,0);

writeoutput("#tz#");

</cfscript

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2009 Apr 17, 2009

Copy link to clipboard

Copied

PaulH wrote:

ok before we go any further lets confirm that your tz is actually PST, what's

the result of this snippet?

tz=createObject("java","java.util.TimeZone").getDefault().getDisplayname(true,0) ;

writeoutput("#tz#");

</cfscript

That code prints

PDT

which is correct - we don't return to PST until the end of October.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 18, 2009 Apr 18, 2009

Copy link to clipboard

Copied

actually that's weird, there is no tz ID of "PDT" (at least on the windows &

ubuntu servers i tested). when i tried to set the ubuntu server's JVM to "PDT"

via the setDefault() method it didn't throw an error but actually set the tz to

UTC. how did you set the tz? from the OS (btw what OS)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 19, 2009 Apr 19, 2009

Copy link to clipboard

Copied

Good morning, Paul.

The Time Zone tab of the Date and Time Properties dialog box shows (GMT-08:00) Pacific Time (US & Canada).  On the Date & Time tab, I see Current Time Zone: Pacific Daylight Time.  The System Properties dialog box says I'm running Windows XP Professional, Version 2002, Service Pack 2.  Although it has no effect on the date I used, the Daylight Savings Time patch was installed back in 2007.

I checked my wife's and my own XP computers (identical to each other yet very different from my work computer) and they too show those exact same settings.

On XP, you can't set the "PDT" timezone; you select ...Pacific Time... and then check the box Automatically adjust clock for daylight savings changes.  I'm sure it's not a real timezone ID but simply a convenient way of saying "Pacific time zone during daylight savings time".

This script

<cfscript>
tz_Default  = createObject( "java", "java.util.TimeZone" ).getDefault();
l__Now      = createObject( "java", "java.util.Date"     ).getTime();
writeoutput( "ColdFusion server's time zone name (including DST): #tz_Default.getDisplayName( true,  0 )#<br/>" );
writeoutput( "ColdFusion server's time zone name (excluding DST): #tz_Default.getDisplayName( false, 0 )#<br/>" );
writeoutput( "ColdFusion server's offset from GMT during standard time: #tz_Default.getRawOffset() / 1000 / 60# minutes (or #tz_Default.getRawOffset() / 1000 / 60 / 60# hours)<br/>" );
writeoutput( "ColdFusion server's adjustment for daylight savings time: #tz_Default.getDSTSavings() / 1000 / 60# minutes<br/>" );
writeoutput( "ColdFusion server's offset from GMT during daylight savings time: #tz_Default.getOffset( l__Now ) / 1000 / 60# minutes (or #tz_Default.getOffset( l__Now ) / 1000 / 60 / 60# hours)<br/>" );
</cfscript>

produces this:

ColdFusion server's time zone name (including DST): PDT
ColdFusion server's time zone name (excluding DST): PST
ColdFusion server's offset from GMT during standard time: -480 minutes (or -8 hours)
ColdFusion server's adjustment for daylight savings time: 60 minutes
ColdFusion server's offset from GMT during daylight savings time: -420 minutes (or -7 hours)

since we are currently in DST.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 19, 2009 Apr 19, 2009

Copy link to clipboard

Copied

ah yes, i forgot the displayname() method option for DST. sorry about that. let me think about the tz math one last time before we call this a bug & tell adobe.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 20, 2009 Apr 20, 2009

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2009 Apr 21, 2009

Copy link to clipboard

Copied

Didn't catch that, Paul.  Try Caps Lock - my hearing isn't what it used to be.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 21, 2009 Apr 21, 2009

Copy link to clipboard

Copied

sorry it was a test to show adobe that email replies w/quotes show up blank in

the forums.

i'll be submitting the wddx DST issue to adobe as a bug. in the meantime you'll

probably have to workaround it. i guess test if the date is in DST & adjust it

back once it's converted from wddx.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 22, 2009 Apr 22, 2009

Copy link to clipboard

Copied

pbyhistorian wrote:

Didn't catch that, Paul.  Try Caps Lock - my hearing isn't what it used to be.

I am liking this thread.  You guys found a bug and ... your replies are cracking me up here.  Productive and entertaining 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation