From: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Date: Sat, 18 Jun 2016 11:37:10 +0000 (+0100)
Subject: Restore 'timezone' field in column info ( extends eef9b484 )
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=591df363660658ed30e60438c5251ca480925a6f;p=dbsrgits%2FDBIx-Class.git

Restore 'timezone' field in column info ( extends eef9b484 )

The keys in the column info hash are semi-public API, and 'timezone' in
particular is used by DBIx::Class::InflateColumn::DateTime::WithTimeZone.

Keep documenting time_zone as the main name, but note that it's stored
under both keys.
---

diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm
index 4f08c1f..b284a64 100644
--- a/lib/DBIx/Class/InflateColumn/DateTime.pm
+++ b/lib/DBIx/Class/InflateColumn/DateTime.pm
@@ -39,7 +39,10 @@ If you want to set a specific time zone and locale for that field, use:
 
 Note: DBIC before 0.082900 only accepted C<timezone>, and silently discarded
 any C<time_zone> arguments. For backwards compatibility, C<timezone> will
-continue being accepted as a synonym for C<time_zone>.
+continue being accepted as a synonym for C<time_zone>, and the value will
+continue to be available in the
+L<< C<column_info> hash|DBIx::Class::ResultSource/column_info >>
+under both names.
 
 If you want to inflate no matter what data_type your column is,
 use inflate_datetime or inflate_date:
@@ -165,10 +168,15 @@ sub register_column {
     }
   }
 
+  # Store the time zone under both 'timezone' for backwards compatibility and
+  # 'time_zone' for DateTime ecosystem consistency
   if ( defined $info->{timezone} ) {
-    $self->throw_exception("Cannot specify both 'timezone' and 'time_zone' in '$column' column defintion.")
-      if defined $info->{time_zone};
-    $info->{time_zone} = delete $info->{timezone};
+    $self->throw_exception("Conflicting 'timezone' and 'time_zone' values in '$column' column defintion.")
+      if defined $info->{time_zone} and $info->{time_zone} ne $info->{timezone};
+    $info->{time_zone} = $info->{timezone};
+  }
+  elsif ( defined $info->{time_zone} ) {
+    $info->{timezone} = $info->{time_zone};
   }
 
   # shallow copy to avoid unfounded(?) Devel::Cycle complaints
diff --git a/t/icdt/offline_pg.t b/t/icdt/offline_pg.t
index 1a04fce..bfd931c 100644
--- a/t/icdt/offline_pg.t
+++ b/t/icdt/offline_pg.t
@@ -23,6 +23,13 @@ DBICTest::Schema->load_classes('EventTZPg');
   my $parser = $s->storage->datetime_parser;
   is( $parser, 'DateTime::Format::Pg', 'datetime_parser is as expected');
 
+  my $colinfo = $s->source('EventTZPg')->column_info('created_on');
+  is (
+    $colinfo->{timezone},
+    $colinfo->{time_zone},
+    'Legacy timezone key is still present in colinfo',
+  );
+
   ok (!$s->storage->_dbh, 'still not connected');
 }