r13597 - in /branches/upstream/libtime-piece-mysql-perl: ./ current/ current/lib/ current/lib/Time/ current/lib/Time/Piece/ current/t/

dmn at users.alioth.debian.org dmn at users.alioth.debian.org
Sat Jan 26 08:15:18 UTC 2008


Author: dmn
Date: Sat Jan 26 08:15:18 2008
New Revision: 13597

URL: http://svn.debian.org/wsvn/?sc=1&rev=13597
Log:
[svn-inject] Installing original source of libtime-piece-mysql-perl

Added:
    branches/upstream/libtime-piece-mysql-perl/
    branches/upstream/libtime-piece-mysql-perl/current/
    branches/upstream/libtime-piece-mysql-perl/current/Changes
    branches/upstream/libtime-piece-mysql-perl/current/MANIFEST
    branches/upstream/libtime-piece-mysql-perl/current/META.yml
    branches/upstream/libtime-piece-mysql-perl/current/Makefile.PL
    branches/upstream/libtime-piece-mysql-perl/current/README
    branches/upstream/libtime-piece-mysql-perl/current/lib/
    branches/upstream/libtime-piece-mysql-perl/current/lib/Time/
    branches/upstream/libtime-piece-mysql-perl/current/lib/Time/Piece/
    branches/upstream/libtime-piece-mysql-perl/current/lib/Time/Piece/MySQL.pm
    branches/upstream/libtime-piece-mysql-perl/current/t/
    branches/upstream/libtime-piece-mysql-perl/current/t/basic.t
    branches/upstream/libtime-piece-mysql-perl/current/t/datetime.t
    branches/upstream/libtime-piece-mysql-perl/current/t/timestamp.t

Added: branches/upstream/libtime-piece-mysql-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libtime-piece-mysql-perl/current/Changes?rev=13597&op=file
==============================================================================
--- branches/upstream/libtime-piece-mysql-perl/current/Changes (added)
+++ branches/upstream/libtime-piece-mysql-perl/current/Changes Sat Jan 26 08:15:18 2008
@@ -1,0 +1,30 @@
+0.05  Jul 21, 2004
+
+- It seems that 0.04 was incorrectly bundled onto CPAN after my Solaris testing.
+
+0.04  Feb 02, 2004
+
+- fixed the test failure on sun4-solaris (and probably others)
+  The problem was a bug (IMO) in strptime on Solaris: if you didn't scan
+  the month-day in the date, it filled the struct tm with 0, which causes
+  mktime to go back to the previous month.
+
+- the constructors now wrap Time::Piece calls in eval so they won't die when
+  you pass invalid dates from MySQL.  Your application should vaidate dates
+  before storing them in MySQL, but (like me) you may have to process data
+  that some less careful programmer has left for you.
+
+0.03  May 02, 2003
+
+- new maintainer: Marty Pauley <marty+perl at kasei.com>
+- added mysql_timestamp method
+- now using Test::More
+
+0.02  Jun 11, 2002
+
+- Forgot to fill in README.  Doh!
+
+0.01  Jun 11, 2002
+
+- First release
+

Added: branches/upstream/libtime-piece-mysql-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libtime-piece-mysql-perl/current/MANIFEST?rev=13597&op=file
==============================================================================
--- branches/upstream/libtime-piece-mysql-perl/current/MANIFEST (added)
+++ branches/upstream/libtime-piece-mysql-perl/current/MANIFEST Sat Jan 26 08:15:18 2008
@@ -1,0 +1,9 @@
+Changes
+MANIFEST
+Makefile.PL
+README
+lib/Time/Piece/MySQL.pm
+t/basic.t
+t/datetime.t
+t/timestamp.t
+META.yml                                 Module meta-data (added by MakeMaker)

