line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::date; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
378
|
use 5.010; |
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
331
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
1
|
|
|
|
|
19626
|
|
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
2849
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
#use Log::Any '$log'; |
8
|
1
|
|
|
1
|
|
5
|
use POSIX qw(strftime); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
9
|
1
|
|
|
1
|
|
440
|
use Scalar::Util qw(looks_like_number blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
373
|
use Data::Unixish::Util qw(%common_args); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
324
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.570'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %SPEC; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$SPEC{date} = { |
18
|
|
|
|
|
|
|
v => 1.1, |
19
|
|
|
|
|
|
|
summary => 'Format date', |
20
|
|
|
|
|
|
|
description => <<'_', |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
_ |
23
|
|
|
|
|
|
|
args => { |
24
|
|
|
|
|
|
|
%common_args, |
25
|
|
|
|
|
|
|
format => { |
26
|
|
|
|
|
|
|
summary => 'Format', |
27
|
|
|
|
|
|
|
schema => 'str*', |
28
|
|
|
|
|
|
|
cmdline_aliases => { f=>{} }, |
29
|
|
|
|
|
|
|
pos => 0, |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
# tz? |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
tags => [qw/datatype:date itemfunc formatting/], |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
sub date { |
36
|
1
|
|
|
1
|
1
|
4
|
my %args = @_; |
37
|
1
|
|
|
|
|
2
|
my ($in, $out) = ($args{in}, $args{out}); |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
2
|
_date_begin(\%args); |
40
|
1
|
|
|
|
|
4
|
while (my ($index, $item) = each @$in) { |
41
|
2
|
|
|
|
|
5
|
push @$out, _date_item($item, \%args); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
4
|
[200, "OK"]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _date_begin { |
48
|
2
|
|
|
2
|
|
3
|
my $args = shift; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
50
|
|
|
6
|
$args->{format} //= '%Y-%m-%d %H:%M:%S'; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _date_item { |
54
|
4
|
|
|
4
|
|
8
|
my ($item, $args) = @_; |
55
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
4
|
my @lt; |
57
|
4
|
50
|
33
|
|
|
37
|
if (looks_like_number($item) && |
|
|
0
|
33
|
|
|
|
|
|
|
|
0
|
|
|
|
|
58
|
|
|
|
|
|
|
$item >= 0 && $item <= 2**31) { # XXX Y2038-bug |
59
|
4
|
|
|
|
|
70
|
@lt = localtime($item); |
60
|
|
|
|
|
|
|
} elsif (blessed($item) && $item->isa('DateTime')) { |
61
|
|
|
|
|
|
|
# XXX timezone! |
62
|
0
|
|
|
|
|
0
|
@lt = localtime($item->epoch); |
63
|
|
|
|
|
|
|
} else { |
64
|
0
|
|
|
|
|
0
|
goto OUT_ITEM; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
82
|
$item = strftime $args->{format}, @lt; |
68
|
|
|
|
|
|
|
|
69
|
4
|
|
|
|
|
20
|
OUT_ITEM: |
70
|
|
|
|
|
|
|
return $item; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
# ABSTRACT: Format date |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |