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
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]