[Catalyst] now() in insert

J. Shirley jshirley at gmail.com
Fri Feb 6 17:24:52 GMT 2009


On Fri, Feb 6, 2009 at 9:19 AM, J. Shirley <jshirley at gmail.com> wrote:
> On Fri, Feb 6, 2009 at 9:04 AM, Devin Austin <devin.austin at gmail.com> wrote:
>> DateTime has ::Formatter classes, I *know* there's a *ahem* MySQL formatter
>> (DateTime::Format::MySQL i believe), and probably a Pg formatter.
>>
>
> Why are you top posting!?  You know better than that.
>
> And I just found this out the other day:
> http://search.cpan.org/~cfaerber/DateTime-Format-DBI-0.032/lib/DateTime/Format/DBI.pm
>

Premature sending.  Oops.

Something like this can be done in your schema class (not-tested, just
typed and as such probably doesn't work but will with a bit of
tweaking ;)):

package MyApp::Schema;

use parent 'DBIx::Class::Schema';

use Moose;

extends 'DBIx::Class::Schema';

has 'datetime_formatter' => (
    is => 'rw',
    isa => 'Object',
    lazy_build => 1,
    builder =>
);

use DateTime::Format::DBI;

sub _build_datetime_formatter {
      my $self = shift;
      return DateTime::Format::DBI->new( $self->storage->dbh );
}

1;

Now your $schema has the formatter object automatically built:

$schema->datetime_formatter->format_date( $dt );



More information about the Catalyst mailing list