Timezone Issues with remote (Date/Time) data and flash

ApplicationSource

We are wrapping up with this great charting application at cfwebtools, and we get a call from a customer that says our data is wrong….

We listen to them, and debug, and for some reason we just can’t quite see the same thing he see’s… On top of that, no one else is having the problem, but the fact is that, he has showed us screen shots, he’s duplicated on Four pc’s of his own, and he’s talked to 10 friends telling us that our data is wrong, and that there is mismatched days in our chart.

The problem:

When he was bringing up the charting application, the charts showed up successfully, but when you ta

ke a closer look, and you know your stuff about Financial Charting applications, you know what your looking for, and you know it with GREAT detail. So this guy, tells us our data is wrong, and pretty much with all of his friends proved to us SOMETHING was going wrong, but we couldn’t duplicate it.

We tried trapping the data he was requesting when the request came in, we tried trapping it right before it went out… then we were using Kevin Langdon’s Service Capture to introspect the data that was coming in to flex.

The data is not that complicated, it looks like this:

Application – Source

Date: 2/20/08

Close: 31.53

Open: 30.61

Date: 2/19/08

Close: 30.93

Open: 30.94

but on his computer it looked like this:

Date: 2/19/08

Close: 31.53

Open: 30.61

Date: 2/18/08

Close: 30.93

Open: 30.94

EVERYTHING WAS SLID BACK BY ONE DAY.

the Date/Time objects were coming back from coldfusion, and it was returning coldfusion sql. They looked like this:

‘2/20/08 00:00:00’

‘2/19/08 00:00:00’

‘2/18/08 00:00:00’

what was really happening is that, flash auto adjusts for your Timezone… so what was really happening is the data is getting turned into this in flash (if they come back to flash as date/time objects)

Pacific Standard Time

‘2/19/08 22:00:00’

‘2/18/08 22:00:00’

‘2/17/08 22:00:00’

I’m sort of at a loss and i’m looking for help, there is one post that was more clear than the rest, but still doesnt solve my issue, it’s written by Ted Patrick of adobe. He states to use Universal Time, (UTC).

I have a problem with this!

I’m not the one creating the date times, nor do I get a chance to touch the data before it goes to my components… Of course I could obviously go in, to my result function of my remote object, or my command of cairngorm, and loop over the data, and adjust it all manually… BUT NOOOOO, I Don’t want to, what if i’m dealing with 40,000 records in a charting application (how bout we make it an even MILLION records, just to prove a point), then obviously the flash player has enough work to do on it’s own, without me looping through the data.

How do I query my database, and have it be a 00:00:00 time, and not have flash offset my date when it comes back to it?

For now, we manually change things in our query to add hours to the date time, but that is kind of sloppy…

Please check the example, and help me out if you can… Like I said I’m at a loss with this one.

ApplicationSource

