[Dbix-class] Re: RFC: Patch for InflateColumn::Datetime to handle invalid date

Eric Waters ewaters at xmission.com
Fri Jun 15 16:46:21 GMT 2007


> Any thoughts?  What would you all like (if anything)
> in terms of a solution for this.  I can get some paid
> time to work on this for us.  Please don't say
> "Postgresql", I don't have that option on this
> contract.

I'm not sure if this is the "best" way to handle it, but it's the way I've handled it.  I don't know the best way to handle the error; I think I would rather see it return undef even though as has been mentioned MySQL isn't consistent on wether it's null or not.  I think the alternative would be to return a pseudo-DateTime object that represents "0000-00-00" in some way.

@@ -62,11 +63,21 @@ sub register_column {
         {
           inflate => sub {
             my ($value, $obj) = @_;
-            $obj->_datetime_parser->$parse($value);
+                       return undef if ! defined $value;
+
+                       my $dt;
+                       eval { $dt = $obj->_datetime_parser->$parse($value) };
+                       #cluck $@ if $@;
+                       return $dt;
           },
           deflate => sub {
             my ($value, $obj) = @_;
-            $obj->_datetime_parser->$format($value);
+                       return $value if ! $value || ! ref($value);
+
+                       my $str;
+                       eval { $str = $obj->_datetime_parser->$format($value) };
+                       #cluck $@ if $@;
+                       return $str;
           },
         }
     );



More information about the Dbix-class mailing list