++ed by:

1 non-PAUSE user.

Author image Nigel Metheringham
and 2 contributors


DBIx::Class::InflateColumn::TimeMoment - Auto-create TimeMoment objects from date and datetime columns.


version 0.050


Load this component and then declare one or more columns to be of the datetime, timestamp or date datatype.

  package Event;
  use base 'DBIx::Class::Core';

    starts_when => { data_type => 'datetime' }
    create_date => { data_type => 'date' }

Then you can treat the specified column as a TimeMoment object.

If you want to inflate no matter what data_type your column is, use inflate_datetime or inflate_date:

    starts_when => { data_type => 'varchar', inflate_datetime => 1 }

    starts_when => { data_type => 'varchar', inflate_date => 1 }

It's also possible to explicitly skip inflation:

    starts_when => { data_type => 'datetime', inflate_datetime => 0 }


This module works with Time::Moment IS8601 date formats to inflate/deflate. A later version may handle databases in a more forgiving way, but really why not make them do something sensible.

For more help with using components, see "USING" in DBIx::Class::Manual::Component.


Chains with the "register_column" in DBIx::Class::Row method, and sets up datetime columns appropriately. This would not normally be directly called by end users.

In the case of an invalid date, Time::Moment will throw an exception. To bypass these exceptions and just have the inflation return undef, use the datetime_undef_if_invalid option in the column info:

        data_type => "datetime",
        default_value => '0000-00-00',
        is_nullable => 1,
        datetime_undef_if_invalid => 1

NOTE: Don't rely on InflateColumn::TimeMoment to parse date strings for you. The column is set directly for any non-references and InflateColumn::TimeMoment is completely bypassed. Instead, use an input parser to create a TimeMoment object.


As is obvious from a quick inspection of the code, this module is very heavily based on and draws code from DBIx::Class::InflateColumn::DateTime, however it is significantly simplified due to the less well developed timezone handling and formatter ecosystem.


More information about the add_columns method, and column metadata, can be found in the documentation for DBIx::Class::ResultSource.


Check the list of additional DBIC resources.


Nigel Metheringham <nigelm@cpan.org>


This software is copyright (c) 2015-2017 by Nigel Metheringham.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.