For all the time I've been hosting my own sites, I have been hosted on
servers in different time zones to my own.   So i have adopted a practice as
follows:

[A] I never use now()
[B] i have a request variable called request.austime set in the
application.cfc  which is the current local time in Sydney.
[C] request.austime is based on the server clock, adjusted for the timezone
offset, returned by the excellent cfc timezone.cfc.
[D] timezone.cfc accesses the java routines that provide the timezone info,
including daylight savings etc.

Using this technique, the same code works on my dev machine which is sitting
in my own timezone, and on a site i have at fasthit in perth, western
australia, and on my shared hosting on servers in california.  And except in
the one case where the java timezone routines didnt keep up with the
political changes of timezones here in NSW, the time automatically changes
to and from daylight savings correctly.   The only hiccup i'd say I found is
that because of the time differences between Australia and California,  the
Californian based sites dont recognise the switch to/from daylight savings
time till about 2pm the following day, rather than at 2am on the day.

The code I use in my application.cfc is as follows:

<cfset timezonecfc = createobject("component","cms.cfcs.utilities.timezone")
/>
<cfset hometimezone ="Australia/Sydney" />
<cfset request.austime = Timezonecfc.castFromServer(now(), hometimezone   )
/>

As long as the server clock doesn't wander too far from actual time,
everything else flows through the site where i need it.  In audit records in
teh tables,  i use #createodbcdatetime(request.austime)# or i use
<cfqueryparam value="#request.austime#" cfsqltype="CF_SQL_TIMESTAMP"/>

By preference I'd like the server to connect regularly to an internet time
server to correct its clock so that could keep my site timely to the
millisecond.

But by using this method i dont have to touch anything to do with setting
time or daylight savings from one year's end to the next, regardless of
where the server sits in the world, or whether or not it's set to UTC or
local time or whatever.

Cheers
Mike Kear
Windsor, NSW, Australia
Adobe Certified Advanced ColdFusion Developer
AFP Webworks
http://afpwebworks.com
ColdFusion 9 Enterprise, PHP, ASP, ASP.NET hosting from AUD$15/month

On Fri, May 21, 2010 at 1:24 PM, Rick Root <[email protected]> wrote:

>
> An excellent point!
>
> On Thu, May 20, 2010 at 11:21 PM, Dave Watts <[email protected]> wrote:
> >
> >> Now() is also database independent, which is generally a good thing
> >> IMO =)  Avoid using database-specific code whenever possible unless
> >> said database specific code provides a not insignificant performance
> >> advantage.  I suspect GetDate() vs. Now() is pretty insignificant.
> >
> > Well, actually, I'd recommend the exact opposite in many cases. It's a
> > good thing to centralize time management wherever possible, and you're
> > typically going to have a single database server servicing one or more
> > application servers. Ideally, all of the servers should use the same
> > NTP server, but even so having a single time source in your
> > application is a good thing.
> >
> > Dave Watts, CTO, Fig Leaf Software
> > http://www.figleaf.com/
> > http://training.figleaf.com/
> >
> > Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
> > GSA Schedule, and provides the highest caliber vendor-authorized
> > instruction at our training centers, online, or onsit
>


--


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:333896
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to