We have a large project that we would like to use our "local" time zone
across many calls to DateTime. We are considering implementing something
like this:

###
package DateTimeX::Local;
use parent 'DateTime';

# Calculate and cache the local time zone based on the OS.
our $LocalTZ = DateTime::TimeZone->new( name => 'local' );

sub new { shift->SUPER::new( time_zone => $LocalTZ, @_ ) };
sub now { shift->SUPER::now( time_zone => $LocalTZ, @_ ) };
###

This works for us, but there are probably some other places where
'floating' is the default time zone... I see that 'floating' is
hard-coded in a few places as the default time zone.

It seems like a useful alternate design might be add this class method:

 DateTime->DefaultTimeZone($tz);

... and refactor to use that instead of the hardcoded value of
'floating' everywhere.

We could then stick a call to DateTime->DefaultTimeZone somewhere, and
developers could go on using DateTime as usual for the most part.

The problem with the DateTimeX::Local solution is that someone could
slip up and use DateTime directly, and everything would work until...
after 7 or 8pm Eastern Time. :) . Also, the approach would break if a
new location in DateTime was added that also used the 'floating' default
as a hard-coded value.

What do you think about the best way to set the time zone to "local"
across a large project?

   Mark




Reply via email to