Skip to content

Commit

Permalink
secondsToInterval has an inclusive interval comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
perlDreamer committed Sep 22, 2010
1 parent 25181ae commit ecbfc1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/WebGUI/Session/DateTime.pm
Expand Up @@ -828,7 +828,7 @@ sub secondsToInterval {
my $seconds = shift;
my $i18n = WebGUI::International->new($self->session, 'WebGUI');
for my $unit (sort { $b <=> $a } keys %intervals) {
if ($seconds > $unit) {
if ($seconds >= $unit) {
return (sprintf('%.0f', $seconds / $unit), $i18n->get($intervals{$unit}));
}
}
Expand Down
24 changes: 13 additions & 11 deletions t/Session/DateTime.t
Expand Up @@ -15,7 +15,7 @@ use File::Spec;
use WebGUI::Test;
use WebGUI::Session;

use Test::More tests => 90; # increment this value for each test you create
use Test::More tests => 92; # increment this value for each test you create

local @INC = @INC;
unshift @INC, File::Spec->catdir( WebGUI::Test->getTestCollateralPath, 'Session-DateTime', 'lib' );
Expand Down Expand Up @@ -218,16 +218,18 @@ cmp_ok(
####################################################

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)), "1 Week(s)", "secondsToInterval(), days, longer than a week");
is(join(" ",$dt->secondsToInterval(60*60*24*363)), "12 Month(s)", "secondsToInterval(), days, longer than a month");
is(join(" ",$dt->secondsToInterval(60*60*24*365*2.4)), "2 Year(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)), "3 Year(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");
is(join(" ",$dt->secondsToInterval(60*60*24*180)), "6 Month(s)", "... months");
is(join(" ",$dt->secondsToInterval(60*60*24*7*3)), "3 Week(s)", "... weeks");
is(join(" ",$dt->secondsToInterval(60*60*24*5)), "5 Day(s)", "... days");
is(join(" ",$dt->secondsToInterval(60*60*24*8)), "1 Week(s)", "... days, longer than a week");
is(join(" ",$dt->secondsToInterval(60*60*24*363)), "12 Month(s)", "... days, longer than a month");
is(join(" ",$dt->secondsToInterval(60*60*24*365*2.4)), "2 Year(s)", "... days, longer than a year");
is(join(" ",$dt->secondsToInterval(60*60*18)), "18 Hour(s)", "... hours");
is(join(" ",$dt->secondsToInterval(60*60*24*365*2.9)), "3 Year(s)", "... hours, longer than a year");
is(join(" ",$dt->secondsToInterval(60*27)), "27 Minute(s)", "... minutes");
is(join(" ",$dt->secondsToInterval(59)), "59 Second(s)", "... seconds");
is(join(" ",$dt->secondsToInterval(3600)), "1 Hour(s)", "... exactly 1 hour");
is(join(" ",$dt->secondsToInterval(60)), "1 Minute(s)", "... exactly 1 minute");

####################################################
#
Expand Down

0 comments on commit ecbfc1a

Please sign in to comment.