hi,
attach the patch and test for handling timezone and
datetime_undef_if_invalid correctly.
Please be indulge with me and the result - if there any missing or wrong
with this first patch and test - please correct me.
Jens
Index: t/89inflate_datetime.t
===================================================================
--- t/89inflate_datetime.t (Revision 4805)
+++ t/89inflate_datetime.t (Arbeitskopie)
@@ -10,7 +10,7 @@
eval { require DateTime::Format::MySQL };
plan skip_all => "Need DateTime::Format::MySQL for inflation tests" if $@;
-plan tests => 21;
+plan tests => 25;
# inflation test
my $event = $schema->resultset("Event")->find(1);
@@ -87,8 +87,31 @@
$invalid->update;
{
- local $@;
+ local $@;
eval { $invalid->created_on };
like( $@, qr/invalid date format/i, "Invalid date format exception");
}
+my $datetime_timezone_invalid = $schema->resultset('Event')->create( {
+
+ starts_at => DateTime->new(year=>2007, month=>12, day=>31, time_zone =>
"America/Chicago" ),
+ created_on => DateTime->new(year=>2006, month=>1, day=>31, hour => 13,
minute => 34, second => 56, time_zone => "America/New_York" ),
+ ends_at => "",
+});
+
+is( $datetime_timezone_invalid->ends_at, undef, "Inflate to undef");
+
+$datetime_timezone_invalid->update({ ends_at => undef } );
+
+is( $datetime_timezone_invalid->ends_at, undef, "Inflate to undef");
+
+my $datetime_timezone_valid = $schema->resultset('Event')->create( {
+
+ starts_at => DateTime->new(year=>2007, month=>12, day=>31, time_zone =>
"America/Chicago" ),
+ created_on => DateTime->new(year=>2006, month=>1, day=>31, hour => 13,
minute => 34, second => 56, time_zone => "America/New_York" ),
+ ends_at => DateTime->new(year=>2008, month=>1, day=>1, hour => 1,
minute => 0, second => 0, time_zone => "Europe/Berlin" ) ,
+});
+
+isa_ok( $datetime_timezone_valid->ends_at,'DateTime', "Inflate to DateTime");
+is( $datetime_timezone_valid->ends_at->time_zone->name, 'UTC', "Timezone is
UTC" );
+
Index: t/lib/sqlite.sql
===================================================================
--- t/lib/sqlite.sql (Revision 4805)
+++ t/lib/sqlite.sql (Arbeitskopie)
@@ -170,7 +170,8 @@
CREATE TABLE event (
id INTEGER PRIMARY KEY NOT NULL,
starts_at datetime NOT NULL,
- created_on timestamp NOT NULL
+ created_on timestamp NOT NULL,
+ ends_at datetime NULL
);
--
Index: t/lib/DBICTest/Schema/Event.pm
===================================================================
--- t/lib/DBICTest/Schema/Event.pm (Revision 4805)
+++ t/lib/DBICTest/Schema/Event.pm (Arbeitskopie)
@@ -11,7 +11,8 @@
__PACKAGE__->add_columns(
id => { data_type => 'integer', is_auto_increment => 1 },
starts_at => { data_type => 'datetime', datetime_undef_if_invalid => 1 },
- created_on => { data_type => 'timestamp' }
+ created_on => { data_type => 'timestamp' },
+ ends_at => { data_type => 'datetime', datetime_undef_if_invalid => 1,
extra => { timezone => 'UTC' }}
);
__PACKAGE__->set_primary_key('id');
Index: lib/DBIx/Class/InflateColumn/DateTime.pm
===================================================================
--- lib/DBIx/Class/InflateColumn/DateTime.pm (Revision 4805)
+++ lib/DBIx/Class/InflateColumn/DateTime.pm (Arbeitskopie)
@@ -90,7 +90,7 @@
my $dt = eval { $obj->_datetime_parser->$parse($value); };
die "Error while inflating ${value} for ${column} on ${self}: $@"
if $@ and not $undef_if_invalid;
- $dt->set_time_zone($timezone) if $timezone;
+ $dt->set_time_zone($timezone) if $timezone and $dt;
return $dt;
},
deflate => sub {
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]