File Coverage

lib/Spreadsheet/Engine/Fn/hms.pm
Criterion Covered Total %
statement 21 21 100.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 29 30 96.6


line stmt bran cond sub pod time code
1             package Spreadsheet::Engine::Fn::hms;
2              
3 28     28   167 use strict;
  28         59  
  28         893  
4 28     28   158 use warnings;
  28         55  
  28         719  
5              
6 28     28   136 use base 'Spreadsheet::Engine::Fn::math';
  28         51  
  28         6860  
7              
8 582     582 1 2172 sub signature { 'n' }
9              
10             sub calculate {
11 291     291 1 9693 my ($self, $value) = @_;
12              
13 291         748 my $fraction = $value - int($value); # fraction of a day
14 291         615 $fraction *= 24;
15              
16 291         599 my $H = int($fraction);
17 291         462 $fraction -= int($fraction);
18 291         480 $fraction *= 60;
19              
20 291         389 my $M = int($fraction);
21 291         331 $fraction -= int($fraction);
22 291         361 $fraction *= 60;
23              
24 291 50       956 my $S = int($fraction + ($value >= 0 ? 0.5 : -0.5));
25 291         1594 return $self->_calculate($H, $M, $S);
26             }
27              
28             1;
29              
30             __END__