fixed #10590: Session::DateTime->secondsToInterval doesn't allow 7 weeks

This commit is contained in:
Graham Knop 2009-07-23 22:04:27 +00:00
parent 8bd99ac6e9
commit 56773eefc1
3 changed files with 28 additions and 41 deletions

View file

@ -1,4 +1,5 @@
7.7.16 7.7.16
- fixed #10590: Session::DateTime->secondsToInterval doesn't allow 7 weeks
- Fix template not found diagnostics. - Fix template not found diagnostics.
- fixed #10665: Navigations with old templates still in 7.7.16 - fixed #10665: Navigations with old templates still in 7.7.16
- fixed #10662: Manage Clipboard / delete item - fixed #10662: Manage Clipboard / delete item

View file

@ -821,39 +821,23 @@ The number of seconds in the interval.
=cut =cut
sub secondsToInterval { sub secondsToInterval {
my $self = shift; my $self = shift;
my $seconds = shift; my $seconds = shift;
my $i18n = WebGUI::International->new($self->session, 'WebGUI'); my $i18n = WebGUI::International->new($self->session, 'WebGUI');
my ($interval, $units); my %units = (
if ($seconds >= 31536000) { 31536000 => "703", # years
$interval = round($seconds/31536000); 2592000 => "702", # months
$units = $i18n->get("703"); 604800 => "701", # weeks
} 86400 => "700", # days
elsif ($seconds >= 2592000) { 3600 => "706", # hours
$interval = round($seconds/2592000); 60 => "705", # minutes
$units = $i18n->get("702"); );
} for my $unit (sort { $b <=> $a } keys %units) {
elsif ($seconds >= 604800) { if ($seconds % $unit == 0) {
$interval = round($seconds/604800); return ($seconds / $unit, $i18n->get($units{$unit}));
$units = $i18n->get("701"); }
}
elsif ($seconds >= 86400) {
$interval = round($seconds/86400);
$units = $i18n->get("700");
} }
elsif ($seconds >= 3600) { return ($seconds, $i18n->get("704")); # seconds
$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);
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -17,7 +17,7 @@ use File::Spec;
use WebGUI::Test; use WebGUI::Test;
use WebGUI::Session; 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(); 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)), "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*180)), "6 Month(s)", "secondsToInterval(), months");
is(join(" ",$dt->secondsToInterval(60*60*24*365*2.9)), "3 Year(s)", "secondsToInterval(), years, rounded up"); is(join(" ",$dt->secondsToInterval(60*60*24*7*3)), "3 Week(s)", "secondsToInterval(), weeks");
is(join(" ",$dt->secondsToInterval(60*60*24*363)), "12 Month(s)", "secondsToInterval(), months"); is(join(" ",$dt->secondsToInterval(60*60*24*5)), "5 Day(s)", "secondsToInterval(), days");
is(join(" ",$dt->secondsToInterval(60*60*24*7*3)), "3 Week(s)", "secondsToInterval(), weeks"); is(join(" ",$dt->secondsToInterval(60*60*24*8)), "8 Day(s)", "secondsToInterval(), days, longer than a week");
is(join(" ",$dt->secondsToInterval(60*60*24*5)), "5 Day(s)", "secondsToInterval(), days"); is(join(" ",$dt->secondsToInterval(60*60*24*363)), "363 Day(s)", "secondsToInterval(), days, longer than a month");
is(join(" ",$dt->secondsToInterval(60*60*18)), "18 Hour(s)", "secondsToInterval(), hours"); is(join(" ",$dt->secondsToInterval(60*60*24*365*2.4)), "876 Day(s)", "secondsToInterval(), days, longer than a year");
is(join(" ",$dt->secondsToInterval(60*27)), "27 Minute(s)", "secondsToInterval(), minutes"); is(join(" ",$dt->secondsToInterval(60*60*18)), "18 Hour(s)", "secondsToInterval(), hours");
is(join(" ",$dt->secondsToInterval(59)), "59 Second(s)", "secondsToInterval(), seconds"); 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");
#################################################### ####################################################
# #