25 Replies Latest reply on Apr 22, 2009 12:52 PM by pbyhistorian

    WDDX (de)serializes dateTime with wrong DST rules?

    pbyhistorian

      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?

        • 1. Re: WDDX deserializes dateTime with wrong DST rules?
          pbyhistorian Level 1

          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'}

           

           

           

           

           

          • 2. Re: WDDX (de)serializes dateTime with wrong DST rules?
            tooMuchTrouble Level 3

            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.

            • 3. More fun with Coldfusion dates
              pbyhistorian Level 1

              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.

              • 4. Re: More fun with Coldfusion dates
                -==cfSearching==- Level 4

                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.

                1 person found this helpful
                • 5. Re: WDDX (de)serializes dateTime with wrong DST rules?
                  tooMuchTrouble Level 3
                  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

                  • 6. Re: WDDX (de)serializes dateTime with wrong DST rules?
                    -==cfSearching==- Level 4

                    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.)

                    • 7. Re: WDDX (de)serializes dateTime with wrong DST rules?
                      pbyhistorian Level 1

                      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.

                      • 8. Re: WDDX (de)serializes dateTime with wrong DST rules?
                        tooMuchTrouble Level 3

                        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...

                        • 9. Re: WDDX (de)serializes dateTime with wrong DST rules?
                          -==cfSearching==- Level 4

                          {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.

                          • 10. Re: WDDX (de)serializes dateTime with wrong DST rules?
                            tooMuchTrouble Level 3

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

                            • 11. Re: WDDX (de)serializes dateTime with wrong DST rules?
                              -==cfSearching==- Level 4

                              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 "-". 

                              • 12. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                pbyhistorian Level 1

                                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.

                                • 13. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                  tooMuchTrouble Level 3

                                  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

                                  • 14. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                    tooMuchTrouble Level 3

                                    and who benefits from my saddle sores

                                    • 15. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                      pbyhistorian Level 1

                                      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.

                                      • 16. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                        tooMuchTrouble Level 3

                                        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)?

                                        • 17. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                          -==cfSearching==- Level 4

                                          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.

                                          • 18. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                            pbyhistorian Level 1

                                            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.

                                            • 19. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                              tooMuchTrouble Level 3

                                              actually here's a tip for saddle sores ;-)

                                               

                                              grease up your chamois too....

                                              • 20. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                                tooMuchTrouble Level 3

                                                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.

                                                • 22. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                                  pbyhistorian Level 1

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

                                                  • 23. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                                    tooMuchTrouble Level 3

                                                    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.

                                                    • 24. Re: WDDX (de)serializes dateTime with wrong DST rules?
                                                      -==cfSearching==- Level 4

                                                      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 ;-)

                                                      • 25. Re: WDDX deserializes dateTime with wrong DST rules?
                                                        pbyhistorian Level 1

                                                        Why thank you, cfSearching - that was kind.  Sadly, I am far, far better at code than humor (and my code isn't stellar).

                                                         

                                                        Paul, a friend showed me a workaround at cflib.org but mine was a little shorter:

                                                        Web Service side ("sb_" = java.lang.StringBuffer; "dt_" = java.util.Date)

                                                        df_Wddx = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" );

                                                        ...

                                                        sb_WddxPacket.append( "<var name='s__Begins'> );

                                                        sb_WddxPacket.append( "     <string>" + df_Wddx.format( dt_Begins ) + "</string>" );

                                                        sb_WddxPacket.append( "</var>" );

                                                        ...

                                                        return sb_WddxPacket.toString();

                                                        ColdFusion side ("st_" = Structure; "dt_" = DateTime)

                                                        <cfinvoke component      = "WebService"
                                                                  returnvariable = "st_WddxPacket"
                                                                  ... />

                                                        <cfset df_Wddx   = CreateObject( "java", "java.text.SimpleDateFormat" ) />
                                                        <cfset df_Wddx.applyPattern( "yyyy-MM-dd'T'HH:mm:ssZ" ) />
                                                        <cfset dt_Begins = df_Wddx.parse( st_WddxPacket.s__Begins ) />

                                                         

                                                         

                                                        It ignores the colon that's supposed to be in the timezone offset but, since Java is talking to Java, it's OK.

                                                         

                                                         

                                                         

                                                        Thanks for submitting the bug for me!