From: Marcus Ramberg Date: Thu, 3 Mar 2005 13:10:40 +0000 (+0000) Subject: added cookbook example for localtime. X-Git-Tag: 5.7099_04~1785 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=3e53f0cdd06d090d5d93dd085dce0889ddd2ad02 added cookbook example for localtime. --- diff --git a/lib/Catalyst/Manual/Cookbook.pod b/lib/Catalyst/Manual/Cookbook.pod index 7902a60..2bf2840 100644 --- a/lib/Catalyst/Manual/Cookbook.pod +++ b/lib/Catalyst/Manual/Cookbook.pod @@ -142,7 +142,8 @@ If you store datetime data in your tables, you can easily expand this column to a L object which lets you call useful methods like ymd, mon and datetime on it. -In order to set it up, add something like the following to your CDBI Model Class: +In order to set it up, add something like the following to your CDBI Model Class, +if you are storing dates as ISO timestamps: __PACKAGE__->has_a( mycolumn => 'Time::Piece', @@ -150,6 +151,14 @@ In order to set it up, add something like the following to your CDBI Model Class deflate => 'datetime' ); +or if you prefer to store dates in unix epoch time you can do something like this: + + __PACKAGE__->has_a( + mycolumn => 'Time::Piece', + inflate => sub { Time::Piece->strptime( shift, "%s" ) }, + deflate => 'epoch' + ); + If you want to use another format in the database, you can change the strptime call to fit your format, and use strftime to return it with your custom format to the database during deflate. See the L and L docs for more info.