Added: branches/upstream/libtime-piece-mysql-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libtime-piece-mysql-perl/current/META.yml?rev=13597&op=file
==============================================================================
--- branches/upstream/libtime-piece-mysql-perl/current/META.yml (added)
+++ branches/upstream/libtime-piece-mysql-perl/current/META.yml Sat Jan 26 08:15:18 2008
@@ -1,0 +1,12 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         Time-Piece-MySQL
+version:      0.05
+version_from: lib/Time/Piece/MySQL.pm
+installdirs:  site
+requires:
+    Test::More:                    0.47
+    Time::Piece:                   1.03
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17

Added: branches/upstream/libtime-piece-mysql-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libtime-piece-mysql-perl/current/Makefile.PL?rev=13597&op=file
==============================================================================
--- branches/upstream/libtime-piece-mysql-perl/current/Makefile.PL (added)
+++ branches/upstream/libtime-piece-mysql-perl/current/Makefile.PL Sat Jan 26 08:15:18 2008
@@ -1,0 +1,14 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME         => 'Time::Piece::MySQL',
+    VERSION_FROM => 'lib/Time/Piece/MySQL.pm',
+    PREREQ_PM    => { 'Time::Piece' => 1.03, 'Test::More' => 0.47 },
+    ( $] >= 5.005
+    ? (    # Add these new keywords supported since 5.005
+          ABSTRACT_FROM => 'lib/Time/Piece/MySQL.pm',
+          AUTHOR        =>
+          'Dave Rolsky <autarch at urth.org>, Marty Pauley <marty+perl at kasei.com>',
+    )
+    : () ),
+);

Added: branches/upstream/libtime-piece-mysql-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libtime-piece-mysql-perl/current/README?rev=13597&op=file
==============================================================================
--- branches/upstream/libtime-piece-mysql-perl/current/README (added)
+++ branches/upstream/libtime-piece-mysql-perl/current/README Sat Jan 26 08:15:18 2008
@@ -1,0 +1,26 @@
+Time::Piece::MySQL
+==================
+
+Time::Piece::MySQL, when used, adds several MySQL-specific methods to
+the Time::Piece class.
+
+INSTALLATION
+
+To install this module type the following:
+
+   perl Makefile.PL
+   make
+   make test
+   make install
+
+DEPENDENCIES
+
+This module won't do much without Time::Piece!
+
+COPYRIGHT AND LICENCE
+
+Copyright (c) 2004 Marty Pauley
+Copyright (c) 2002 David Rolsky
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.

