Search Flex Components Free

Custom Search

December 7, 2007

Does Flex need to assume AMF3 Date’s are UTC?

Background Information: I've inherited an application that stores many Dates and Times. The software is used by people all over the world who manually enter Dates & Times from worksheets into the software. The information is stored in a SQL Database and all dates and times are stored without any Timezone information and represent all different timezones. Dates from different timezones aren't compared or mixed, so when a report is generated form the database, its assumed the report and its dates and times are relevant to the client.
Many different applications hook into this system and I don't have the luxury of changing anything other than my Flex application to make it match the rest of the system.
My Goal: My Flex application should allow a user to enter a Date and Time, which I store into a Date Type. For example:"11/16/2006 03:00:00 PM" would be entered by a user in Eastern Standard Time (GMT-5)."11/16/2006 03:00:00 PM" would be entered by a user in Pacific Standard Time (GMT-8)."11/16/2006 03:00:00 PM" would be entered by a user in Moscow (GMT+3).
Each of those Dates would be saved in my database as: "11/16/2006 03:00:00 "
My Problem:AMF3 no longer supports a Timezone Offset. See "
AMF3 Specification" at OSFlash.org. I currently can take a Date & Time from my Database -> Backend (.NET in this case) > Gateway (Fluorine in this case) -> AMF3 and in reverse from AMF3 -> Gateway -> Backend -> Database without the Date or Time being modified in any way and without any Timezone information.
The problem is, Flex assumes the AMF3 information is in UTC(GMT). So as soon AMF3 is deserialzed into Flex, the Flex Date is modified to the client's local timezone offset.
What I want is all three of the dates above to show up in Flex, regardless of the client timezone, as "11/16/2006 03:00:00 PM" and I don't want to have to manually display the UTC Date all over my Flex application in order to do this. This would include if the Date is a member in a ValueObject.
My Solution (Work in Progress):Everytime a Date is brought into Flex, I call a function:
PLAIN TEXT
Actionscript:
public static function getUTCDate(myDate:Date):Date
{
return new Date(myDate.fullYearUTC, myDate.monthUTC, myDate.dateUTC, myDate.hoursUTC, myDate.minutesUTC, myDate.secondsUTC, myDate.millisecondsUTC);
}
which is called as
PLAIN TEXT
Actionscript:
flexDate = DateUtil.getUTCDate(flexDate);
Everytime a Date is sent from Flex, I call a function:
PLAIN TEXT
Actionscript:
public static function sendUTCDate(myDate:Date):Date
{
var sDate:Date = new Date(Date.UTC(myDate.fullYear, myDate.month, myDate.date, myDate.hours, myDate.minutes, myDate.seconds, myDate.milliseconds));
return sDate;
}
which is called as
PLAIN TEXT
Actionscript:
flexDate = DateUtil.sendUTCDate(flexDate);
My WishSomething that would make this automatic for me. Either a way to tell the AMF3 Date Deserialization to be saved as a Local Date, or some way to not make me call manually call these functions every time a Date is deserialized or serialized.
Many Thanks to Anyone with Any Ideas!

Related Flex Tutorials