[CDBI] CDBI and Class::Date

Arshavir Grigorian grigorian at gmail.com
Thu Dec 6 09:24:28 GMT 2007


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.



More information about the ClassDBI mailing list