8 comments on this post.
  1. kldavis4:

    Axel,

    I am not entirely clear on the issue here. First of all, if you are getting a UTC date from your server, then the data will be correct, assuming it is getting treated as such and not manually parsed into a Date object. If it is UTC, then you would expect to see different times for people in different time zones.

    It sounds like what you really want is that the dates being viewed by the client be displayed as if they come from a specific time zone regardless of the client machine’s operating system time zone setting. I actually ran into this issue with one of my applications. User’s of this application could change their time zone within the application, regardless of what the machine was set to. This works fine on the server side, because we were working with UTC dates and stored a time zone preference which could then be used to display the correct date to the user based on their time zone. When we added our flex app into the mix, it became a problem, though, because if we passed the utc date to the flex app, there was no way to format it based on the user’s time zone, but instead the machine time zone setting. So I came up with a couple of solutions to this problem, none of which is particularly elegant, but I can live with it because I believe they are working around a fundamental flaw in the flash player (ie not being able to configure your time zone from within the vm).

    The first solution is to transform your date/time value into it’s string components, and then parse it into a date object on the client. The server determines the time zone used to get the “display” date (as opposed to utc date), and you send the month, date, year, hour, min, sec, etc fields to the client and it gets re-assembled.

    The second solution is to find the time zone offset of the client and adjust values based on that. You do this by having your client send a specific known date to the server in UTC. You create a date using the , say 01-01-2000 00:00:00:0, using the year,month,date,hour,minute,second,millisecond constructor of the Date object, and then send the UTC value of that date object to the server. The server does the same thing, but using the specific time zone that you are ‘targetting’. Then you get the utc value of this date, and find the difference between it and what the client sent you. This will give you the time zone offset of the client, which you can send back to the client. Then just roll each date that the server sends to the client by this amount.

    This still requires that you touch the data somewhere along the line, either on the server or the client, but there is just no way around it if you want the dates displayed using a time zone other than what the user’s machine is set to.

  2. admin:

    I couldn’t agree with you more on your solutions, I did think about the timezone offset, but the problem is the amount of data we have coming back in the application is too much to touch it and adjust the offset manually…

    unfortunately the date in the db is stored as an sql “smalldatetime” and thats how it comes back, not as UTC, i’ve been told there are built in ms sql functions to do conversions, but have not tried it out…

    so the problem here is really that we’re not storing the dates correctly in the db, but the thing is, almost every application i’ve worked on just uses date/time in sql… because it’s a great solution and covers most issues as far as needing to filter on dates and things like that.

    it is just wierd that flash does that out of the box… i would have thought for it to be the other way around… as in, in order to use the timezone of the local machine it would be a player setting in the html wrapper that you specify…

    anyway… thanks for the comment.

  3. Joss:

    Axel,

    Instead of looping through your data, there is a great post from farata systems, that you might want to consider.
    http://flexblog.faratasystems.com/?p=289
    Hope this helps.

    -Joss.

  4. Pat Buchanan:

    Amen to that. I’ve been fighting this thing for 2 days before I finally figured out that it was being automatically converted for me. In some of my apps, this is great because I’m doing it all manually right now. In others, I *need* the exact date from the server. I don’t care how their computer is setup timezone wise. If I say midnight, I mean midnight.

    And with everyone saying to use UTC – I don’t see the immediate benefit since I’ll have to loop through and edit any data I get from the server anyway.

    If you find a good, easy solution to this, let me know. For now, I’m converting everything over to strings (lucky for me I own the server side as well). Seems like a hack to me.

    Thanks

  5. cardinalweb:

    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. TJ Downes:

    For us, we cast the date as a string at the DB level. Then passed as a string to Flex. At that point we loop over the collections and cast them as Dates. Not elegant but it works. However you still need to be careful when you are casting new Dates as it will then grab the timezoneOffset from the client and becomes apparent when working across DST.

    Overall the Flash player needs to be enhanced in this area. There needs to be built in i18N libraries as well as the ability to force the client timezone or turn off the offsets.

  7. ja4509:

    We ran into the same thing. Somewhere the milliseconds from epoch (Jan. 1st. 1970) was being tinkered with. I find this dangerous as well as unexceptable. When you set a date no matter where it is in the world the millseconds from epoch in UTC should be untouchable. Only the offests from that setting should be tinkered with and a simple boolean should be supplied to turn on and off DST or time zone offsetting. Flex should have a DateFormatter that allows stting the time zone.

    But Flex unlike Java is still a bit raw and needs some maturing.

  8. Jason:

    Add me to the list of people who are annoyed by this “feature” in flex. Working with clients who travel and plan events in multiple time zones is a real problem with Flex. To make matters worse, Adobe seems to have gone to great lengths to insure that there is absolutely no way you can override this behavior by making the Date class final. Using UTC would be acceptable but not a single UI date control in the Flex UI toolkit will use the UTC values. Either of those options would have solved the issue.

    What we have to do is actually have the client provide it’s offset along with every request and the server then makes the adjustment to all date values going in and out.

    Add to the list of other issues is that, at least on our server, a negative timezone offset (London for example) will get converted into an uint instead of a negative number. You have to convert it from uint to int which is yet another annoyance. A clue that this is happening is when people from London start seeing dates in the early 1900’s!

    It would be nice to see some improvement in this area in Flex 4.

Leave a comment