[Dbix-class] Where to set database date format for InflateColumn::DateTime?

Adam Witney awitney at sgul.ac.uk
Thu Apr 17 11:41:28 GMT 2014



On 17. 4. 2014 12:12, Hartmaier Alexander wrote:
> Hi,
>
> On 2014-04-17 12:51, Adam Witney wrote:
>>
>> Hi,
>>
>> I have a Catalyst/DBIx::Class application but I am having trouble with
>> datetime inflation.
>>
>> I have a PostgreSQL database with datestyle "SQL, DMY" and timezone
>> "GB". The table has a field with datatype "timestamp without
>> timezone", so my dates look like "15/04/2014 13:41:50" in the database.
>>
>> My Result class loads the TimeStamp component, but when I try to
>> render the variable in my TT view I get a long error including:
>>
>> "The 'month' parameter ("15") to DateTime::new did not pass the 'an
>> integer between 1 and 12' callback"
>>
>> I assume it is trying to inflate the field as MDY rather than DMY as
>> is set in my database?
>>
>> I can get the string version of the date by setting the column to
>> "'inflate_datetime' => 0", but I would like to get the DateTime object
>> back.
>>
>> I am having trouble working out how and where I tell my application of
>> the database datestyle format, could someone provide any advice?
> I guess you're missing on_connect_do => 'datetime_setup' as hidden in
> the docs here:
> https://metacpan.org/pod/DBIx::Class::Storage::DBI#datetime_setup
>
> This will run the appropriate sql required for each supported rdbms to
> make datetime columns return the format inflatecolumn::datetime expects.

Great thanks,

  on_connect_do => "SET datestyle = 'sql, mdy'",

did the trick

Adam



More information about the DBIx-Class mailing list