[Bps-public-commit] dbix-searchbuilder branch, date-time-helpers, updated. 1.59-17-gca58644

Ruslan Zakirov ruz at bestpractical.com
Fri Sep 16 06:33:37 EDT 2011


The branch, date-time-helpers has been updated
       via  ca58644a0a1443bea58dd1d383af237104881c09 (commit)
       via  20b138a2568703fbffd546ce0c03072d0eb83739 (commit)
       via  5ebfa9da9016d0fd5f878d6ea38ad4f384a658bd (commit)
       via  1bf01e3c4b471fd9691581d0f881ffd7cad9e524 (commit)
       via  1797e88ab02735474ad49b5f26f61325d244ad0d (commit)
       via  e37fa5c9a580f3388e89eff46a556d9d620f2c28 (commit)
       via  0e97716d37975b1684b9da002965af2d05ed98b0 (commit)
      from  4291d1ebc8b10ca43804e0560ec4d89e3c0dbca2 (commit)

Summary of changes:
 lib/DBIx/SearchBuilder/Handle/Oracle.pm |   25 ++++++++-
 lib/DBIx/SearchBuilder/Handle/Pg.pm     |    7 ++-
 lib/DBIx/SearchBuilder/Handle/SQLite.pm |   25 +++++++++
 lib/DBIx/SearchBuilder/Handle/mysql.pm  |    2 +-
 t/02records_datetime.t                  |   87 ++++++++++++++++++++++++++++++-
 5 files changed, 139 insertions(+), 7 deletions(-)

- Log -----------------------------------------------------------------
commit 0e97716d37975b1684b9da002965af2d05ed98b0
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 16 14:23:38 2011 +0400

    add missing 'map'

diff --git a/lib/DBIx/SearchBuilder/Handle/Pg.pm b/lib/DBIx/SearchBuilder/Handle/Pg.pm
index 05bf8a4..21c9d71 100755
--- a/lib/DBIx/SearchBuilder/Handle/Pg.pm
+++ b/lib/DBIx/SearchBuilder/Handle/Pg.pm
@@ -314,7 +314,7 @@ sub ConvertTimezoneFunction {
 
     my $dbh = $self->dbh;
     my $res = $args{'Field'};
-    $res = "TIMEZONE($_, $res)" foreach $dbh->quote( $_ ), grep $_, @args{'From', 'To'};
+    $res = "TIMEZONE($_, $res)" foreach map $dbh->quote( $_ ), grep $_, @args{'From', 'To'};
     return $res;
 }
 

commit e37fa5c9a580f3388e89eff46a556d9d620f2c28
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 16 14:24:21 2011 +0400

    timezone conversion for SQLite
    
    it's limitted, only utc->local, local->utc

diff --git a/lib/DBIx/SearchBuilder/Handle/SQLite.pm b/lib/DBIx/SearchBuilder/Handle/SQLite.pm
index a8b9e29..e75222c 100644
--- a/lib/DBIx/SearchBuilder/Handle/SQLite.pm
+++ b/lib/DBIx/SearchBuilder/Handle/SQLite.pm
@@ -177,6 +177,31 @@ sub SimpleDateTimeFunctions {
     };
 }
 
+sub ConvertTimezoneFunction {
+    my $self = shift;
+    my %args = (
+        From  => 'UTC',
+        To    => undef,
+        Field => '',
+        @_
+    );
+    return $args{'Field'} unless $args{From} && $args{'To'};
+    return $args{'Field'} if lc $args{From} eq lc $args{'To'};
+
+    my $res;
+    if ( lc($args{'To'}||'') eq 'utc' ) {
+        $res = "datetime($args{'Field'}, 'utc')";
+    }
+    elsif ( lc($args{'From'}||'') eq 'utc' ) {
+        $res = "datetime($args{'Field'}, 'localtime')";
+    }
+    else {
+        warn "SQLite only supports TZ convesion from UTC or to UTC";
+        $res = $args{'Field'};
+    }
+    return $res;
+}
+
 1;
 
 __END__

commit 1797e88ab02735474ad49b5f26f61325d244ad0d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 16 14:25:57 2011 +0400

    Oracle: set format for all date/timestamp settings

diff --git a/lib/DBIx/SearchBuilder/Handle/Oracle.pm b/lib/DBIx/SearchBuilder/Handle/Oracle.pm
index 0f01d8a..6531faa 100755
--- a/lib/DBIx/SearchBuilder/Handle/Oracle.pm
+++ b/lib/DBIx/SearchBuilder/Handle/Oracle.pm
@@ -47,8 +47,12 @@ sub Connect  {
     
     $self->dbh->{LongTruncOk}=1;
     $self->dbh->{LongReadLen}=8000;
-    
-    $self->SimpleQuery("ALTER SESSION set NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'");
+
+    foreach my $setting (qw(DATE TIMESTAMP TIMESTAMP_TZ)) {
+        $self->SimpleQuery(
+            "ALTER SESSION set NLS_${setting}_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"
+        );
+    }
     
     return ($rv); 
 }

