diff --git a/lib/NGCP/Schema.pm b/lib/NGCP/Schema.pm index 5da0d731..939e2646 100644 --- a/lib/NGCP/Schema.pm +++ b/lib/NGCP/Schema.pm @@ -14,6 +14,9 @@ __PACKAGE__->load_namespaces( default_resultset_class => 'ResultSet', ); +use DBIx::Class::Storage::DBI; +DBIx::Class::Storage::DBI->datetime_parser_type('NGCP::Schema::Storage::DateTime::Format::MySQL'); + class_has('config', is => 'rw', isa => 'NGCP::Schema::Config', lazy => 1, default => sub { return NGCP::Schema::Config->instance; }); diff --git a/lib/NGCP/Schema/Storage/DateTime/Format/MySQL.pm b/lib/NGCP/Schema/Storage/DateTime/Format/MySQL.pm new file mode 100644 index 00000000..af0e0ac2 --- /dev/null +++ b/lib/NGCP/Schema/Storage/DateTime/Format/MySQL.pm @@ -0,0 +1,28 @@ +package NGCP::Schema::Storage::DateTime::Format::MySQL; + +use strict; + +use vars qw ($VERSION); + +$VERSION = '0.06'; + +use base ("DateTime::Format::MySQL"); + +sub format_time +{ + my ( $self, $dt ) = @_; + my ($h,$m,$s) = ($dt->hour(), $dt->minute(), $dt->second()); + if ($s >= 60) { #Returns the second, from 0..61. The values 60 and 61 are used for leap seconds. + $s = 59; + } + my $sep = ':'; + return sprintf( + '%0.2d%s%0.2d%s%0.2d', + $h, $sep, + $m, $sep, + $s + ); +} + + +1;