From: Rafael Kitover Date: Wed, 18 May 2011 09:51:35 +0000 (-0400) Subject: add DateTime parser for Sybase ASE X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=deabd575192fc9d512582efe111a89f9478f3af7;p=dbsrgits%2FDBIx-Class-Historic.git add DateTime parser for Sybase ASE --- diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm index 7cad0aa..c738db4 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm @@ -27,6 +27,10 @@ __PACKAGE__->mk_group_accessors('simple' => _identity_method/ ); +__PACKAGE__->datetime_parser_type( + 'DBIx::Class::Storage::DBI::Sybase::ASE::DateTime::Format' +); + my @also_proxy_to_extra_storages = qw/ connect_call_set_auto_cast auto_cast connect_call_blob_setup connect_call_datetime_setup @@ -906,6 +910,34 @@ sub _exec_svp_rollback { $self->_dbh->do("ROLLBACK TRANSACTION $name"); } +package # hide from PAUSE + DBIx::Class::Storage::DBI::Sybase::ASE::DateTime::Format; + +my $datetime_parse_format = '%Y-%m-%dT%H:%M:%S.%3NZ'; +my $datetime_format_format = '%m/%d/%Y %H:%M:%S.%3N'; + +my ($datetime_parser, $datetime_formatter); + +sub parse_datetime { + shift; + require DateTime::Format::Strptime; + $datetime_parser ||= DateTime::Format::Strptime->new( + pattern => $datetime_parse_format, + on_error => 'croak', + ); + return $datetime_parser->parse_datetime(shift); +} + +sub format_datetime { + shift; + require DateTime::Format::Strptime; + $datetime_formatter ||= DateTime::Format::Strptime->new( + pattern => $datetime_format_format, + on_error => 'croak', + ); + return $datetime_formatter->format_datetime(shift); +} + 1; =head1 Schema::Loader Support