[Catalyst] User timezones

Carl Johnstone catalyst at fadetoblack.me.uk
Thu Jun 25 14:55:17 GMT 2009


Devin Austin wrote:
> you could simply create a column and add the GMT offset.

NO!

If you only use GMT offsets you'll just annoy your users anywhere in the 
world that has DST. If that's the only solution don't bother - just use a 
relevant fixed timezone.

Much better to use the Olsen DB timezone names (DateTime supports them).

my $dt = DateTime->new( year => 2009,
                        month => 6,
                        day => 25,
                        hour => 15,
                        minute => 42,
                        time_zone => 'Europe/London');
print $dt->datetime, "\n";
$dt->set_time_zone('America/New_York');
print $dt->datetime, "\n";


As far as the original question - you could pass the user's choice of 
timezone as a parameter when you call the model to request the time. So 
instead of:

$object->creation_date->strftime(' ... ');
$object->creation_date($user->prefs->tz)->strftime(' ... ');

That still allows you to have a model that will work without being part of a 
web request and that is easily testable.

Carl




More information about the Catalyst mailing list