File Coverage

blib/lib/Astro/App/Satpass2/FormatTime/POSIX/Strftime.pm
Criterion Covered Total %
statement 35 38 92.1
branch 8 12 66.6
condition 0 3 0.0
subroutine 10 10 100.0
pod 1 1 100.0
total 54 64 84.3


line stmt bran cond sub pod time code
1             package Astro::App::Satpass2::FormatTime::POSIX::Strftime;
2              
3 20     20   358 use 5.008;
  20         78  
4              
5 20     20   110 use strict;
  20         215  
  20         649  
6 20     20   444 use warnings;
  20         98  
  20         1074  
7              
8 20     20   107 use parent qw{ Astro::App::Satpass2::FormatTime };
  20         34  
  20         156  
9              
10 20     20   14891 use Astro::Coord::ECI::Utils qw{ gm_strftime local_strftime };
  20         282574  
  20         2378  
11 20     20   12098 use Astro::App::Satpass2::FormatTime::Strftime;
  20         75  
  20         1564  
12 20     20   147 use Astro::App::Satpass2::Utils qw{ ARRAY_REF @CARP_NOT };
  20         87  
  20         1938  
13 20     20   123 use POSIX ();
  20         42  
  20         9578  
14              
15             our $VERSION = '0.057';
16              
17             sub format_datetime {
18 618     618 1 1588 my ( $self, $tplt, $time, $gmt ) = @_;
19 618         1839 $time = $self->__round_time_value( $time );
20 618 100       2268 defined $gmt or $gmt = $self->gmt();
21 618 100       1719 if ( ARRAY_REF eq ref $time ) {
    50          
22             # NOTE that this is not documented, and is used only to
23             # determine the maximum width generated by the given time
24             # format, so I believe it can stand as-is. IF this is wrong AND
25             # the strftime() behavior of Perl 5.39.8 and 5.39.9 makes it int
26             # 5.40, I will need to set the zone to 'GMT' if $gmt is true.
27             $gmt
28 330 50       1489 and local $ENV{TZ} = 'GMT';
29 330         498 return POSIX::strftime( $tplt, @{ $time } );
  330         3799  
30             } elsif ( $gmt ) {
31 288         2179 return gm_strftime( $tplt, $time );
32             } else {
33 0         0 my $tz = $self->tz();
34             defined $tz
35             and $tz ne ''
36 0 0 0     0 and local $ENV{TZ} = $tz;
37 0         0 return local_strftime( $tplt, $time );
38             }
39             }
40              
41             {
42             my %adjuster = (
43             year => sub { $_[0][5] = $_[1] - 1900; return },
44             month => sub { $_[0][4] = $_[1] - 1; return },
45             day => sub { $_[0][3] = $_[1]; return },
46             hour => sub { $_[0][2] = $_[1]; return },
47             minute => sub { $_[0][1] = $_[1]; return },
48             second => sub { $_[0][0] = $_[1]; return },
49             );
50              
51             sub __format_datetime_width_adjust_object {
52 390     390   676 my ( undef, $obj, $name, $val ) = @_; # Invocant unused
53 390 100       785 $obj or $obj = [ 0, 0, 0, 1, 0, 200 ];
54 390         1026 $adjuster{$name}->( $obj, $val );
55 390         689 return $obj;
56             }
57              
58             }
59              
60             1;
61              
62             __END__