commit 1bf01e3c4b471fd9691581d0f881ffd7cad9e524
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 16 14:26:38 2011 +0400

    add reference to Oracle's documentation on datetime

diff --git a/lib/DBIx/SearchBuilder/Handle/Oracle.pm b/lib/DBIx/SearchBuilder/Handle/Oracle.pm
index 6531faa..a2b508f 100755
--- a/lib/DBIx/SearchBuilder/Handle/Oracle.pm
+++ b/lib/DBIx/SearchBuilder/Handle/Oracle.pm
@@ -321,6 +321,7 @@ sub Fields {
     return @{ $cache->{ lc $table } || [] };
 }
 
+# http://download.oracle.com/docs/cd/B14117_01/server.101/b10749/ch4datetime.htm
 sub SimpleDateTimeFunctions {
     my $self = shift;
     return $self->{'_simple_date_time_functions'}

commit 5ebfa9da9016d0fd5f878d6ea38ad4f384a658bd
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 16 14:27:18 2011 +0400

    timezone conversions for Oracle

diff --git a/lib/DBIx/SearchBuilder/Handle/Oracle.pm b/lib/DBIx/SearchBuilder/Handle/Oracle.pm
index a2b508f..6e1eaa2 100755
--- a/lib/DBIx/SearchBuilder/Handle/Oracle.pm
+++ b/lib/DBIx/SearchBuilder/Handle/Oracle.pm
@@ -356,6 +356,22 @@ sub SimpleDateTimeFunctions {
     };
 }
 
+sub ConvertTimezoneFunction {
+    my $self = shift;
+    my %args = (
+        From  => 'UTC',
+        To    => undef,
+        Field => '',
+        @_
+    );
+    return $args{'Field'} unless $args{From} && $args{'To'};
+    return $args{'Field'} if lc $args{From} eq lc $args{'To'};
+
+    my $dbh = $self->dbh;
+    $_ = $dbh->quote( $_ ) foreach @args{'From', 'To'};
+    return "FROM_TZ( CAST ($args{'Field'} AS TIMESTAMP), $args{'From'}) AT TIME ZONE $args{'To'}";
+}
+
 1;
 
 __END__

commit 20b138a2568703fbffd546ce0c03072d0eb83739
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 16 14:28:02 2011 +0400

    unify begining of ConvertTZ function

