line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Astro::App::Satpass2::FormatTime; |
2
|
|
|
|
|
|
|
|
3
|
20
|
|
|
20
|
|
1627
|
use 5.008; |
|
20
|
|
|
|
|
73
|
|
4
|
|
|
|
|
|
|
|
5
|
20
|
|
|
20
|
|
112
|
use strict; |
|
20
|
|
|
|
|
57
|
|
|
20
|
|
|
|
|
553
|
|
6
|
20
|
|
|
20
|
|
109
|
use warnings; |
|
20
|
|
|
|
|
45
|
|
|
20
|
|
|
|
|
629
|
|
7
|
|
|
|
|
|
|
|
8
|
20
|
|
|
20
|
|
631
|
use POSIX (); |
|
20
|
|
|
|
|
6357
|
|
|
20
|
|
|
|
|
520
|
|
9
|
|
|
|
|
|
|
|
10
|
20
|
|
|
20
|
|
128
|
use parent qw{ Astro::App::Satpass2::Copier }; |
|
20
|
|
|
|
|
50
|
|
|
20
|
|
|
|
|
122
|
|
11
|
|
|
|
|
|
|
|
12
|
20
|
|
|
20
|
|
1468
|
use Astro::App::Satpass2::Utils qw{ @CARP_NOT }; |
|
20
|
|
|
|
|
43
|
|
|
20
|
|
|
|
|
2245
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.051'; |
15
|
|
|
|
|
|
|
|
16
|
20
|
|
|
20
|
|
183
|
use constant ROUND_TIME => 1; |
|
20
|
|
|
|
|
76
|
|
|
20
|
|
|
|
|
20777
|
|
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
|
12739
|
my ( $class, %args ) = @_; |
30
|
34
|
50
|
|
|
|
119
|
ref $class and $class = ref $class; |
31
|
|
|
|
|
|
|
|
32
|
34
|
100
|
|
|
|
134
|
__PACKAGE__ eq $class and $class = $delegate; |
33
|
|
|
|
|
|
|
|
34
|
34
|
|
|
|
|
129
|
my $self = { |
35
|
|
|
|
|
|
|
round_time => ROUND_TIME, |
36
|
|
|
|
|
|
|
}; |
37
|
34
|
|
|
|
|
131
|
bless $self, $class; |
38
|
34
|
|
|
|
|
243
|
$self->init( %args ); |
39
|
34
|
|
|
|
|
117
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub attribute_names { |
43
|
54
|
|
|
54
|
1
|
205
|
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
|
6
|
my ( $self ) = @_; |
61
|
2
|
|
33
|
|
|
38
|
( my $name = ref $self || $self ) =~ s/ \A $leader_re //smx; |
62
|
2
|
|
|
|
|
22
|
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
|
1022
|
my ( $self, $tplt, $gmt ) = @_; |
79
|
|
|
|
|
|
|
|
80
|
356
|
50
|
|
|
|
1564
|
defined $gmt |
81
|
|
|
|
|
|
|
or $gmt = $self->gmt(); |
82
|
356
|
50
|
|
|
|
861
|
$gmt = $gmt ? 1 : 0; |
83
|
|
|
|
|
|
|
|
84
|
356
|
|
|
|
|
780
|
my $class = ref $self; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
exists $cache{$class}{$tplt}[$gmt] |
87
|
356
|
100
|
|
|
|
1671
|
and return $cache{$class}{$tplt}[$gmt]; |
88
|
|
|
|
|
|
|
|
89
|
15
|
|
|
|
|
78
|
my ( $time, $wid ) = $self->_format_datetime_width_try( $tplt, undef, |
90
|
|
|
|
|
|
|
$gmt, year => 2100 ); |
91
|
15
|
|
|
|
|
77
|
( $time, $wid ) = $self->_format_datetime_width_try( $tplt, $time, |
92
|
|
|
|
|
|
|
$gmt, month => 1 .. 12 ); |
93
|
15
|
|
|
|
|
91
|
( $time, $wid ) = $self->_format_datetime_width_try( $tplt, $time, |
94
|
|
|
|
|
|
|
$gmt, day => 1 .. 7 ); |
95
|
15
|
|
|
|
|
79
|
( $time, $wid ) = $self->_format_datetime_width_try( $tplt, $time, |
96
|
|
|
|
|
|
|
$gmt, hour => 6, 18 ); |
97
|
|
|
|
|
|
|
|
98
|
15
|
|
|
|
|
111
|
return ( $cache{$class}{$tplt}[$gmt] = $wid ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _format_datetime_width_try { |
104
|
60
|
|
|
60
|
|
191
|
my ( $self, $tplt, $time, $gmt, $name, @try ) = @_; |
105
|
60
|
|
|
|
|
122
|
my $wid; |
106
|
|
|
|
|
|
|
my $max_trial; |
107
|
60
|
|
|
|
|
134
|
foreach my $trial ( @try ) { |
108
|
330
|
|
|
|
|
1031
|
$time = $self->__format_datetime_width_adjust_object( |
109
|
|
|
|
|
|
|
$time, $name, $trial, $gmt ); |
110
|
330
|
|
|
|
|
862
|
my $size = length $self->format_datetime( $tplt, $time ); |
111
|
330
|
100
|
66
|
|
|
1821
|
defined $wid and $size <= $wid and next; |
112
|
60
|
|
|
|
|
104
|
$wid = $size; |
113
|
60
|
|
|
|
|
118
|
$max_trial = $trial; |
114
|
|
|
|
|
|
|
} |
115
|
60
|
|
|
|
|
203
|
$time = $self->__format_datetime_width_adjust_object( $time, $name, |
116
|
|
|
|
|
|
|
$max_trial, $gmt ); |
117
|
60
|
|
|
|
|
239
|
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
|
2222
|
my ( $self, @arg ) = @_; |
130
|
1037
|
100
|
|
|
|
2124
|
if ( @arg ) { |
131
|
298
|
|
|
|
|
625
|
my $val = $arg[0]; |
132
|
298
|
50
|
33
|
|
|
1774
|
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
|
|
|
|
|
666
|
$self->{round_time} = $val; |
138
|
298
|
|
|
|
|
798
|
return $self; |
139
|
|
|
|
|
|
|
} else { |
140
|
739
|
|
|
|
|
2775
|
return $self->{round_time}; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub __round_time_value { |
146
|
618
|
|
|
618
|
|
1096
|
my ( $self, $time ) = @_; |
147
|
618
|
100
|
|
|
|
1645
|
ref $time |
148
|
|
|
|
|
|
|
and return $time; |
149
|
288
|
50
|
|
|
|
606
|
if ( my $round = $self->round_time() ) { |
150
|
288
|
|
|
|
|
1549
|
$time = POSIX::floor( ( $time + $round / 2 ) / $round ) * $round; |
151
|
|
|
|
|
|
|
} |
152
|
288
|
|
|
|
|
796
|
return $time; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__PACKAGE__->create_attribute_methods(); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__END__ |