[Dbix-class] Pointless update on a date field

Matt S Trout dbix-class at trout.me.uk
Mon Sep 17 22:03:38 GMT 2007


On Mon, Sep 17, 2007 at 08:26:05PM +0100, Richard Jones wrote:
> Jason Kohles wrote:
> >>How then do I do something like $schema->update( \%form_data ) when 
> >>the user submits a date formatted as '20/12/2000'. How would you do it 
> >>with the US equivalent '12/20/2000'?
> >>
> >As I understand it, you have a date_to_mysql() method that takes a 
> >variety of different date formats and turns them into mysql formatted 
> >dates, what you should probably do is turn that into a 
> >date_to_datetime() method, that returns a DateTime object instead of a 
> >mysql-formatted date.  In my case I just use HTML::FormFu with an 
> 
> Right, all appears to work OK if I use a date_to_datetime() method 
> instead of a date_to_mysql() one. But in one sense I don't really gain 
> much as I still have to manually parse the users' date input to create a 
> datetime object, ie
> 
> instead of date_to_mysql():
> return join '-', Decode_Date_EU($date);
> 
> 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)

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list