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/Questionnaire.pm | |
parent | f8fef5162bddb4e10f22f8ddce8314a585ec8b4b (diff) |
Remove *_local tz functions, set timezone on fetching original columns from database.
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Questionnaire.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Questionnaire.pm | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm index b6791603a..fcaa17d99 100644 --- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm @@ -44,23 +44,25 @@ __PACKAGE__->belongs_to( # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:NGlSRjoBpDoIvK3EueqN6Q use DateTime::TimeZone; +use Moose; +use namespace::clean -except => [ 'meta' ]; my $tz = DateTime::TimeZone->new( name => "local" ); -sub whensent_local { - my $self = shift; +my $tz_f; +$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) + if FixMyStreet->config('TIME_ZONE'); - return $self->whensent - ? $self->whensent->set_time_zone($tz) - : $self->whensent; -} +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; +}; -sub whenanswered_local { - my $self = shift; - - return $self->whenanswered - ? $self->whenanswered->set_time_zone($tz) - : $self->whenanswered; -} +around whensent => $stz; +around whenanswered => $stz; 1; |