fixed #10590: Session::DateTime->secondsToInterval doesn't allow 7 weeks
This commit is contained in:
parent
8bd99ac6e9
commit
56773eefc1
3 changed files with 28 additions and 41 deletions
|
|
@ -1,4 +1,5 @@
|
|||
7.7.16
|
||||
- fixed #10590: Session::DateTime->secondsToInterval doesn't allow 7 weeks
|
||||
- Fix template not found diagnostics.
|
||||
- fixed #10665: Navigations with old templates still in 7.7.16
|
||||
- fixed #10662: Manage Clipboard / delete item
|
||||
|
|
|
|||
|
|
@ -821,39 +821,23 @@ The number of seconds in the interval.
|
|||
=cut
|
||||
|
||||
sub secondsToInterval {
|
||||
my $self = shift;
|
||||
my $seconds = shift;
|
||||
my $self = shift;
|
||||
my $seconds = shift;
|
||||
my $i18n = WebGUI::International->new($self->session, 'WebGUI');
|
||||
my ($interval, $units);
|
||||
if ($seconds >= 31536000) {
|
||||
$interval = round($seconds/31536000);
|
||||
$units = $i18n->get("703");
|
||||
}
|
||||
elsif ($seconds >= 2592000) {
|
||||
$interval = round($seconds/2592000);
|
||||
$units = $i18n->get("702");
|
||||
}
|
||||
elsif ($seconds >= 604800) {
|
||||
$interval = round($seconds/604800);
|
||||
$units = $i18n->get("701");
|
||||
}
|
||||
elsif ($seconds >= 86400) {
|
||||
$interval = round($seconds/86400);
|
||||
$units = $i18n->get("700");
|
||||
my %units = (
|
||||
31536000 => "703", # years
|
||||
2592000 => "702", # months
|
||||
604800 => "701", # weeks
|
||||
86400 => "700", # days
|
||||
3600 => "706", # hours
|
||||
60 => "705", # minutes
|
||||
);
|
||||
for my $unit (sort { $b <=> $a } keys %units) {
|
||||
if ($seconds % $unit == 0) {
|
||||
return ($seconds / $unit, $i18n->get($units{$unit}));
|
||||
}
|
||||
}
|
||||
elsif ($seconds >= 3600) {
|
||||
$interval = round($seconds/3600);
|
||||
$units = $i18n->get("706");
|
||||
}
|
||||
elsif ($seconds >= 60) {
|
||||
$interval = round($seconds/60);
|
||||
$units = $i18n->get("705");
|
||||
}
|
||||
else {
|
||||
$interval = $seconds;
|
||||
$units = $i18n->get("704");
|
||||
}
|
||||
return ($interval, $units);
|
||||
return ($seconds, $i18n->get("704")); # seconds
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use File::Spec;
|
|||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
|
||||
use Test::More tests => 77; # increment this value for each test you create
|
||||
use Test::More tests => 79; # increment this value for each test you create
|
||||
|
||||
installBadLocale();
|
||||
|
||||
|
|
@ -216,15 +216,17 @@ cmp_ok(
|
|||
#
|
||||
####################################################
|
||||
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*365*2)), "2 Year(s)", "secondsToInterval(), years");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*365*2.4)), "2 Year(s)", "secondsToInterval(), years, rounded down");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*365*2.9)), "3 Year(s)", "secondsToInterval(), years, rounded up");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*363)), "12 Month(s)", "secondsToInterval(), months");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*7*3)), "3 Week(s)", "secondsToInterval(), weeks");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*5)), "5 Day(s)", "secondsToInterval(), days");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*18)), "18 Hour(s)", "secondsToInterval(), hours");
|
||||
is(join(" ",$dt->secondsToInterval(60*27)), "27 Minute(s)", "secondsToInterval(), minutes");
|
||||
is(join(" ",$dt->secondsToInterval(59)), "59 Second(s)", "secondsToInterval(), seconds");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*365*2)), "2 Year(s)", "secondsToInterval(), years");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*180)), "6 Month(s)", "secondsToInterval(), months");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*7*3)), "3 Week(s)", "secondsToInterval(), weeks");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*5)), "5 Day(s)", "secondsToInterval(), days");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*8)), "8 Day(s)", "secondsToInterval(), days, longer than a week");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*363)), "363 Day(s)", "secondsToInterval(), days, longer than a month");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*365*2.4)), "876 Day(s)", "secondsToInterval(), days, longer than a year");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*18)), "18 Hour(s)", "secondsToInterval(), hours");
|
||||
is(join(" ",$dt->secondsToInterval(60*60*24*365*2.9)), "25404 Hour(s)", "secondsToInterval(), hours, longer than a year");
|
||||
is(join(" ",$dt->secondsToInterval(60*27)), "27 Minute(s)", "secondsToInterval(), minutes");
|
||||
is(join(" ",$dt->secondsToInterval(59)), "59 Second(s)", "secondsToInterval(), seconds");
|
||||
|
||||
####################################################
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue