Ad Class::Date

[prev] [thread] [next] [Date index for 2004/04/23]

From: Bodo Schulze
Subject: Ad Class::Date
Date: 20:58 on 23 Apr 2004
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

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52