diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-02-10 17:10:40 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-02-13 10:09:33 +0000 |
commit | 3571f96251df08dd8a9dda3ec4e1fadf30d6c63d (patch) | |
tree | 6cd0d05d06a51dfdcbe183c4c10b38c0a15c6231 /perllib/FixMyStreet.pm | |
parent | 9591ba909210b2a628237074b54e5eb3c6536856 (diff) |
Create timezone objects only once at startup.
Cache a DateTime::TimeZone::Local object, so that in an environment
where /etc/localtime is a copy of a timezone file, we don't repeatedly
walk all the timezone files to find the matching one.
Diffstat (limited to 'perllib/FixMyStreet.pm')
-rw-r--r-- | perllib/FixMyStreet.pm | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/perllib/FixMyStreet.pm b/perllib/FixMyStreet.pm index f3b72c4d0..76760b967 100644 --- a/perllib/FixMyStreet.pm +++ b/perllib/FixMyStreet.pm @@ -6,6 +6,7 @@ use warnings; use Path::Class; my $ROOT_DIR = file(__FILE__)->parent->parent->absolute->resolve; +use DateTime::TimeZone; use Readonly; use Sub::Override; @@ -217,4 +218,23 @@ sub get_email_template { return $template; } +my $tz = DateTime::TimeZone->new( name => "local" ); +my $tz_f; +$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) + if FixMyStreet->config('TIME_ZONE'); + +sub local_time_zone { + return $tz; +} + +sub time_zone { + return $tz_f; +} + +sub set_time_zone { + my ($class, $dt) = @_; + $dt->set_time_zone($tz); + $dt->set_time_zone($tz_f) if $tz_f; +} + 1; |