[Dbix-class] Re: DateTime objects passed to search() are not supported properly

Bill Moseley moseley at hank.org
Thu Sep 20 19:44:31 GMT 2012


On Thu, Sep 20, 2012 at 3:22 AM, Peter Rabbitson <rabbit+dbic at rabbit.us>wro=
te:

>
> Precisely. The problem is that we can not invoke the correct IC::DT
> deflation routine to respect possible time_zone settings. The formatter is
> fine for use only as that - a formatter. There is no practical way to tie
> the IC::DT metadata to your search criteria. There is no change in behavi=
or
> - DBIC has always done the wrong thing (simply stringifying the DT object=
).
> What changed is that now you are getting a warning about it.


Sorry, I'm being a bit slow here.

Quoting the Cookbook again:


  my $dtf =3D $schema->storage->datetime_parser;
  my $rs =3D $schema->resultset('users')->search(
    {
      signup_date =3D> {
        -between =3D> [
          $dtf->format_datetime($dt_start),
          $dtf->format_datetime($dt_end),
        ],
      }
    },
  );


So, if $dt_start is not floating (has a timezone) then
$dtf->format_datetime( $dt_start ) would be a sting that included the
timezone which is needed to specify a point in time to the database.

Is the problem that the above query is passed directly to SQL::Abstract
which doesn't have access to the storage object, and thus cannot get at the
formatter?

Couldn't something like Data::Visitor be used to find all the DateTIme
objects in the criteria and then run them through the formater?   search()
can get at the storage object, right?

If I pass in a floating DateTime then that's my own fault and maybe that's
where it should warn (or even throw and error).




-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120920/7d5=
7819b/attachment.htm


More information about the DBIx-Class mailing list