| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Time::dt; |
|
2
|
|
|
|
|
|
|
$VERSION = v0.0.1; |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# Copyright (C) 2013 Eric L. Wilhelm |
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
23092
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
66
|
|
|
7
|
2
|
|
|
2
|
|
12
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
68
|
|
|
8
|
2
|
|
|
2
|
|
21
|
use Carp; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
209
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Time::dt - date and time succinctly |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Time::dt; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
say "iso timestamp: ", dt; |
|
19
|
|
|
|
|
|
|
say "stringification shmingification: ", dt->dt; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Time::dt::strptime($timestamp, "%Y-%m-%d %H:%M:%S"); # epoch |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
11
|
BEGIN {require Exporter; *import = \&Exporter::import}; |
|
|
2
|
|
|
|
|
156
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT = qw(dt); |
|
27
|
|
|
|
|
|
|
our @EXPORT_OK = qw(read_dt strptime); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
{ |
|
30
|
|
|
|
|
|
|
package Time::Piece::Tidy; |
|
31
|
2
|
|
|
2
|
|
10
|
use base 'Time::Piece'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
1910
|
|
|
32
|
2
|
|
|
2
|
|
31325
|
use overload '""' => \&dt; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
16
|
|
|
33
|
|
|
|
|
|
|
sub dt { |
|
34
|
1
|
|
|
1
|
|
149
|
my $self = shift; |
|
35
|
1
|
|
|
|
|
2
|
my $fmt = '%Y-%m-%d %H:%M:%S'; |
|
36
|
1
|
50
|
|
|
|
5
|
$fmt .= ' %Z' if ($self->[10]); # XXX this is bad or wrong |
|
37
|
1
|
|
|
|
|
7
|
$self->strftime($fmt); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
*cdate = \&dt; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 zdt |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
String format with timezone. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
print $dt->zdt('US/Eastern'); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub zdt { |
|
50
|
1
|
|
|
1
|
|
133
|
my ($self, $tz) = @_; |
|
51
|
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
7
|
my $e = $self->epoch; |
|
53
|
1
|
|
|
|
|
122
|
local $ENV{TZ} = $tz; |
|
54
|
1
|
|
|
|
|
5
|
ref($self)->new($e)->dt; |
|
55
|
|
|
|
|
|
|
} # zdt ################################################################ |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} # end package |
|
58
|
|
|
|
|
|
|
######################################################################## |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 Functions |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 dt |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $dt = dt(time); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub dt { |
|
69
|
2
|
|
|
2
|
1
|
30
|
my $t = shift; |
|
70
|
2
|
|
|
|
|
25
|
Time::Piece::Tidy->new($t); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 read_dt |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $dt = read_dt( |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub read_dt { |
|
80
|
1
|
|
|
1
|
1
|
396
|
my $ts = shift; |
|
81
|
1
|
|
|
|
|
5
|
dt(strptime($ts)); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 strptime |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Returns the epoch seconds for a given parsed time. |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $t = strptime($string, $format); |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
{ |
|
93
|
|
|
|
|
|
|
my %zones = ( |
|
94
|
|
|
|
|
|
|
PST => '-0800', |
|
95
|
|
|
|
|
|
|
PDT => '-0700', |
|
96
|
|
|
|
|
|
|
MST => '-0700', |
|
97
|
|
|
|
|
|
|
MDT => '-0600', |
|
98
|
|
|
|
|
|
|
CST => '-0600', |
|
99
|
|
|
|
|
|
|
CDT => '-0500', |
|
100
|
|
|
|
|
|
|
EST => '-0500', |
|
101
|
|
|
|
|
|
|
EDT => '-0400', |
|
102
|
|
|
|
|
|
|
AST => '-0400', |
|
103
|
|
|
|
|
|
|
ALST => '-0900', |
|
104
|
|
|
|
|
|
|
ALDT => '-0800', |
|
105
|
|
|
|
|
|
|
HST => '-1000', |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
my $zk = join('|', keys %zones); |
|
108
|
|
|
|
|
|
|
sub strptime { |
|
109
|
2
|
|
|
2
|
1
|
580
|
my ($string, $format) = @_; |
|
110
|
2
|
|
50
|
|
|
13
|
$format ||= '%Y-%m-%d %H:%M:%S %Z'; |
|
111
|
|
|
|
|
|
|
|
|
112
|
2
|
|
|
|
|
3
|
my $is_local; |
|
113
|
2
|
50
|
|
|
|
15
|
if($format =~ s/%Z$/%z/) { |
|
|
|
0
|
|
|
|
|
|
|
114
|
2
|
|
|
|
|
76
|
$string =~ s/ ($zk)$/ $zones{$1}/; # hack to parse named zones |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
elsif($format =~ m/%z$/) { |
|
117
|
0
|
|
|
|
|
0
|
$string =~ s/:(\d\d)$/$1/; # fix broken tz |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
else { |
|
120
|
0
|
|
|
|
|
0
|
$is_local = 1; # no zone means localtime |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
5
|
my @vals = eval {Time::Piece::_strptime($string, $format)}; |
|
|
2
|
|
|
|
|
17
|
|
|
124
|
2
|
50
|
|
|
|
9
|
die "$@ $string - $format" if $@; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
2
|
50
|
|
|
|
15
|
return $is_local |
|
128
|
|
|
|
|
|
|
? Time::Local::timelocal(@vals[0..9]) |
|
129
|
|
|
|
|
|
|
: Time::Local::timegm(@vals[0..9]); |
|
130
|
|
|
|
|
|
|
}} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Eric Wilhelm @ |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
http://scratchcomputing.com/ |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 BUGS |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
If you found this module on CPAN, please report any bugs or feature |
|
141
|
|
|
|
|
|
|
requests through the web interface at L. I will be |
|
142
|
|
|
|
|
|
|
notified, and then you'll automatically be notified of progress on your |
|
143
|
|
|
|
|
|
|
bug as I make changes. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
If you pulled this development version from my /svn/, please contact me |
|
146
|
|
|
|
|
|
|
directly. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Copyright (C) 2013 Eric L. Wilhelm, All Rights Reserved. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 NO WARRANTY |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Absolutely, positively NO WARRANTY, neither express or implied, is |
|
155
|
|
|
|
|
|
|
offered with this software. You use this software at your own risk. In |
|
156
|
|
|
|
|
|
|
case of loss, no person or entity owes you anything whatsoever. You |
|
157
|
|
|
|
|
|
|
have been warned. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 LICENSE |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
162
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# vi:ts=2:sw=2:et:sta |
|
167
|
|
|
|
|
|
|
1; |