8 Replies Latest reply on Aug 17, 2011 1:33 AM by SOGC

    Daylight Savings Time Issue

    SOGC

      We have an app built with the Flex 4.0 SDK that's communicating with a C# DLL via WebOrb.

       

      Certain dates are coming back different than they are in C#.  For example:

       

       

      In our C# code we have a date of 12/20/2012 12:00:00AM.  After this date is passed to Flex it shows "Wed Dec 19 23:00:00 GMT-0800 2012". This is inaccurate as it's subtracting an hour from the C# date.

       

      When we change the C# date to 8/19/2011 12:00:00AM it's then shown in Flex as "Fri Aug 19 00:00:00 GMT-0700 2011".  This is correctly converting the date.

       

      The problem is for a date of 12/20/2012 Flex is showing an incorrect date of 12/19/2012.

       

      How can we ensure that the dates passed through WebOrb are unchanged and shown exactly as they are in our C# DLL?

        • 1. Re: Daylight Savings Time Issue
          SOGC Level 1

          After researching the forums it looks like this is an issue a lot of people have and apparently it's a bug in Flex that hasn't been fixed for years.

           

          There must be some way to pass DateTimes exactly as they are in C# to Flex without any modification (for daylight savings time or anything else).

           

          If there isn't a way to turn it off is there a way to determine whether there's been an adjustment and compensate for it?

          • 2. Re: Daylight Savings Time Issue
            tooMuchTrouble Level 3

            On 8/17/2011 12:12 PM, SOGC said:

             

            After researching the forums it looks like this is an issue a lot of people have and apparently it's a bug in Flex that hasn't been fixed for years.

             

            i wouldn't call this a bug, just the way the flash client has always behaved. if

            i have client apps & servers in different TZ i always pass around java epoch

            offsets & have the server/client convert to their TZ as needed.

             

            flex:

            // convert from epoch to local date

            localDate=new Date(epochOffsetFromServer*1.0);

             

            // convert from local date to epoch to send back to server

            epochOffsetLocal=localDate.getTime();

             

            sorry don't know webOrb to show you how to do this server side (though i can

            tell you how to do this in coldfusion)

             

            btw this is what i18n folks call "timezone hell"

            • 3. Re: Daylight Savings Time Issue
              SOGC Level 1

              // convert from epoch to local date

              localDate=new Date(epochOffsetFromServer*1.0);

               

              What is epochOffsetFromServer?  Is this the Date object returned from the C# DLL (through WebOrb)?  Wouldn't multiplying it by 1.0 just leave it as the same value?

              • 4. Re: Daylight Savings Time Issue
                tooMuchTrouble Level 3

                On 8/17/2011 1:14 PM, SOGC said:

                What is epochOffsetFromServer?  Is this the Date object returned from the C#

                 

                uh, its a server side date that's been converted to epoch offset.

                 

                DLL (through WebOrb)?  Wouldn't multiplying it by 1.0 just leave it as the

                same value?

                 

                just to make sure it's a Number (had an issue once where Date() didn't like int

                coming from the server).

                • 5. Re: Daylight Savings Time Issue
                  SOGC Level 1

                  Ok so I tested the statement you suggested (but I need to add a Number() around the date being converted otherwise it threw an error):

                   

                  Alert.show(member.PrescriptionExpirationDate.toString() + " : " + (new Date(Number(member.PrescriptionExpirationDate) * 1.0)).toString());

                   

                  The alert box is showing the exact same date for both values.  I'm not really sure what the statement you provided was meant to accomplish.

                   

                  I found this post:

                   

                  http://www.axelscript.com/2008/02/20/timezone-issues-with-remote-datetime-data-and-flash/

                   

                  With this comment that seems to be the best solution I've found so far:

                   

                  hi guys, ive been working on this problem for a long time  as well and it seems ridiculous that there is not some setting you can  toggle to tell the Flex application NOT to convert based on a client’s  timezone. Anyways, the best workaround for us was actually to return all  our date/time values from our database results as String values in the  proper ActionScript Date format. In this case “Jan 1 2008 10:00 AM”,  there are other formats.

                  Once it comes in, we loop over the results and just set them into Date objects within an array collection:

                  for (var k:int = 0; k < DataFromServer.length; k++) {

                  //convert from string to date

                  DataFromServer[k].dateTimeVariable= new Date(DataFromServer[k].dateTimeVariable);

                  }

                  This works and on 5000+ records seems to not notice much of a  performance hit. Im sure if you had 40k you might have a problem. But  for us this allows us to keep date/time objects in Flex without having  to worry about the Flash engine compensating for time zones and DST!

                  Hope this helps someone.

                  • 6. Re: Daylight Savings Time Issue
                    tooMuchTrouble Level 3

                    On 8/17/2011 1:49 PM, SOGC said:

                    >

                    Alert.show(member.PrescriptionExpirationDate.toString() + " : " + (new Date(Number(member.PrescriptionExpirationDate) * 1.0)).toString());

                     

                    The alert box is showing the exact same date for both values.  I'm not really sure what the statement you provided was meant to accomplish.

                     

                    well one thing it proves is that you're not paying attention. you want to pass

                    epoch offsets (ie ms since 1-jan-1970) NOT Dates back & forth.

                     

                    DST changes will eventually bite you if you're using strings instead of epoch

                    offsets (or whatever method used that actually accounts for them).

                    • 7. Re: Daylight Savings Time Issue
                      SOGC Level 1

                      Ok so I think I've found a solution.  To be clear my intention is to keep the all of DateTime's stored in the DB for a specific timezone (depending on where the clients' location is).  I specifically want the DateTime in the DB to reflect the date of the client's timezone.  Then, regardless of what timezone they log in from, I want them to see the dates that match their timezone.

                       

                      My web server's timezone is Mountain Time, and it looks like Flex automatically converts the DateTimes from Mountain Time to whatever timezone the client is in.  So, by doing some trial and error, I've been able to "scrub" the returned Date object in Flex like this:


                                          if (member.PrescriptionExpirationDate.getTimezoneOffset() != 420.0)
                                          {
                                              var tzOffset:Number = member.PrescriptionExpirationDate.valueOf() +
                                                      ((member.PrescriptionExpirationDate.getTimezoneOffset() - 420.0) * 60000);
                                              var newDateValue:Date = new Date(tzOffset);
                                          }

                       

                      Where newDateValue will now reflect the exact same date as was passed from the DB.  I tested with the following scenarios:

                       

                      Laptop timezone setting: Pacific

                      Flex Client App timezone setting: Pacific

                       

                      Laptop timezone setting: Eastern

                      Flex Client App timezone setting: Pacific

                       

                      Laptop timezone setting: Pacific

                      Flex Client App timezone setting: Eastern

                       

                      Laptop timezone setting: Eastern

                      Flex Client App timezone setting: Eastern

                       

                      Laptop timezone setting: Hawaiian

                      Flex Client App timezone setting: Pacific

                       

                      Laptop timezone setting: Pacific

                      Flex Client App timezone setting: Hawaiian

                       

                      Laptop timezone setting: Hawaiian

                      Flex Client App timezone setting: Hawaiian

                       

                      Laptop timezone setting: Hawaiian

                      Flex Client App timezone setting: Eastern

                       

                      Laptop timezone setting: Eastern

                      Flex Client App timezone setting: Hawaiian

                       

                      In all of the scenarios above the newDateValue reflected EXACTLY what was in our DB.  It was in the client's timezone but reflected the exact date at 12:00:00AM as it should.

                       

                      The next step would be to figure out how to get in front the WebOrb data serialization and "scrub" the date at that point before it even hits the Flex app.  Alternatively, I can loop through all of the data once it hits the Flex app and change the date manually - I'd need to do this in multiple places so it'd be best just to do it before the data is sent to the Flex app.

                      • 8. Re: Daylight Savings Time Issue
                        SOGC Level 1

                        How do I pass the epoch offsets from C# (instead of the actual DateTime)?  And if my WebOrb object classes already contain DateTimes, would I need to change the data types to double (or something similar) to pass the offsets?