Refactor exact duration intervals into a separate method.

This commit is contained in:
Colin Kuskie 2009-07-23 23:47:45 +00:00
parent 56773eefc1
commit 3c4ae9aa82
3 changed files with 57 additions and 6 deletions

View file

@ -812,7 +812,8 @@ sub new {
=head2 secondsToInterval ( seconds )
Returns an interval and internationalized units derived the number of seconds.
Returns an interval and internationalized units derived the number
of seconds, rounding to the closest unit smaller than the interval.
=head3 seconds
@ -842,6 +843,38 @@ sub secondsToInterval {
#-------------------------------------------------------------------
=head2 secondsToExactInterval ( seconds )
Returns an interval and internationalized units derived the number of seconds.
=head3 seconds
The number of seconds in the interval.
=cut
sub secondsToExactInterval {
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}));
}
}
return ($seconds, $i18n->get("704")); # seconds
}
#-------------------------------------------------------------------
=head2 secondsToTime ( seconds )
Returns a time string of the format HH::MM::SS on a 24 hour clock. See also timeToSeconds().