diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-10-08 18:18:09 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@firefly.ukcod.org.uk> | 2012-10-08 18:18:29 +0100 |
commit | 7a3b06d61f63f34eed12029c974dc66d6ffbdc87 (patch) | |
tree | 816d6ef3e8189a6af36e672949340be997b06074 | |
parent | 0a07e772c8c7682f0b8717bed5a8b7e321c25665 (diff) |
Add TIME_ZONE variable for local display of times.
-rw-r--r-- | .travis.yml | 4 | ||||
-rw-r--r-- | conf/general.yml-example | 4 | ||||
-rw-r--r-- | perllib/Utils.pm | 31 |
3 files changed, 27 insertions, 12 deletions
diff --git a/.travis.yml b/.travis.yml index 6232140a4..dcf35ab60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,10 @@ language: perl perl: - "5.14" +branches: + only: + - master + before_install: - sudo apt-get update -qq - sudo apt-get install -qq jhead diff --git a/conf/general.yml-example b/conf/general.yml-example index b826dd89d..8d5018362 100644 --- a/conf/general.yml-example +++ b/conf/general.yml-example @@ -36,6 +36,10 @@ EXAMPLE_PLACES: [ 'High Street', 'Main Street' ] LANGUAGES: - 'en-gb,English,en_GB' +# If you're running an installation that is being used in a different time zone +# from the server, you can set the time zone here (standard time zone string) +TIME_ZONE: "" + # File locations for uploaded photos and cached geocoding results. UPLOAD_DIR: '../upload/' GEO_CACHE: '../cache/' diff --git a/perllib/Utils.pm b/perllib/Utils.pm index 23a87485d..8a4c4265d 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -12,9 +12,9 @@ package Utils; use strict; +use DateTime; use Encode; use File::Slurp qw(); -use POSIX qw(strftime); use mySociety::DBHandle qw(dbh); use mySociety::GeoUtil; use mySociety::Locale; @@ -251,25 +251,32 @@ sub cleanup_text { } sub prettify_epoch { - my ( $s, $type ) = @_; + my ( $epoch, $type ) = @_; $type = 'short' if $type eq '1'; - my @s = localtime($s); + my $dt = DateTime->from_epoch( epoch => $epoch, time_zone => 'local' ); + $dt->set_time_zone( FixMyStreet->config('TIME_ZONE') ) + if FixMyStreet->config('TIME_ZONE'); + + my $now = DateTime->now( time_zone => 'local' ); + $now->set_time_zone( FixMyStreet->config('TIME_ZONE') ) + if FixMyStreet->config('TIME_ZONE'); + my $tt = ''; - $tt = strftime('%H:%M', @s) unless $type eq 'date'; - my @t = localtime(); - if (strftime('%Y%m%d', @s) eq strftime('%Y%m%d', @t)) { + $tt = $dt->strftime('%H:%M') unless $type eq 'date'; + + if ($dt->strftime('%Y%m%d') eq $now->strftime('%Y%m%d')) { return "$tt " . _('today'); } $tt .= ', ' unless $type eq 'date'; - if (strftime('%Y %U', @s) eq strftime('%Y %U', @t)) { - $tt .= decode_utf8(strftime('%A', @s)); + if ($dt->strftime('%Y %U') eq $now->strftime('%Y %U')) { + $tt .= decode_utf8($dt->strftime('%A')); } elsif ($type eq 'short') { - $tt .= decode_utf8(strftime('%e %b %Y', @s)); - } elsif (strftime('%Y', @s) eq strftime('%Y', @t)) { - $tt .= decode_utf8(strftime('%A %e %B %Y', @s)); + $tt .= decode_utf8($dt->strftime('%e %b %Y')); + } elsif ($dt->strftime('%Y') eq $now->strftime('%Y')) { + $tt .= decode_utf8($dt->strftime('%A %e %B %Y')); } else { - $tt .= decode_utf8(strftime('%a %e %B %Y', @s)); + $tt .= decode_utf8($dt->strftime('%a %e %B %Y')); } return $tt; } |