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   291 use 5.008;
  20         69  
4              
5 20     20   75 use strict;
  20         205  
  20         356  
6 20     20   257 use warnings;
  20         111  
  20         977  
7              
8 20     20   81 use parent qw{ Astro::App::Satpass2::FormatTime };
  20         66  
  20         81  
9              
10 20     20   11734 use Astro::Coord::ECI::Utils qw{ gm_strftime local_strftime };
  20         193734  
  20         1636  
11 20     20   8343 use Astro::App::Satpass2::FormatTime::Strftime;
  20         53  
  20         1149  
12 20     20   98 use Astro::App::Satpass2::Utils qw{ ARRAY_REF @CARP_NOT };
  20         26  
  20         1513  
13 20     20   123 use POSIX ();
  20         29  
  20         6808  
14              
15             our $VERSION = '0.058';
16              
17             sub format_datetime {
18 618     618 1 1064 my ( $self, $tplt, $time, $gmt ) = @_;
19 618         1209 $time = $self->__round_time_value( $time );
20 618 100       1549 defined $gmt or $gmt = $self->gmt();
21 618 100       1185 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       1056 and local $ENV{TZ} = 'GMT';
29 330         396 return POSIX::strftime( $tplt, @{ $time } );
  330         1746  
30             } elsif ( $gmt ) {
31 288         982 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   518 my ( undef, $obj, $name, $val ) = @_; # Invocant unused
53 390 100       533 $obj or $obj = [ 0, 0, 0, 1, 0, 200 ];
54 390         713 $adjuster{$name}->( $obj, $val );
55 390         564 return $obj;
56             }
57              
58             }
59              
60             1;
61              
62             __END__