Ad Class::Date
[prev]
[thread]
[next]
[Date index for 2004/04/23]
This is in response to Jeremy Seitz' last posting about Class::Date.
I played around a bit with it and found it fits my needs. If
you're happy with MySQL's date format, all you need is:
Using Class::DBI, version 0.95
package Foo;
[snap]
Foo->has_a( date => 'Class::Date' );
It worked fine without specifying inflate() and deflate(). Later on:
package main;
use Foo;
use Class::Date;
Foo->create({ date => Class::Date->now });
...
my $row = Foo->retrieve($id);
my $date = $row->date;
In string context the $date object get's automatically stringified.
If you want a different output format, change the has_a() to something like:
Foo->has_a( date => 'Class::Date',
inflate => sub { # German date format
$Class::Date::DATE_FORMAT = "%d.%m.%Y - %H:%M:%S";
Class::Date->new(shift) }
);
Bodo
|
Ad Class::Date
Bodo Schulze 20:58 on 23 Apr 2004
|