File Coverage

lib/Spreadsheet/Engine/Function/NOW.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 35 35 100.0


line stmt bran cond sub pod time code
1             package Spreadsheet::Engine::Function::NOW;
2              
3 28     28   159 use strict;
  28         54  
  28         922  
4 28     28   142 use warnings;
  28         65  
  28         737  
5              
6 28     28   142 use base 'Spreadsheet::Engine::Fn::base';
  28         65  
  28         2121  
7 28     28   171 use Time::Local;
  28         51  
  28         7804  
8              
9 230     230 1 557 sub argument_count { 0 }
10 78     78 1 4851 sub result_type { 'nd' }
11              
12             sub _start_time {
13 78     78   149 my ($self, $time) = @_;
14 78         3745 return timegm((localtime($time))[ 0 .. 5 ]);
15             }
16              
17             sub result {
18 230     230 1 365 my $self = shift;
19 230         398 my $startval = time();
20 230         315 my $s1970 = 25569; # 1/1/1970 starting with 1/1/1900 as 1
21 230         299 my $seconds_in_a_day = 24 * 60 * 60;
22 230         937 my $time2 = $self->_start_time($startval);
23 230         7145 my $offset = ($time2 - $startval) / (60 * 60);
24 230         424 my $nowdays = $s1970 + $time2 / $seconds_in_a_day;
25 230         1859 return Spreadsheet::Engine::Value->new(
26             type => $self->result_type,
27             value => $nowdays,
28             );
29             }
30              
31             1;
32              
33             __END__