diff options
author | Matthew Somerville <matthew@mysociety.org> | 2013-02-14 16:15:32 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2013-02-14 16:36:17 +0000 |
commit | 5c88c6954449bb6d2dbc1a6d1142d08adbc89d55 (patch) | |
tree | 8403f80f6d80cb60541ae90a0fe6e1b4ea8d324e /perllib/FixMyStreet/DB/Result/Comment.pm | |
parent | f8fef5162bddb4e10f22f8ddce8314a585ec8b4b (diff) |
Remove *_local tz functions, set timezone on fetching original columns from database.
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Comment.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 33fbb9356..eb9e52a65 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -116,23 +116,21 @@ with 'FixMyStreet::Roles::Abuser'; my $tz = DateTime::TimeZone->new( name => "local" ); -sub created_local { - my $self = shift; - - return $self->created - ? $self->created->set_time_zone($tz) - : $self->created; -} - -sub confirmed_local { - my $self = shift; - - # if confirmed is null then it doesn't get inflated so don't - # try and set the timezone - return $self->confirmed - ? $self->confirmed->set_time_zone($tz) - : $self->confirmed; -} +my $tz_f; +$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) + if FixMyStreet->config('TIME_ZONE'); + +my $stz = sub { + my ( $orig, $self ) = ( shift, shift ); + my $s = $self->$orig(@_); + return $s unless $s && UNIVERSAL::isa($s, "DateTime"); + $s->set_time_zone($tz); + $s->set_time_zone($tz_f) if $tz_f; + return $s; +}; + +around created => $stz; +around confirmed => $stz; # You can replace this text with custom code or comments, and it will be preserved on regeneration |