line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::end_year; |
2
|
2
|
|
|
2
|
|
749
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
107359
|
|
|
2
|
|
|
|
|
9
|
|
3
|
2
|
|
|
2
|
|
321
|
use Moo; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
4
|
2
|
|
|
2
|
|
381
|
use Catmandu::Util qw(:is :check :array); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
719
|
|
5
|
2
|
|
|
2
|
|
486
|
use DateTime::Format::Strptime; |
|
2
|
|
|
|
|
76506
|
|
|
2
|
|
|
|
|
10
|
|
6
|
2
|
|
|
2
|
|
129
|
use DateTime::TimeZone; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
28
|
|
7
|
2
|
|
|
2
|
|
6
|
use DateTime; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
768
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.0130"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Fix::Base'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has path => ( |
14
|
|
|
|
|
|
|
is => 'ro' , |
15
|
|
|
|
|
|
|
required => 1 |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
has add => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => sub { check_integer($_[0]); }, |
20
|
|
|
|
|
|
|
required => 0, |
21
|
|
|
|
|
|
|
lazy => 1, |
22
|
|
|
|
|
|
|
default => sub { 0; } |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
has time_zone => ( |
25
|
|
|
|
|
|
|
is => 'ro', |
26
|
|
|
|
|
|
|
required => 1, |
27
|
|
|
|
|
|
|
isa => sub { |
28
|
|
|
|
|
|
|
check_string($_[0]); |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
default => sub { |
31
|
|
|
|
|
|
|
"UTC" |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
has pattern => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
required => 1, |
37
|
|
|
|
|
|
|
isa => sub { |
38
|
|
|
|
|
|
|
check_string($_[0]); |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
default => sub { |
41
|
|
|
|
|
|
|
"%FT%T.%NZ" |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
around BUILDARGS => sub { |
46
|
|
|
|
|
|
|
my($orig,$class,$path,%args) = @_; |
47
|
|
|
|
|
|
|
$orig->($class, |
48
|
|
|
|
|
|
|
path => $path, |
49
|
|
|
|
|
|
|
%args |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub emit { |
54
|
2
|
|
|
2
|
0
|
4614
|
my($self,$fixer) = @_; |
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
7
|
my $path = $fixer->split_path($self->path()); |
57
|
|
|
|
|
|
|
my $end_year = $fixer->capture(sub{ |
58
|
2
|
|
|
2
|
|
5234
|
my $skip = shift; |
59
|
|
|
|
|
|
|
#we need to set the time zone first before doing any math! |
60
|
2
|
|
|
|
|
8
|
my $d = DateTime->now->set_time_zone($self->time_zone)->truncate(to => "day"); |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
561
|
$d->set_month(1); |
63
|
2
|
|
|
|
|
397
|
$d->set_day(1); |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
353
|
$d->add(seconds => -1,years => 1); |
66
|
|
|
|
|
|
|
|
67
|
2
|
50
|
|
|
|
685
|
if(is_integer($skip)){ |
68
|
2
|
|
|
|
|
18
|
$d->add(years => $skip); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
398
|
$d; |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
32
|
}); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$fixer->emit_create_path($fixer->var,$path,sub{ |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
2
|
|
113
|
my $var = shift; |
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
4
|
my $d = $fixer->generate_var(); |
80
|
2
|
|
|
|
|
62
|
my $p = $fixer->emit_declare_vars($d); |
81
|
2
|
|
|
|
|
26
|
$p .= " $d = ${end_year}->(".$self->add().");"; |
82
|
2
|
|
|
|
|
301
|
$p .= " ${var} = DateTime::Format::Strptime::strftime('".$self->pattern()."',$d);"; |
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
|
|
5
|
$p; |
85
|
|
|
|
|
|
|
|
86
|
2
|
|
|
|
|
119
|
}); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
__END__ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 NAME |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Catmandu::Fix::end_year - Catmandu Fix for retrieving date string for end of the current year |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SYNOPSIS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#get end of the year in time zone Europe/Brussels |
100
|
|
|
|
|
|
|
end_year('end_year','pattern' => '%Y-%m-%dT%H:%M:SZ','time_zone' => 'Europe/Brussels') |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#get end of next year in time zone Europe/Brussels |
103
|
|
|
|
|
|
|
end_year('end_year','pattern' => '%Y-%m-%dT%H:%M:SZ','time_zone' => 'Europe/Brussels', 'add' => 1) |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Nicolas Franck, C<< <nicolas.franck at ugent.be> >> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SEE ALSO |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L<Catmandu::Fix> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |