From ecbfc1a8274c4ac059deee407e862bfe42170b0b Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 22 Sep 2010 10:46:10 -0700 Subject: [PATCH] secondsToInterval has an inclusive interval comparison --- lib/WebGUI/Session/DateTime.pm | 2 +- t/Session/DateTime.t | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/WebGUI/Session/DateTime.pm b/lib/WebGUI/Session/DateTime.pm index fd344b515..fbf2b0dc7 100644 --- a/lib/WebGUI/Session/DateTime.pm +++ b/lib/WebGUI/Session/DateTime.pm @@ -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})); } } diff --git a/t/Session/DateTime.t b/t/Session/DateTime.t index 3ceb49822..681c9f1c3 100644 --- a/t/Session/DateTime.t +++ b/t/Session/DateTime.t @@ -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' ); @@ -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"); #################################################### #