[Catalyst] DateTime Timezone
Chisel Wright
chisel at herlpacker.co.uk
Fri Dec 15 10:08:06 GMT 2006
On Fri, Dec 15, 2006 at 10:34:35AM +0100, Tobias Kremer wrote:
> My application stores all dates in a MySQL database in the UTC timezone.
> Because I'm doing further calculations with these dates after retrieving them
> via DBIx::Class I don't want them to get auto-inflated into the timezone
> of the current user. The DateTime POD recommends doing date calculations only
> with dates of the same timezone and having everything in UTC should make
> things work like they're supposed to work (I hope).
>
> I think the DateTime objects should only be converted for displaying purposes
> (i.e. when they're going to be displayed in a TT template). Is that correct?
> If so, what's the best way (and where's the best place) to achieve this
> conversion?
I tend to use the following in my schema classes to deal with timestamps
in my app(s):
package MyApp::Schema::TableName;
use DateTime::Format::Pg;
# ...
foreach my $datecol (qw/created last_modified/) {
__PACKAGE__->inflate_column($datecol, {
inflate => sub { DateTime::Format::Pg->parse_datetime(shift); },
deflate => sub { DateTime::Format::Pg->format_datetime(shift); },
});
}
I'm sure it's not all that different for MySql;
http://search.cpan.org/~drolsky/DateTime-Format-MySQL/
Chisel
--
Chisel Wright
e: chisel at herlpacker.co.uk
w: http://www.herlpacker.co.uk/
This is not an automated signature.
I type this in to the bottom of every message.
More information about the Catalyst
mailing list