| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Astro::App::Satpass2::FormatTime; |
|
2
|
|
|
|
|
|
|
|
|
3
|
20
|
|
|
20
|
|
1702
|
use 5.008; |
|
|
20
|
|
|
|
|
92
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
20
|
|
|
20
|
|
113
|
use strict; |
|
|
20
|
|
|
|
|
47
|
|
|
|
20
|
|
|
|
|
509
|
|
|
6
|
20
|
|
|
20
|
|
100
|
use warnings; |
|
|
20
|
|
|
|
|
45
|
|
|
|
20
|
|
|
|
|
530
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
20
|
|
|
20
|
|
613
|
use POSIX (); |
|
|
20
|
|
|
|
|
6339
|
|
|
|
20
|
|
|
|
|
541
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
20
|
|
|
20
|
|
124
|
use parent qw{ Astro::App::Satpass2::Copier }; |
|
|
20
|
|
|
|
|
52
|
|
|
|
20
|
|
|
|
|
105
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
20
|
|
|
20
|
|
1386
|
use Astro::App::Satpass2::Utils qw{ @CARP_NOT }; |
|
|
20
|
|
|
|
|
53
|
|
|
|
20
|
|
|
|
|
2095
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.051_01'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
20
|
|
|
20
|
|
181
|
use constant ROUND_TIME => 1; |
|
|
20
|
|
|
|
|
88
|
|
|
|
20
|
|
|
|
|
19873
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $delegate = eval { |
|
19
|
|
|
|
|
|
|
require Astro::App::Satpass2::FormatTime::DateTime::Strftime; |
|
20
|
|
|
|
|
|
|
require DateTime::TimeZone; |
|
21
|
|
|
|
|
|
|
DateTime::TimeZone->new( name => 'local' ); |
|
22
|
|
|
|
|
|
|
'Astro::App::Satpass2::FormatTime::DateTime::Strftime'; |
|
23
|
|
|
|
|
|
|
} || do { |
|
24
|
|
|
|
|
|
|
require Astro::App::Satpass2::FormatTime::POSIX::Strftime; |
|
25
|
|
|
|
|
|
|
'Astro::App::Satpass2::FormatTime::POSIX::Strftime'; |
|
26
|
|
|
|
|
|
|
}; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
|
29
|
34
|
|
|
34
|
1
|
12519
|
my ( $class, %args ) = @_; |
|
30
|
34
|
50
|
|
|
|
113
|
ref $class and $class = ref $class; |
|
31
|
|
|
|
|
|
|
|
|
32
|
34
|
100
|
|
|
|
120
|
__PACKAGE__ eq $class and $class = $delegate; |
|
33
|
|
|
|
|
|
|
|
|
34
|
34
|
|
|
|
|
120
|
my $self = { |
|
35
|
|
|
|
|
|
|
round_time => ROUND_TIME, |
|
36
|
|
|
|
|
|
|
}; |
|
37
|
34
|
|
|
|
|
123
|
bless $self, $class; |
|
38
|
34
|
|
|
|
|
244
|
$self->init( %args ); |
|
39
|
34
|
|
|
|
|
131
|
return $self; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub attribute_names { |
|
43
|
54
|
|
|
54
|
1
|
199
|
return ( qw{ gmt tz } ); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
{ |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my %skip = map { $_ => 1 } qw{ back_end }; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub copy { |
|
51
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $copy ) = @_; |
|
52
|
0
|
|
|
|
|
0
|
return $self->SUPER::copy( $copy, %skip ); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
{ |
|
57
|
|
|
|
|
|
|
my $leader_re = qr{ @{[ __PACKAGE__ ]} :: }smxo; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub class_name_of_record { |
|
60
|
2
|
|
|
2
|
1
|
5
|
my ( $self ) = @_; |
|
61
|
2
|
|
33
|
|
|
33
|
( my $name = ref $self || $self ) =~ s/ \A $leader_re //smx; |
|
62
|
2
|
|
|
|
|
8
|
return $name; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub format_datetime { ## no critic (RequireFinalReturn) |
|
67
|
0
|
|
|
0
|
1
|
0
|
my ( $self ) = @_; |
|
68
|
|
|
|
|
|
|
# ->weep() throws an exception. |
|
69
|
0
|
|
|
|
|
0
|
$self->weep( |
|
70
|
|
|
|
|
|
|
'Method format_datetime() must be overridden' ); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
{ |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my %cache; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub format_datetime_width { |
|
78
|
356
|
|
|
356
|
1
|
891
|
my ( $self, $tplt, $gmt ) = @_; |
|
79
|
|
|
|
|
|
|
|
|
80
|
356
|
50
|
|
|
|
1369
|
defined $gmt |
|
81
|
|
|
|
|
|
|
or $gmt = $self->gmt(); |
|
82
|
356
|
50
|
|
|
|
872
|
$gmt = $gmt ? 1 : 0; |
|
83
|
|
|
|
|
|
|
|
|
84
|
356
|
|
|
|
|
766
|
my $class = ref $self; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
exists $cache{$class}{$tplt}[$gmt] |
|
87
|
356
|
100
|
|
|
|
1703
|
and return $cache{$class}{$tplt}[$gmt]; |
|
88
|
|
|
|
|
|
|
|
|
89
|
15
|
|
|
|
|
79
|
my ( $time, $wid ) = $self->_format_datetime_width_try( $tplt, undef, |
|
90
|
|
|
|
|
|
|
$gmt, year => 2100 ); |
|
91
|
15
|
|
|
|
|
72
|
( $time, $wid ) = $self->_format_datetime_width_try( $tplt, $time, |
|
92
|
|
|
|
|
|
|
$gmt, month => 1 .. 12 ); |
|
93
|
15
|
|
|
|
|
106
|
( $time, $wid ) = $self->_format_datetime_width_try( $tplt, $time, |
|
94
|
|
|
|
|
|
|
$gmt, day => 1 .. 7 ); |
|
95
|
15
|
|
|
|
|
106
|
( $time, $wid ) = $self->_format_datetime_width_try( $tplt, $time, |
|
96
|
|
|
|
|
|
|
$gmt, hour => 6, 18 ); |
|
97
|
|
|
|
|
|
|
|
|
98
|
15
|
|
|
|
|
133
|
return ( $cache{$class}{$tplt}[$gmt] = $wid ); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _format_datetime_width_try { |
|
104
|
60
|
|
|
60
|
|
229
|
my ( $self, $tplt, $time, $gmt, $name, @try ) = @_; |
|
105
|
60
|
|
|
|
|
92
|
my $wid; |
|
106
|
|
|
|
|
|
|
my $max_trial; |
|
107
|
60
|
|
|
|
|
133
|
foreach my $trial ( @try ) { |
|
108
|
330
|
|
|
|
|
1009
|
$time = $self->__format_datetime_width_adjust_object( |
|
109
|
|
|
|
|
|
|
$time, $name, $trial, $gmt ); |
|
110
|
330
|
|
|
|
|
828
|
my $size = length $self->format_datetime( $tplt, $time ); |
|
111
|
330
|
100
|
66
|
|
|
1656
|
defined $wid and $size <= $wid and next; |
|
112
|
60
|
|
|
|
|
107
|
$wid = $size; |
|
113
|
60
|
|
|
|
|
118
|
$max_trial = $trial; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
60
|
|
|
|
|
210
|
$time = $self->__format_datetime_width_adjust_object( $time, $name, |
|
116
|
|
|
|
|
|
|
$max_trial, $gmt ); |
|
117
|
60
|
|
|
|
|
216
|
return ( $time, $wid ); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
{ |
|
121
|
|
|
|
|
|
|
my %valid = ( |
|
122
|
|
|
|
|
|
|
hour => 3600, |
|
123
|
|
|
|
|
|
|
minute => 60, |
|
124
|
|
|
|
|
|
|
second => 1, |
|
125
|
|
|
|
|
|
|
none => undef, |
|
126
|
|
|
|
|
|
|
); |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub round_time { |
|
129
|
1037
|
|
|
1037
|
1
|
2143
|
my ( $self, @arg ) = @_; |
|
130
|
1037
|
100
|
|
|
|
2029
|
if ( @arg ) { |
|
131
|
298
|
|
|
|
|
570
|
my $val = $arg[0]; |
|
132
|
298
|
50
|
33
|
|
|
1723
|
if ( defined $val && $val =~ m/ [^0-9] /smx ) { |
|
133
|
0
|
0
|
|
|
|
0
|
exists $valid{$val} |
|
134
|
|
|
|
|
|
|
or $self->wail( "Invalid rounding spec '$val'" ); |
|
135
|
0
|
|
|
|
|
0
|
$val = $valid{$val} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
298
|
|
|
|
|
681
|
$self->{round_time} = $val; |
|
138
|
298
|
|
|
|
|
757
|
return $self; |
|
139
|
|
|
|
|
|
|
} else { |
|
140
|
739
|
|
|
|
|
2590
|
return $self->{round_time}; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub __round_time_value { |
|
146
|
618
|
|
|
618
|
|
1077
|
my ( $self, $time ) = @_; |
|
147
|
618
|
100
|
|
|
|
1500
|
ref $time |
|
148
|
|
|
|
|
|
|
and return $time; |
|
149
|
288
|
50
|
|
|
|
571
|
if ( my $round = $self->round_time() ) { |
|
150
|
288
|
|
|
|
|
1380
|
$time = POSIX::floor( ( $time + $round / 2 ) / $round ) * $round; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
288
|
|
|
|
|
847
|
return $time; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__PACKAGE__->create_attribute_methods(); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__END__ |