Flex Pasta » 2010 » January

I wake up to the phone ringing.  I check the clock: 2:30 A.M on January 5th.  Groggy and dizzy I answer the phone.  It is my brother.  I am in Cincinnati(Eastern Time) and he lives in San Fransisco(Pacific Time).  “Why are you calling me at 2:30 in the morning”, I ask him.  “It’s only 11:30 P.M. here”, he says,  “and I am calling to tell you that I am father to a baby boy named Johnny!”.  “Congratulations!!”, I tell him.  We chat a bit more and then hang up.  The whole family is excited.  We had all placed bets on which day little Johnny would be born.  I had picked January 5th.  “Yes!!!”, I say.  I have won.  Or have I??  Johnny is born on January 5th eastern time, but January 4th pacific time.  So who wins?  Johnny’s birth date of record is January 4th.  But when was he born?  The answer to that depends on where I am.

Flex and Timezones

Assume now the nurse is entering the date and time of birth(when the baby is born) in the Flex baby tracker application: Jan. 4, 11:30 PM Pacific.  Also assume that the developer has coded the app to use a Date object in Flex, and java.util.Date in the Java remote class and that the application servers sits in Cincinnati(eastern time).  When the nurse saves the record, AMF will transfer over the date object as milliseconds since 1970.  When it hits the server in eastern time, the date is now stored as 2:30 AM January 5th.  If the nurse wanted to record the birth date, then as a developer, I would not want to use a date. In this instance, the date should be January 4th, globally, regardless of location or timezone.  A string or integer value should be used.  A Flex mx:DateChooser component is dangerous.  If the nurse picks a birthdate in a mx:DateChooser, the date would be created locally on the client pc as Jan 4th, 2010 at midnight(00:00:00).  When transferred to a server in eastern time, this date would become Jan 4th, 2010 at 3AM.  This is not what we want.  Someone in Hawaii viewing this baby record would get the date Jan 3rd, 2010 at 10PM.  The birth date January 4th should appear globally to anyone the same way.

Solution:

Option 1 - Have the date chooser covert the value to a string like 01-04-2010 and then transfer the value to the server and store it as a string.  This would ensure it globally being January 4th.

Option 2 - Option 1 has a problem: How do I do a query for all birthdays in January?  A little tricky with a string variable.  Option 2 is to covert the date chooser value to an integer in the form yyyymmdd(20100104). The date is transferred and stored in the database as an integer.  Doing this makes it easier to query.  For example, select * from baby where birthdate > 20100101 and birthdate < 20100131.  The data still keeps the integrity for greater than and less than operations.

Have a headache yet?  Go take some Tylenol:)