Greetings all,

Been fighting with this, can't figure out the answer, and going mad.  I am
storing all times and dates in a database in UTC (GMT) format, to properly
show users the time according to their time zone, and allow the server to be
(re)located anywhere in the world without having to change code or data.
Ignore Daylight Savings Time considerations for this example (though if you
have any suggestions, I am all ears!) -- I have not had the chance to even
think about DST yet.

1.  The user fills out a form.  When they submit, a hidden form field is
populated with the user's current system time and date, using javascript.
Since Javascript calculates the months from 0 to 11, I add ONE to the month
at the time I create the timestamp.

2.  The form submits to a page which converts the current CF Server time to
an ODBCDateTime in UTC.  The User's hidden time field is also converted to
an ODBCDateTime format.

3.  The different between the user's timestamp on their machine, and the UTC
according to the server creates the Time Zone Offset for that user -- their
actual TIME ZONE.

As a real-world example:

--  Assume that the Server and the User both use a utility which maintains
synchronization with time servers on the Internet; therefore the two systems
are within milliseconds of Atomic Time.
--  On March 30th, 2001, a user in NY submits a form at 7am EST, on a server
in California (4am PST).
--  The software calculates the current UTC time as being 12:00:00PM (4am CA
time is 12 noon GMT/UTC).
--  The difference between the user's time (3/30/2001 4:00:00am) and UTC
(12:00:00PM) is -8 hours, which is absolutely correct; we know the user is
in PST because of this difference.

NOW!:  The code snippet below shows the CF Code that calcuates the
difference between the user's time and UTC.  However, if you run this code,
you will NOT get a difference of - 8 hours, but instead, -7 hours.  If you
increment UTC by at least one second, it then calculates the timezone
properly; but one cannot assume that the user and the server will always be
out of synch... although it is most likely a certainty, I do not wish to
assume anything.

I also do not wish to make the user choose their time zone on the form; I
really wanted this to be automatic.

Here is the code:

<CFOUTPUT>
        <CFSET TestUTCNow = CreateODBCDateTime("3/30/2001 12:00:00")>
        <CFSET TestUserTime = CreateODBCDateTime("3/30/2001 4:00:00")>
        <CFSET UserTZOffset = DateDiff("h", TestUTCNow, TestUserTime)>
        User's TimeZoneOffset = #UserTZOffset#  <!--- This SHOULD be -8, but is
only -7! Unless, you make UTCNow equal to "3/30/2001 12:00:01" --->
</CFOUTPUT>

Has anyone solved this problem, or have a different way of putting the
user's timezone into the database, including DST issues?

Thanks in advance,

.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Marc Funaro, President
Advantex Technical Consulting Services
5547 State Highway 12
Norwich, NY 13815
Phone:  607-336-6895
Fax: 801-383-4864
Internet: http://www.advantex.net
Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to