Added: branches/upstream/libtime-piece-mysql-perl/current/lib/Time/Piece/MySQL.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libtime-piece-mysql-perl/current/lib/Time/Piece/MySQL.pm?rev=13597&op=file
==============================================================================
--- branches/upstream/libtime-piece-mysql-perl/current/lib/Time/Piece/MySQL.pm (added)
+++ branches/upstream/libtime-piece-mysql-perl/current/lib/Time/Piece/MySQL.pm Sat Jan 26 08:15:18 2008
@@ -1,0 +1,158 @@
+package Time::Piece::MySQL;
+use strict;
+use vars qw($VERSION);
+$VERSION = '0.05';
+
+use Time::Piece;
+
+sub import { shift; @_ = ('Time::Piece', @_); goto &Time::Piece::import }
+
+package Time::Piece;
+
+use Time::Seconds;
+
+BEGIN
+{
+    my $has_dst_bug =
+	Time::Piece->strptime( '20000601120000', '%Y%m%d%H%M%S' )->hour != 12;
+    sub HAS_DST_BUG () { $has_dst_bug }
+}
+
+sub mysql_date
+{
+    my $self = shift;
+    my $old_sep = $self->date_separator('-');
+    my $ymd = $self->ymd;
+    $self->date_separator($old_sep);
+    return $ymd;
+}
+
+sub mysql_time
+{
+    my $self = shift;
+    my $old_sep = $self->time_separator(':');
+    my $hms = $self->hms;
+    $self->time_separator($old_sep);
+    return $hms;
+}
+
+sub mysql_datetime
+{
+    my $self = shift;
+    return join ' ', $self->mysql_date, $self->mysql_time;
+}
+
+
+# '1000-01-01 00:00:00' to '9999-12-31 23:59:59'
+
+sub from_mysql_date {
+    my ($class, $dt) = @_;
+    return unless $dt and $dt ge '1970' and $dt lt '2038';
+    my $time = eval {$class->strptime($dt, '%Y-%m-%d')};
+    return $time;
+}
+
+sub from_mysql_datetime {
+    my ($class, $dt) = @_;
+    return unless $dt and $dt ge '1970' and $dt lt '2038';
+    my $time = eval {$class->strptime($dt, '%Y-%m-%d %H:%M:%S')};
+    $time -= ONE_HOUR if HAS_DST_BUG && $time->isdst;
+    return $time;
+}
+
+sub mysql_timestamp {
+	my $self = shift;
+	return $self->strftime('%Y%m%d%H%M%S');
+}
+
+sub from_mysql_timestamp {
+    # From MySQL version 4.1, timestamps are returned as datetime strings
+    my ($class, $timestamp) = @_;
+    my $length = length $timestamp;
+    # most timestamps have 2-digit years, except 8 and 14 char ones
+    if ( $length != 14 && $length != 8 ) {
+        $timestamp = (substr($timestamp, 0, 2) < 70 ? "20" : "19")
+                   . $timestamp;
+    }
+    # now we need to extend this to 14 chars to make sure we get
+    # consistent cross-platform results
+    $timestamp .= substr("19700101000000", length $timestamp);
+    my $time = eval {$class->strptime( $timestamp, '%Y%m%d%H%M%S')};
+    return $time;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Time::Piece::MySQL - Adds MySQL-specific methods to Time::Piece
+
+=head1 SYNOPSIS
+
+  use Time::Piece::MySQL;
+
+  my $time = localtime;
+
+  print $time->mysql_datetime;
+  print $time->mysql_date;
+  print $time->mysql_time;
+
+  my $time = Time::Piece->from_mysql_datetime( $mysql_datetime );
+  my $time = Time::Piece->from_mysql_date( $mysql_date );
+  my $time = Time::Piece->from_mysql_timestamp( $mysql_timestamp );
+
+=head1 DESCRIPTION
+
+Using this module instead of, or in addition to, C<Time::Piece> adds a
+few MySQL-specific date-time methods to C<Time::Piece> objects.
+
+=head1 OBJECT METHODS
+
+=head2 mysql_date / mysql_time / mysql_datetime / mysql_timestamp
+
+Returns the date and/or time in a format suitable for use by MySQL.
+
+=head1 CONSTRUCTORS
+
+=head2 from_mysql_date / from_mysql_datetime / from_mysql_timestamp
+
+Given a date, datetime, or timestamp value as returned from MySQL, these
+constructors return a new Time::Piece object.  If the value is NULL, they
+will retrun undef.
+
+=head2 CAVEAT
+
+C<Time::Piece> itself only works with times in the Unix epoch, this module has
+the same limitation.  However, MySQL itself handles date and datetime columns
+from '1000-01-01' to '9999-12-31'.  Feeding in times outside of the Unix epoch
+to any of the constructors has unpredictable results.
+
+Also, MySQL doesn't validate dates (because your application should); it only
+checks that dates are in the right format.  So, your database might include
+dates like 2004-00-00 or 2001-02-31.  Passing invalid dates to any of the
+constructors is a bad idea: on my system the former type (with zeros) returns
+undef (previous version used to die) while the latter returns a date in the
+following month.
+
+=head1 AUTHOR
+
+Original author: Dave Rolsky <autarch at urth.org>
+
+Current maintainer: Marty Pauley <marty+perl at kasei.com>
+
+=head1 COPYRIGHT
+
+(c) 2002 Dave Rolsky
+
+(c) 2004 Marty Pauley
+
+This program is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+L<Time::Piece>
+
+=cut

Added: branches/upstream/libtime-piece-mysql-perl/current/t/basic.t
URL: http://svn.debian.org/wsvn/branches/upstream/libtime-piece-mysql-perl/current/t/basic.t?rev=13597&op=file
==============================================================================
--- branches/upstream/libtime-piece-mysql-perl/current/t/basic.t (added)
+++ branches/upstream/libtime-piece-mysql-perl/current/t/basic.t Sat Jan 26 08:15:18 2008
@@ -1,0 +1,28 @@
+#!/usr/bin/perl
+use strict;
+use Test::More tests => 12;
+use Time::Piece::MySQL;
+
+my $lt = localtime;
+isa_ok( $lt, 'Time::Piece' );
+
+my $gmt = gmtime;
+isa_ok( $gmt, 'Time::Piece' );
+
+for my $t ( $lt, $gmt )
+{
+    is( $t->mysql_date, $t->ymd );
+    is( $t->mysql_time, $t->hms );
+    is( $t->mysql_datetime, join ' ', $t->ymd, $t->hms );
+}
+
+my $t = Time::Piece->from_mysql_datetime( $lt->mysql_datetime );
+
+isa_ok( $t, 'Time::Piece' );
+
+is( $t->mysql_datetime, $lt->mysql_datetime );
+
+my $t2 = Time::Piece->from_mysql_date( $lt->mysql_date );
+isa_ok( $t2, 'Time::Piece' );
+
+is( $t2->ymd, $lt->ymd );

Added: branches/upstream/libtime-piece-mysql-perl/current/t/datetime.t
URL: http://svn.debian.org/wsvn/branches/upstream/libtime-piece-mysql-perl/current/t/datetime.t?rev=13597&op=file
==============================================================================
--- branches/upstream/libtime-piece-mysql-perl/current/t/datetime.t (added)
+++ branches/upstream/libtime-piece-mysql-perl/current/t/datetime.t Sat Jan 26 08:15:18 2008
@@ -1,0 +1,25 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More tests => 6;
+use Time::Piece::MySQL;
+
+my $t = Time::Piece->from_mysql_datetime('2012-02-11 05:45:37');
+isa_ok( $t, 'Time::Piece' );
+$t = Time::Piece->from_mysql_date('2012-02-11');
+isa_ok( $t, 'Time::Piece' );
+
+my @null = qw/ 0000-00-00 1000-01-01 9999-12-31 /;
+for my $d (@null) {
+    ok !defined Time::Piece->from_mysql_date($d), "$d is not in range";
+}
+ok !defined Time::Piece->from_mysql_date(undef), "null is not in range";
+
+#
+# What should we do with these dates?
+# In some tests, @bad dates produced undef but @ugly dates produced
+# Time::Piece objects in the following month.
+#
+my @bad = qw/ 2001-00-00 2001-00-31 2001-02-00 2001-04-00 /;
+my @ugly = qw/ 2001-02-31 2001-04-31 2001-11-31 /;
+

Added: branches/upstream/libtime-piece-mysql-perl/current/t/timestamp.t
URL: http://svn.debian.org/wsvn/branches/upstream/libtime-piece-mysql-perl/current/t/timestamp.t?rev=13597&op=file
==============================================================================
--- branches/upstream/libtime-piece-mysql-perl/current/t/timestamp.t (added)
+++ branches/upstream/libtime-piece-mysql-perl/current/t/timestamp.t Sat Jan 26 08:15:18 2008
@@ -1,0 +1,23 @@
+#!/usr/bin/perl
+use strict;
+use Test::More;
+use Time::Piece::MySQL;
+
+my %timestamp = (
+    '70' => '19700101000000',
+    '1202' => '20120201000000',
+    '120211' => '20120211000000',
+    '20120211' => '20120211000000',
+    '1202110545' => '20120211054500',
+    '120211054537' => '20120211054537',
+    '20120211054537' => '20120211054537',
+);
+
+#my @null = qw/ 19691231235959 20380101000000 /;
+
+plan tests => scalar keys %timestamp;
+
+for my $stamp (keys %timestamp) {
+    my $t = Time::Piece->from_mysql_timestamp($stamp);
+    is $t->mysql_timestamp, $timestamp{$stamp}, "timestamp $stamp";
+}




More information about the Pkg-perl-cvs-commits mailing list