File Coverage

blib/lib/DateTime/TimeZone/TAI.pm
Criterion Covered Total %
statement 29 32 90.6
branch 2 2 100.0
condition n/a
subroutine 9 12 75.0
pod 7 7 100.0
total 47 53 88.6


line stmt bran cond sub pod time code
1             package DateTime::TimeZone::TAI;
2              
3 2     2   227419 use strict;
  2         5  
  2         85  
4              
5 2     2   14 use vars qw ($VERSION);
  2         3  
  2         114  
6             $VERSION = '0.00_01';
7              
8 2     2   12 use base 'DateTime::TimeZone';
  2         7  
  2         1147  
9              
10 2     2   76383 use DateTime::LeapSecond;
  2         142510  
  2         111  
11              
12             # TAI-UTC on 1972-01-01
13 2     2   22 use constant TAI_OFFSET => 10;
  2         5  
  2         758  
14              
15             sub new
16             {
17 1     1 1 403 my $class = shift;
18              
19 1         7 return bless { name => 'TAI' }, $class;
20             }
21              
22 0     0 1 0 sub is_dst_for_datetime { 0 }
23              
24             sub offset_for_datetime {
25 21     21 1 7540 my $self = shift;
26              
27 21         59 my $offset = TAI_OFFSET + $_[0]->leap_seconds;
28              
29 21         197 return $offset;
30             }
31              
32             sub offset_for_local_datetime {
33 14     14 1 219 my $self = shift;
34              
35 14         40 my $rd_as_seconds = $_[0]->local_rd_as_seconds;
36 14         60 my $rd = int($rd_as_seconds/86_400);
37 14         18 my $seconds = $rd_as_seconds % 86_400;
38              
39 14         397 my $offset = TAI_OFFSET + DateTime::LeapSecond::leap_seconds($rd);
40              
41             # We assume that TAI - UTC is positive (and that the total offset is
42             # smaller than 86_400...)
43 14 100       165 if ($seconds < $offset) {
44 4         102 $offset = TAI_OFFSET + DateTime::LeapSecond::leap_seconds($rd - 1);
45             }
46              
47 14         69 return $offset;
48             }
49              
50 0     0 1 0 sub short_name_for_datetime { 'TAI' }
51              
52 0     0 1 0 sub category { undef }
53              
54 21     21 1 4198 sub is_utc { 0 }
55              
56             1;
57             __END__