diff options
author | Marius Halden <marius.h@lden.org> | 2017-05-28 21:31:42 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2017-05-28 21:31:42 +0200 |
commit | 987124b09a32248414faf4d0d6615d43b29ac6f6 (patch) | |
tree | a549db8af723c981d3b346e855f25d6fd5ff8aa7 /perllib/Utils.pm | |
parent | dbf56159e44c1560a413022451bf1a1c4cb22a52 (diff) | |
parent | a085b63ce09f87e83b75cda9b9cd08aadfe75d61 (diff) |
Merge tag 'v2.0.4' into fiksgatami-dev
Diffstat (limited to 'perllib/Utils.pm')
-rw-r--r-- | perllib/Utils.pm | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/perllib/Utils.pm b/perllib/Utils.pm index 7dd2a3f39..6ba20e9d3 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -99,7 +99,7 @@ sub truncate_coordinate { Strip leading and trailing white space from a string. Also reduces all white space to a single space. -Trim +Trim =cut @@ -195,7 +195,28 @@ sub prettify_dt { # argument is duration in seconds, rounds to the nearest minute sub prettify_duration { my ($s, $nearest) = @_; - if ($nearest eq 'week') { + + unless ( defined $nearest ) { + if ($s < 3600) { + $nearest = 'minute'; + } elsif ($s < 3600*24) { + $nearest = 'hour'; + } elsif ($s < 3600*24*7) { + $nearest = 'day'; + } elsif ($s < 3600*24*7*4) { + $nearest = 'week'; + } elsif ($s < 3600*24*7*4*12) { + $nearest = 'month'; + } else { + $nearest = 'year'; + } + } + + if ($nearest eq 'year') { + $s = int(($s+60*60*24*3.5)/60/60/24/7/4/12)*60*60*24*7*4*12; + } elsif ($nearest eq 'month') { + $s = int(($s+60*60*24*3.5)/60/60/24/7/4)*60*60*24*7*4; + } elsif ($nearest eq 'week') { $s = int(($s+60*60*24*3.5)/60/60/24/7)*60*60*24*7; } elsif ($nearest eq 'day') { $s = int(($s+60*60*12)/60/60/24)*60*60*24; @@ -206,6 +227,8 @@ sub prettify_duration { return _('less than a minute') if $s == 0; } my @out = (); + _part(\$s, 60*60*24*7*4*12, \@out); + _part(\$s, 60*60*24*7*4, \@out); _part(\$s, 60*60*24*7, \@out); _part(\$s, 60*60*24, \@out); _part(\$s, 60*60, \@out); @@ -217,7 +240,11 @@ sub _part { if ($$s >= $m) { my $i = int($$s / $m); my $str; - if ($m == 60*60*24*7) { + if ($m == 60*60*24*7*4*12) { + $str = mySociety::Locale::nget("%d year", "%d years", $i); + } elsif ($m == 60*60*24*7*4) { + $str = mySociety::Locale::nget("%d month", "%d months", $i); + } elsif ($m == 60*60*24*7) { $str = mySociety::Locale::nget("%d week", "%d weeks", $i); } elsif ($m == 60*60*24) { $str = mySociety::Locale::nget("%d day", "%d days", $i); |