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

@ -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
}
#-------------------------------------------------------------------