added cookbook example for localtime.
Marcus Ramberg [Thu, 3 Mar 2005 13:10:40 +0000 (13:10 +0000)]
lib/Catalyst/Manual/Cookbook.pod

index 7902a60..2bf2840 100644 (file)
@@ -142,7 +142,8 @@ If you store datetime data in your tables, you can easily expand this column to
 a L<Time::Piece> 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<Time::Piece> and L<Class::DBI> docs for more info.