[Dbix-class] Pointless update on a date field

Richard Jones ra.jones at dpw.clara.co.uk
Tue Sep 18 22:05:14 GMT 2007

Matt S Trout wrote:
>> I have:
>> my ($yr, $month, $day) = Date::Calc::Decode_Date_EU($date);
>> return DateTime->new( year => $yr, month => $month, day => $day);
> There's almost certainly a DateTime::Format module that'll do better than
> that - the strptime one for a start. Trying to use Date::Calc stuff to get
> to DateTime objects is always going to be more work since you're now hand
> linking two separate projects with incompatible APIs.
> I often use Time::ParseDate which gets me an epoch value then construct a
> DateTime object from that (and it'll usually DWIM however the date's supplied)

Time::ParseDate works nice, providing dates are >= epoch (1970-01-01). 
But it's not much use for dates of birth, at least for an adult 
population. For a date before 1970, Time::ParseDate parsedate() does 
generate the $no_of_seconds_since_epoch (a negative number), but 
DateTime->from_epoch( epoch => $no_of_seconds_since_epoch ) dies as it 
seems unable to handle a negative number of seconds.

DateTime::Format::Strptime *can* handle dates before the epoch, but it 
needs the date pattern specifying, thus lacking the flexibility provided 
by Date::Calc::Decode_Date_EU.

So, it seems Date::Calc is a better option for generating a DateTime 
object from a form field where the user is not restricted to a 
particular date format.
Richard Jones

More information about the DBIx-Class mailing list