| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package LBMA::Statistics::Date; |
|
2
|
12
|
|
|
12
|
|
131053
|
use strict; |
|
|
12
|
|
|
|
|
30
|
|
|
|
12
|
|
|
|
|
416
|
|
|
3
|
12
|
|
|
12
|
|
64
|
use warnings; |
|
|
12
|
|
|
|
|
26
|
|
|
|
12
|
|
|
|
|
551
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.061'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
12
|
|
|
12
|
|
18580
|
use DateTime; |
|
|
12
|
|
|
|
|
2679968
|
|
|
|
12
|
|
|
|
|
582
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
12
|
|
|
12
|
|
24357
|
use Log::Log4perl qw/:easy/; |
|
|
12
|
|
|
|
|
810778
|
|
|
|
12
|
|
|
|
|
95
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
LBMA::Statistics::Date - Common date methods for LBMA::Statistics (Internal only) |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTON |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
LBMA::Statistics::Date handles common date methods for LBMA::Statistics. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This module is for internal use only. There's no need to access it directly. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
See L |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 new - Constructor |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head3 Parameters |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Parameters are all lowercase. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over 4 |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item * year - four digit year (1968 .. ) |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item * month - one or two digit month (1 .. 12) |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item * day - one or two digit day (1 .. 31) |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=back |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use strict; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use warnings; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use LBMA::Statistics::Date; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $date = LBMA::Statistics::Date->new( year => $year, |
|
50
|
|
|
|
|
|
|
month => $month, |
|
51
|
|
|
|
|
|
|
day => $day, |
|
52
|
|
|
|
|
|
|
) or die $!; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
If no parameters are passed to this class, today is assumed. |
|
55
|
|
|
|
|
|
|
Today is determined using UTC. In doubt pass a valid date. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $date = LBMA::Statistics::Date->new( ); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Dies if supplied date isn't valid or year is before 1968. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
|
65
|
13
|
|
|
13
|
1
|
552
|
my $class = shift; |
|
66
|
13
|
|
|
|
|
26
|
my $self = {}; |
|
67
|
13
|
|
|
|
|
39
|
bless $self, $class; |
|
68
|
13
|
|
|
|
|
44
|
$self->_init(@_); |
|
69
|
9
|
|
|
|
|
164
|
return $self; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 year - returns the year |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
print $date->year(), "\n"; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub year { |
|
79
|
3
|
|
|
3
|
1
|
24
|
my $self = shift; |
|
80
|
3
|
|
|
|
|
18
|
return $self->{year}; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 day_pattern - returns a date/day-pattern YY-MMM-DD |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
print $date->day_pattern(), "\n"; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub day_pattern { |
|
90
|
4
|
|
|
4
|
1
|
32
|
my $self = shift; |
|
91
|
4
|
|
|
|
|
45
|
return $self->{day_pattern}; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 INTERNAL METHODS |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 _init |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
formats date strings from supplied year, month, day |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _init { |
|
104
|
13
|
|
|
13
|
|
19
|
my $self = shift; |
|
105
|
13
|
|
|
|
|
19
|
my ( $year, $month, $day ); |
|
106
|
0
|
|
|
|
|
0
|
my $dt; |
|
107
|
13
|
100
|
|
|
|
41
|
if (@_) { |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Use supplied date |
|
110
|
9
|
|
|
|
|
34
|
my %args = @_; |
|
111
|
9
|
|
|
|
|
16
|
$year = $args{year}; |
|
112
|
9
|
|
|
|
|
13
|
$month = $args{month}; |
|
113
|
9
|
|
|
|
|
15
|
$day = $args{day}; |
|
114
|
9
|
50
|
|
|
|
49
|
$dt = DateTime->new( |
|
115
|
|
|
|
|
|
|
year => $year, |
|
116
|
|
|
|
|
|
|
day => $day, |
|
117
|
|
|
|
|
|
|
month => $month, |
|
118
|
|
|
|
|
|
|
locale => 'en_GB', # It's a british site |
|
119
|
|
|
|
|
|
|
) or LOGDIE $!; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
else { |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Use current date |
|
125
|
4
|
50
|
|
|
|
34
|
$dt = DateTime->now( locale => 'en_GB' ) |
|
126
|
|
|
|
|
|
|
or LOGDIE $!; # It's a british site |
|
127
|
4
|
|
|
|
|
8837
|
$year = $dt->year(); |
|
128
|
4
|
|
|
|
|
40
|
$month = $dt->month(); |
|
129
|
4
|
|
|
|
|
37
|
$day = $dt->day(); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Sanity check for the wild ones |
|
133
|
12
|
100
|
|
|
|
8019
|
if ( $year < 1968 ) { |
|
134
|
2
|
|
|
|
|
14
|
LOGDIE |
|
135
|
|
|
|
|
|
|
"Year is $year - Historic daily prices and monthly and annual averages are available back to 1968."; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
10
|
50
|
|
|
|
42
|
my $today = DateTime->now( locale => 'en_GB' ) or LOGDIE $!; |
|
138
|
10
|
|
|
|
|
3483
|
my $current_year = $today->year(); |
|
139
|
10
|
100
|
|
|
|
71
|
if ( $year > $current_year ) { |
|
140
|
1
|
|
|
|
|
5
|
LOGDIE "Year is $year - This ain't a crystal ball!"; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Format the date to match (DD-MMM-YY) |
|
144
|
|
|
|
|
|
|
# %b The abbreviated month name ( locale => 'en_GB' ) |
|
145
|
|
|
|
|
|
|
# %d The day of the month as a decimal number (range 01 to 31) |
|
146
|
|
|
|
|
|
|
# %y The year as a decimal number without a century (range 00 to 99). |
|
147
|
9
|
|
|
|
|
50
|
my $day_pattern = $dt->strftime('%d-%b-%y'); |
|
148
|
|
|
|
|
|
|
|
|
149
|
9
|
|
|
|
|
690
|
$self->{day_pattern} = $day_pattern; |
|
150
|
9
|
|
|
|
|
20
|
$self->{year} = $year; |
|
151
|
9
|
|
|
|
|
17
|
$self->{month} = $month; |
|
152
|
9
|
|
|
|
|
18
|
$self->{day} = $day; |
|
153
|
9
|
|
|
|
|
52
|
DEBUG("day_pattern: $day_pattern"); |
|
154
|
9
|
|
|
|
|
135
|
DEBUG("year: $year"); |
|
155
|
9
|
|
|
|
|
93
|
DEBUG("month: $month"); |
|
156
|
9
|
|
|
|
|
74
|
DEBUG("day: $day"); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# return true; |
|
160
|
|
|
|
|
|
|
1; |
|
161
|
|
|
|
|
|
|
__END__ |