[Bast-commits] r5419 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class/InflateColumn t t/lib/DBICTest/Schema

plu at dev.catalyst.perl.org plu at dev.catalyst.perl.org
Sat Feb 7 13:40:41 GMT 2009


Author: plu
Date: 2009-02-07 13:40:41 +0000 (Sat, 07 Feb 2009)
New Revision: 5419

Modified:
   DBIx-Class/0.08/trunk/Changes
   DBIx-Class/0.08/trunk/lib/DBIx/Class/InflateColumn/DateTime.pm
   DBIx-Class/0.08/trunk/t/89inflate_datetime.t
   DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/EventTZ.pm
Log:
Possible to set locale in IC::DateTime extra => {} config

Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes	2009-02-07 13:29:46 UTC (rev 5418)
+++ DBIx-Class/0.08/trunk/Changes	2009-02-07 13:40:41 UTC (rev 5419)
@@ -1,4 +1,5 @@
 Revision history for DBIx::Class
+        - Possible to set locale in IC::DateTime extra => {} config
 
 0.08099_06 2009-01-23 07:30:00 (UTC)
         - Allow a scalarref to be supplied to the 'from' resultset attribute

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/InflateColumn/DateTime.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/InflateColumn/DateTime.pm	2009-02-07 13:29:46 UTC (rev 5418)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/InflateColumn/DateTime.pm	2009-02-07 13:40:41 UTC (rev 5419)
@@ -27,10 +27,10 @@
   print "This event starts the month of ".
     $event->starts_when->month_name();
 
-If you want to set a specific timezone for that field, use:
+If you want to set a specific timezone and locale for that field, use:
 
   __PACKAGE__->add_columns(
-    starts_when => { data_type => 'datetime', extra => { timezone => "America/Chicago" } }
+    starts_when => { data_type => 'datetime', extra => { timezone => "America/Chicago", locale => "de_DE" } }
   );
 
 If you want to inflate no matter what data_type your column is,
@@ -110,10 +110,15 @@
   }
 
   my $timezone;
-  if ( exists $info->{extra} and exists $info->{extra}{timezone} and defined $info->{extra}{timezone} ) {
+  if ( defined $info->{extra}{timezone} ) {
     $timezone = $info->{extra}{timezone};
   }
 
+  my $locale;
+  if ( defined $info->{extra}{locale} ) {
+    $locale = $info->{extra}{locale};
+  }
+
   my $undef_if_invalid = $info->{datetime_undef_if_invalid};
 
   if ($type eq 'datetime' || $type eq 'date') {
@@ -143,6 +148,7 @@
             die "Error while inflating ${value} for ${column} on ${self}: $@"
               if $@ and not $undef_if_invalid;
             $dt->set_time_zone($timezone) if $timezone;
+            $dt->set_locale($locale) if $locale;
             return $dt;
           },
           deflate => sub {
@@ -154,6 +160,7 @@
                       and not $floating_tz_ok
                       and not $ENV{DBIC_FLOATING_TZ_OK};
                 $value->set_time_zone($timezone);
+                $value->set_locale($locale) if $locale;
             }
             $obj->_datetime_parser->$format($value);
           },

Modified: DBIx-Class/0.08/trunk/t/89inflate_datetime.t
===================================================================
--- DBIx-Class/0.08/trunk/t/89inflate_datetime.t	2009-02-07 13:29:46 UTC (rev 5418)
+++ DBIx-Class/0.08/trunk/t/89inflate_datetime.t	2009-02-07 13:40:41 UTC (rev 5419)
@@ -10,7 +10,7 @@
 eval { require DateTime::Format::MySQL };
 plan skip_all => "Need DateTime::Format::MySQL for inflation tests" if $@;
 
-plan tests => 28;
+plan tests => 32;
 
 # inflation test
 my $event = $schema->resultset("Event")->find(1);
@@ -58,6 +58,11 @@
         hour => 13, minute => 34, second => 56, time_zone => "America/New_York" ),
 });
 
+is ($event_tz->starts_at->day_name, "Montag", 'Locale de_DE loaded: day_name');
+is ($event_tz->starts_at->month_name, "Dezember", 'Locale de_DE loaded: month_name');
+is ($event_tz->created_on->day_name, "Tuesday", 'Default locale loaded: day_name');
+is ($event_tz->created_on->month_name, "January", 'Default locale loaded: month_name');
+
 my $starts_at = $event_tz->starts_at;
 is("$starts_at", '2007-12-31T00:00:00', 'Correct date/time using timezone');
 

Modified: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/EventTZ.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/EventTZ.pm	2009-02-07 13:29:46 UTC (rev 5418)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/EventTZ.pm	2009-02-07 13:40:41 UTC (rev 5419)
@@ -10,7 +10,7 @@
 
 __PACKAGE__->add_columns(
   id => { data_type => 'integer', is_auto_increment => 1 },
-  starts_at => { data_type => 'datetime', extra => { timezone => "America/Chicago" } },
+  starts_at => { data_type => 'datetime', extra => { timezone => "America/Chicago", locale => 'de_DE' } },
   created_on => { data_type => 'timestamp', extra => { timezone => "America/Chicago", floating_tz_ok => 1 } },
 );
 




More information about the Bast-commits mailing list