diff --git a/lib/DBIx/SearchBuilder/Handle/Pg.pm b/lib/DBIx/SearchBuilder/Handle/Pg.pm
index 21c9d71..635b174 100755
--- a/lib/DBIx/SearchBuilder/Handle/Pg.pm
+++ b/lib/DBIx/SearchBuilder/Handle/Pg.pm
@@ -305,12 +305,13 @@ From argument.
 sub ConvertTimezoneFunction {
     my $self = shift;
     my %args = (
-        From  => undef,
+        From  => 'UTC',
         To    => undef,
         Field => '',
         @_
     );
-    return $args{'Field'} if ($args{From}||'') eq ($args{'To'}||'');
+    return $args{'Field'} unless $args{From} && $args{'To'};
+    return $args{'Field'} if lc $args{From} eq lc $args{'To'};
 
     my $dbh = $self->dbh;
     my $res = $args{'Field'};
diff --git a/lib/DBIx/SearchBuilder/Handle/mysql.pm b/lib/DBIx/SearchBuilder/Handle/mysql.pm
index 65f93e7..a257bd8 100755
--- a/lib/DBIx/SearchBuilder/Handle/mysql.pm
+++ b/lib/DBIx/SearchBuilder/Handle/mysql.pm
@@ -175,7 +175,7 @@ sub ConvertTimezoneFunction {
         @_
     );
     return $args{'Field'} unless $args{From} && $args{'To'};
-    return $args{'Field'} if $args{From} eq $args{'To'};
+    return $args{'Field'} if lc $args{From} eq lc $args{'To'};
     my $dbh = $self->dbh;
     $_ = $dbh->quote( $_ ) foreach @args{'From', 'To'};
     return "CONVERT_TZ( $args{'Field'}, $args{'From'}, $args{'To'} )";

commit ca58644a0a1443bea58dd1d383af237104881c09
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 16 14:30:02 2011 +0400

    test time zones conversions

diff --git a/t/02records_datetime.t b/t/02records_datetime.t
index 63d34c0..ed5df74 100644
--- a/t/02records_datetime.t
+++ b/t/02records_datetime.t
@@ -1,5 +1,6 @@
 #!/usr/bin/perl -w
 
+BEGIN { $ENV{'TZ'} = 'Europe/Moscow' };
 
 use strict;
 use warnings;
@@ -7,7 +8,7 @@ use Test::More;
 BEGIN { require "t/utils.pl" }
 our (@AvailableDrivers);
 
-use constant TESTS_PER_DRIVER => 21;
+use constant TESTS_PER_DRIVER => 38;
 
 my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -35,6 +36,12 @@ SKIP: {
     my $count_all = init_data( 'TestApp::User', $handle );
     ok( $count_all,  "init users data" );
 
+    is( $handle->DateTimeFunction, 'NULL', 'no type' );
+    is( $handle->DateTimeFunction( Type => 'bad function' ), 'NULL', 'bad type' );
+
+    is( $handle->ConvertTimezoneFunction( Field => '?' ), '?', 'no To argument' );
+    is( $handle->ConvertTimezoneFunction( To => 'utc', Field => '?' ), '?', 'From and To equal' );
+
     foreach my $type ('date time', 'DateTime', 'date_time', 'Date-Time') {
         run_test(
             { Type => $type },
@@ -43,6 +50,14 @@ SKIP: {
                 '2011-05-20 19:53:23' => '2011-05-20 19:53:23',
             },
         );
+        run_test(
+            { Type => $type, Timezone => { To => 'Europe/Moscow' } },
+            {
+                '' => undef,
+                '2011-05-20 19:53:23' => '2011-05-20 23:53:23',
+                '2011-05-20 22:53:23' => '2011-05-21 02:53:23',
+            },
+        );
     }
 
     run_test(
@@ -52,12 +67,29 @@ SKIP: {
             '2011-05-20 19:53:23' => '19:53:23',
         },
     );
+    run_test(
+        { Type => 'time', Timezone => { To => 'Europe/Moscow' } },
+        {
+            '' => undef,
+            '2011-05-20 19:53:23' => '23:53:23',
+            '2011-05-20 22:53:23' => '2:53:23',
+        },
+    );
 
     run_test( 
         { Type => 'hourly' },
         {
             '' => undef,
             '2011-05-20 19:53:23' => '2011-05-20 19',
+            '2011-05-20 22:53:23' => '2011-05-20 22',
+        },
+    );
+    run_test( 
+        { Type => 'hourly', Timezone => { To => 'Europe/Moscow' } },
+        {
+            '' => undef,
+            '2011-05-20 19:53:23' => '2011-05-20 23',
+            '2011-05-20 22:53:23' => '2011-05-21 02',
         },
     );
 
@@ -68,6 +100,14 @@ SKIP: {
             '2011-05-20 19:53:23' => '19',
         },
     );
+    run_test(
+        { Type => 'hour', Timezone => { To => 'Europe/Moscow' } },
+        {
+            '' => undef,
+            '2011-05-20 19:53:23' => '23',
+            '2011-05-20 22:53:23' => '2',
+        },
+    );
 
     foreach my $type ( 'date', 'daily' ) {
         run_test(
@@ -77,6 +117,14 @@ SKIP: {
                 '2011-05-20 19:53:23' => '2011-05-20',
             },
         );
+        run_test(
+            { Type => $type, Timezone => { To => 'Europe/Moscow' } },
+            {
+                '' => undef,
+                '2011-05-20 19:53:23' => '2011-05-20',
+                '2011-05-20 22:53:23' => '2011-05-21',
+            },
+        );
     }
 
     run_test(
@@ -86,15 +134,40 @@ SKIP: {
             '2011-05-20 19:53:23' => '5',
             '2011-05-21 19:53:23' => '6',
             '2011-05-22 19:53:23' => '0',
+            '2011-05-20 22:53:23' => '5',
+            '2011-05-21 22:53:23' => '6',
+            '2011-05-22 22:53:23' => '0',
+        },
+    );
+    run_test(
+        { Type => 'day of week', Timezone => { To => 'Europe/Moscow' } },
+        {
+            '' => undef,
+            '2011-05-20 19:53:23' => '5',
+            '2011-05-21 19:53:23' => '6',
+            '2011-05-22 19:53:23' => '0',
+            '2011-05-20 22:53:23' => '6',
+            '2011-05-21 22:53:23' => '0',
+            '2011-05-22 22:53:23' => '1',
         },
     );
 
+
     foreach my $type ( 'day', 'DayOfMonth' ) {
         run_test(
             { Type => $type },
             {
                 '' => undef,
                 '2011-05-20 19:53:23' => '20',
+                '2011-05-20 22:53:23' => '20',
+            },
+        );
+        run_test(
+            { Type => $type, Timezone => { To => 'Europe/Moscow' } },
+            {
+                '' => undef,
+                '2011-05-20 19:53:23' => '20',
+                '2011-05-20 22:53:23' => '21',
             },
         );
     }
@@ -104,6 +177,15 @@ SKIP: {
         {
             '' => undef,
             '2011-05-20 19:53:23' => '140',
+            '2011-05-20 22:53:23' => '140',
+        },
+    );
+    run_test(
+        { Type => 'day of year', Timezone => { To => 'Europe/Moscow' } },
+        {
+            '' => undef,
+            '2011-05-20 19:53:23' => '140',
+            '2011-05-20 22:53:23' => '141',
         },
     );
 
@@ -253,6 +335,9 @@ sub init_data {
     [ '2011-05-20 19:53:23' ], # friday
     [ '2011-05-21 19:53:23' ], # saturday
     [ '2011-05-22 19:53:23' ], # sunday
+    [ '2011-05-20 22:53:23' ], # fri in UTC, sat in moscow
+    [ '2011-05-21 22:53:23' ], # sat in UTC, sun in moscow
+    [ '2011-05-22 22:53:23' ], # sun in UTC, mon in moscow
     );
 }
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list