[Dbix-class] InflateColumn::DateTime

Mark Hedges hedges at ucsd.edu
Thu Jun 8 19:32:48 CEST 2006


On Thu, 8 Jun 2006, Christopher H. Laco wrote:
> 
> If the order item and cart item instead load InflateColumn::DateTime,
> all hell breaks loose. If I try copying the raw value, which is a
> DateTime object, I get this what trying to add to a relation:
> 
> > Can't use string ("Handel::Subclassing::OrderSchema") as a HASH ref while "strict refs" in use at F:\CatInABox\extlib/DB
> > Ix/Class/AccessorGroup.pm line 248.
> 
> If I force the copy to eval as a string, I get this error instead:
> 
> > Invalid date format: 2006-06-07T00:00:00 at F:\CatInABox\extlib/DBIx/Class/InflateColumn/DateTime.pm line 57

That date format is the default stringification for DateTime.
MySQL actually seems like it can deal with it, but some DB's can't.

Sounds like this is the case where the routine needs to
do something like I do here in these subrefs that I import
for doing inflate/deflate.  The $dt_fmt_* objects are 
various DateTime::Format-ish objects.

    our $inflate_datetime = sub {
        my $dt = $dt_fmt_mysql->parse_datetime( shift );
        $dt->set_time_zone( $TIME_ZONE );
        $dt->set_formatter( $dt_fmt_us );
        return $dt;
    };

    our $deflate_datetime = sub {
        my ($dt) = @_;

        # maybe we are trying to use a scalar ref to set now() in SQL?
        return $dt if ref $dt eq 'SCALAR';
    
        $dt->set_time_zone( $TIME_ZONE );
        $dt->set_formatter( $dt_fmt_mysql );

        return scalar DateTime::Format::MySQL->format_datetime( $dt );

        # hmm, I think just 'return "$dt";' might work there too
        # since the formatter object has been set... test it
    };

As for writing test code or contributing, it's taken me over
two months just to get a little form field mailer plugin done
for CGI::FormBuilder.  The Los Angeles mantra... "Pay me."  :-)
Sorry, just facts of life right now, I don't have time.

Mark



More information about the Dbix-class mailing list