Re: [Catalyst] DateTime Timezone
Zitat von Nilson Santos Figueiredo Junior <[EMAIL PROTECTED]>: > I ended up creating a InflateColumn::DateTimeHack which sets the > timezone when inflating. > It's not the prettiest thing, but it works and saves painful manual > (de|in)flating in every schema class. Yes, that's exactly what came to my mind as a solution. Funny, that every time I start hacking with Catalyst I come across everyday problems for which there don't seem any clean solutions yet :( I suppose that's the drawback of having the freedom to choose one of the thousands of cpan modules for every given task: You have to make 'em interact in a sane way ... :) --Tobias ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] DateTime Timezone
On 12/15/06, Tobias Kremer <[EMAIL PROTECTED]> wrote: Hmm ... There must be a better way of dealing with DateTime, timezones and MySQL ... I ended up creating a InflateColumn::DateTimeHack which sets the timezone when inflating. It's not the prettiest thing, but it works and saves painful manual (de|in)flating in every schema class. -Nilson Santos F. Jr. ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] DateTime Timezone
Zitat von Chisel Wright <[EMAIL PROTECTED]>: > I tend to use the following in my schema classes to deal with timestamps > in my app(s): Yes, that's also what the DBIx::Class::InflateColumn::DateTime component which I'm using for this purpose does: http://search.cpan.org/~bricas/DBIx-Class-0.07003/lib/DBIx/Class/InflateColumn/DateTime.pm Unfortunately I just found out that DateTime::Format::MySQL::parse_datetime returns dates in the floating timezone (not UTC). Thus I'll now have to revert to manual inflation to set_time_zone( 'UTC' ) on the date objects or subclass D::F::MySQL :( Hmm ... There must be a better way of dealing with DateTime, timezones and MySQL ... Ideas are very welcome :) -- Tobias ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] DateTime Timezone
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: [EMAIL PROTECTED] w: http://www.herlpacker.co.uk/ This is not an automated signature. I type this in to the bottom of every message. ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] DateTime Timezone
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? Thanks! -- Tobias ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/