Re: [CDBI] CDBI and Class::Date
"Arshavir Grigorian" <[email protected]> Wed, 12 Dec 2007 02:56:42 -0800
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
On Dec 6, 2007 1:24 AM, Arshavir Grigorian <[email protected]> wrote: > Hi, > > I have a db field of type "timestamp with time zone" (Postgres). I > also have a CDBI class for that table which uses Class::Date, like so: > > __PACKAGE__->has_a (last_update_dt => 'Class::Date', > inflate => sub { > $Class::Date::DATE_FORMAT = "%a - %b %d, %Y %H:%M"; > Class::Date->new(shift) }, > deflate => 'string'); > > Regardless of what the db connection's timezone is set to, the > Class::Date object is created with tz UTC, which is incorrect since > the date returned is in each user's timezone. To remedy this, I do > > $new_date = $db_row->last_update_dt->clone(tz => $correct_tz); > then > $gmt_date = $new_date->to_tz('UTC') > > The main issue though is that calling to_tz('UTC') has no effect and I > am not sure why. When Dump-ing $gmt_date date, the timezone is UTC, > but everything else is the same as in $new_date. However, if instead > of reading the date from the database, I use Class::Date::now(), > things work as advertised, but there is something wrong with operating > on dates from the database. > > Ultimately, I would like to calculate the difference in minutes > between the date/timestamp in the database and now, which I think is > best done when all timestamps are in UTC. > > I would appreciate any explanation for this weird behavior. > Here is more information if that helps.I tried setting/hardcoding the timezone in the code explicitly but still no go. The object is still created as UTC. __PACKAGE__->has_a (last_update_dt => 'Class::Date', inflate => sub { $Class::Date::DATE_FORMAT = "%a - %b %d, %Y %H:%M"; Class::Date->new(shift, 'PST') }, # also tried 'America/Los_Angeles deflate => 'string'); I checked $ENV{'TZ'} and it was not set. Since all my users can have different timezones, I set the appropriate timezone on the database connection before handling each request and I would ideally like to use that time zone when creating the Class::Date object. By the way, couldn't subscribe to the Class::Date mailing list but the website seems to be out of commission. TIA. _______________________________________________ ClassDBI mailing list ClassDBI-Ra3b/[email protected] http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi