From 9259e1db23f01bafa5267856020fec67cc349c31 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 24 Jul 2009 00:12:56 +0000 Subject: [PATCH] And restore the original method, and add tests to catch the approximation in Session/DateTime.t instead of relying on Asset/Story.t --- lib/WebGUI/Session/DateTime.pm | 46 +++++++++++++++++++++++----------- t/Storage.t | 2 +- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/WebGUI/Session/DateTime.pm b/lib/WebGUI/Session/DateTime.pm index e2baa9c79..2230aabd4 100644 --- a/lib/WebGUI/Session/DateTime.pm +++ b/lib/WebGUI/Session/DateTime.pm @@ -822,23 +822,39 @@ 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 %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})); - } + 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"); } - return ($seconds, $i18n->get("704")); # seconds + 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); } #------------------------------------------------------------------- diff --git a/t/Storage.t b/t/Storage.t index 55d33911e..b53451aa2 100644 --- a/t/Storage.t +++ b/t/Storage.t @@ -31,7 +31,7 @@ my $cwd = Cwd::cwd(); my ($extensionTests, $fileIconTests) = setupDataDrivenTests($session); -my $numTests = 136; # increment this value for each test you create +my $numTests = 127; # increment this value for each test you create plan tests => $numTests + scalar @{ $extensionTests } + scalar @{ $fileIconTests }; my $uploadDir = $session->config->get('uploadsPath');