Permalink
Browse files

implementation taken from what I wrote for a DBIx::Class branch

  • Loading branch information...
0 parents commit 9b27e51c60f1df63b44fb271f2f48dead7f3d3db @rkitover committed Jun 13, 2009
Showing with 199 additions and 0 deletions.
  1. +2 −0 Changes
  2. +14 −0 Makefile.PL
  3. +42 −0 README
  4. +120 −0 lib/DateTime/Format/Sybase.pm
  5. +9 −0 t/00-load.t
  6. +12 −0 t/pod.t
@@ -0,0 +1,2 @@
+Revision history for DateTime-Format-Sybase
+
@@ -0,0 +1,14 @@
+use inc::Module::Install;
+
+name 'DateTime-Format-Sybase';
+all_from 'lib/DateTime/Format/Sybase.pm';
+author 'Rafael Kitover <rkitover@cpan.org>';
+license 'perl';
+
+test_requires 'Test::More';
+
+requires 'DateTime::Format::Strptime';
+
+auto_provides;
+auto_install;
+WriteAll;
42 README
@@ -0,0 +1,42 @@
+DateTime-Format-Sybase
+
+A module to parse and format Sybase datetimes.
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the
+perldoc command.
+
+ perldoc DateTime::Format::Sybase
+
+You can also look for information at:
+
+ RT, CPAN's request tracker
+ http://rt.cpan.org/NoAuth/Bugs.html?Dist=DateTime-Format-Sybase
+
+ AnnoCPAN, Annotated CPAN documentation
+ http://annocpan.org/dist/DateTime-Format-Sybase
+
+ CPAN Ratings
+ http://cpanratings.perl.org/d/DateTime-Format-Sybase
+
+ Search CPAN
+ http://search.cpan.org/dist/DateTime-Format-Sybase/
+
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2009 Rafael Kitover
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
@@ -0,0 +1,120 @@
+package DateTime::Format::Sybase;
+
+use strict;
+use warnings;
+use DateTime::Format::Strptime;
+
+=head1 NAME
+
+DateTime::Format::Sybase - Parse and format Sybase datetimes
+
+=head1 VERSION
+
+Version 0.01
+
+=cut
+
+our $VERSION = '0.01';
+
+=head1 SYNOPSIS
+
+ use DateTime::Format::Sybase;
+ use DBI;
+
+ my $dbh = DBI->connect('dbi:Sybase:SERVER', 'sa', '');
+ $dbh->syb_date_fmt('ISO_Strict'); # output format
+ $dbh->do('set dateformat mdy'); # input format
+
+ my $dt = DateTime::Format::Sybase->parse_datetime(
+ '2004-08-21T14:36:48.080Z'
+ );
+
+ DateTime::Format::Sybase->format_datetime($dt); # '08/21/2004 14:36:48.080'
+
+=head1 DESCRIPTION
+
+Run the DBI calls as specified in L</SYNOPSIS> on connection to use this module
+with Sybase.
+
+=cut
+
+my $output_format = DateTime::Format::Strptime->new(
+ pattern => '%Y-%m-%dT%H:%M:%S.%3NZ'
+);
+
+my $input_format = DateTime::Format::Strptime->new(
+ pattern => '%m/%d/%Y %H:%M:%S.%3N'
+);
+
+sub parse_datetime { shift; $output_format->parse_datetime(@_) }
+sub parse_timestamp { shift; $output_format->parse_datetime(@_) }
+
+sub format_datetime { shift; $input_format->format_datetime(@_) }
+sub format_timestamp { shift; $input_format->format_datetime(@_) }
+
+=head1 METHODS
+
+=head2 parse_datetime
+
+Parse a string returned by L<DBD::Sybase> for a C<DATETIME> or C<SMALLDATETIME>
+column in the C<ISO_Strict> L<DBD::Sybase/syb_date_fmt> format.
+
+Remember C<SMALLDATETIME> fields have only minute precision.
+
+=head2 parse_timestamp
+
+Same as L</parse_datetime>.
+
+=head1 format_datetime
+
+Format a L<DateTime> object into a string in the Sybase C<mdy> C<DATETIME> input
+format, with a time component, for insertion into the database.
+
+=head2 format_timestamp
+
+Same as L</format_datetime>.
+
+=head1 AUTHOR
+
+Rafael Kitover, C<< <rkitover at cpan.org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to C<bug-datetime-format-sybase at rt.cpan.org>, or through
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DateTime-Format-Sybase>. I will be notified, and then you'll
+automatically be notified of progress on your bug as I make changes.
+
+=head1 SUPPORT
+
+You can look for information at:
+
+=over 4
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DateTime-Format-Sybase>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/DateTime-Format-Sybase>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/DateTime-Format-Sybase>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/DateTime-Format-Sybase/>
+
+=back
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright (c) 2009 Rafael Kitover
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1; # End of DateTime::Format::Sybase
@@ -0,0 +1,9 @@
+#!perl -T
+
+use Test::More tests => 1;
+
+BEGIN {
+ use_ok( 'DateTime::Format::Sybase' );
+}
+
+diag( "Testing DateTime::Format::Sybase $DateTime::Format::Sybase::VERSION, Perl $], $^X" );
12 t/pod.t
@@ -0,0 +1,12 @@
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More;
+
+# Ensure a recent version of Test::Pod
+my $min_tp = 1.22;
+eval "use Test::Pod $min_tp";
+plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
+
+all_pod_files_ok();

0 comments on commit 9b27e51

Please sign in to comment.