line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ============================================================================ |
2
|
|
|
|
|
|
|
package DateTime::Format::CLDR; |
3
|
|
|
|
|
|
|
# ============================================================================ |
4
|
17
|
|
|
17
|
|
4043543
|
use strict; |
|
17
|
|
|
|
|
47
|
|
|
17
|
|
|
|
|
506
|
|
5
|
17
|
|
|
17
|
|
104
|
use warnings; |
|
17
|
|
|
|
|
44
|
|
|
17
|
|
|
|
|
508
|
|
6
|
17
|
|
|
17
|
|
5239
|
use utf8; |
|
17
|
|
|
|
|
152
|
|
|
17
|
|
|
|
|
121
|
|
7
|
|
|
|
|
|
|
|
8
|
17
|
|
|
17
|
|
7797
|
use DateTime; |
|
17
|
|
|
|
|
4444932
|
|
|
17
|
|
|
|
|
709
|
|
9
|
17
|
|
|
17
|
|
136
|
use DateTime::Locale 0.4000; |
|
17
|
|
|
|
|
389
|
|
|
17
|
|
|
|
|
383
|
|
10
|
17
|
|
|
17
|
|
105
|
use DateTime::TimeZone; |
|
17
|
|
|
|
|
40
|
|
|
17
|
|
|
|
|
470
|
|
11
|
17
|
|
|
17
|
|
9143
|
use Params::Validate qw( validate_pos validate SCALAR BOOLEAN OBJECT CODEREF ); |
|
17
|
|
|
|
|
42523
|
|
|
17
|
|
|
|
|
1213
|
|
12
|
17
|
|
|
17
|
|
129
|
use Exporter; |
|
17
|
|
|
|
|
114
|
|
|
17
|
|
|
|
|
550
|
|
13
|
17
|
|
|
17
|
|
121
|
use Carp qw(croak carp); |
|
17
|
|
|
|
|
43
|
|
|
17
|
|
|
|
|
761
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Export functions |
16
|
17
|
|
|
17
|
|
165
|
use base qw(Exporter); |
|
17
|
|
|
|
|
41
|
|
|
17
|
|
|
|
|
68206
|
|
17
|
|
|
|
|
|
|
our @EXPORT_OK = qw( cldr_format cldr_parse ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# CPAN data |
20
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:MAROS'; |
21
|
|
|
|
|
|
|
our $VERSION = '1.19'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Default format if none is set |
24
|
|
|
|
|
|
|
our $DEFAULT_FORMAT = 'date_format_medium'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Simple regexp blocks |
27
|
|
|
|
|
|
|
our %PARTS = ( |
28
|
|
|
|
|
|
|
year_long => qr/(-?\d{1,4})/o, |
29
|
|
|
|
|
|
|
year_short => qr/(-?\d{2})/o, |
30
|
|
|
|
|
|
|
day_week => qr/([1-7])/o, |
31
|
|
|
|
|
|
|
day_month => qr/(3[01]|[12]\d|0?[1-9])/o, |
32
|
|
|
|
|
|
|
day_year => qr/([1-3]\d\d|0?[1-9]\d|(?:00)?[1-9])/o, |
33
|
|
|
|
|
|
|
month => qr/(1[0-2]|0?[1-9])/o, |
34
|
|
|
|
|
|
|
hour_23 => qr/(00|2[0-4]|1\d|0?\d)/o, |
35
|
|
|
|
|
|
|
hour_24 => qr/(2[0-4]|1\d|0?[1-9])/o, |
36
|
|
|
|
|
|
|
hour_12 => qr/(1[0-2]|0?[1-9])/o, |
37
|
|
|
|
|
|
|
hour_11 => qr/(00|1[01]|0?\d)/o, |
38
|
|
|
|
|
|
|
minute => qr/([0-5]?\d)/o, |
39
|
|
|
|
|
|
|
second => qr/(6[01]|[0-5]?\d)/o, |
40
|
|
|
|
|
|
|
quarter => qr/([1-4])/o, |
41
|
|
|
|
|
|
|
week_year => qr/(5[0-3]|[1-4]\d|0?[1-9])/o, |
42
|
|
|
|
|
|
|
week_month => qr/(\d)/o, |
43
|
|
|
|
|
|
|
#timezone => qr/[+-](1[0-4]|0?\d)(00|15|30|45)/o, |
44
|
|
|
|
|
|
|
number => qr/(\d+)/o, |
45
|
|
|
|
|
|
|
timezone2 => qr/([+-]?[A-Z0-9a-z]+)([+-](?:1[0-4]|0\d)(?:00|15|30|45))/o, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Table for mapping abbreviated timezone names to offsets |
49
|
|
|
|
|
|
|
our %ZONEMAP = ( |
50
|
|
|
|
|
|
|
'A' => '+0100', 'ACDT' => '+1030', 'ACST' => '+0930', |
51
|
|
|
|
|
|
|
'ADT' => 'Ambiguous', 'AEDT' => '+1100', 'AES' => '+1000', |
52
|
|
|
|
|
|
|
'AEST' => '+1000', 'AFT' => '+0430', 'AHDT' => '-0900', |
53
|
|
|
|
|
|
|
'AHST' => '-1000', 'AKDT' => '-0800', 'AKST' => '-0900', |
54
|
|
|
|
|
|
|
'AMST' => '+0400', 'AMT' => '+0400', 'ANAST' => '+1300', |
55
|
|
|
|
|
|
|
'ANAT' => '+1200', 'ART' => '-0300', 'AST' => 'Ambiguous', |
56
|
|
|
|
|
|
|
'AT' => '-0100', 'AWST' => '+0800', 'AZOST' => '+0000', |
57
|
|
|
|
|
|
|
'AZOT' => '-0100', 'AZST' => '+0500', 'AZT' => '+0400', |
58
|
|
|
|
|
|
|
'B' => '+0200', 'BADT' => '+0400', 'BAT' => '+0600', |
59
|
|
|
|
|
|
|
'BDST' => '+0200', 'BDT' => '+0600', 'BET' => '-1100', |
60
|
|
|
|
|
|
|
'BNT' => '+0800', 'BORT' => '+0800', 'BOT' => '-0400', |
61
|
|
|
|
|
|
|
'BRA' => '-0300', 'BST' => 'Ambiguous', 'BT' => 'Ambiguous', |
62
|
|
|
|
|
|
|
'BTT' => '+0600', 'C' => '+0300', 'CAST' => '+0930', |
63
|
|
|
|
|
|
|
'CAT' => 'Ambiguous', 'CCT' => 'Ambiguous', 'CDT' => 'Ambiguous', |
64
|
|
|
|
|
|
|
'CEST' => '+0200', 'CET' => '+0100', 'CETDST' => '+0200', |
65
|
|
|
|
|
|
|
'CHADT' => '+1345', 'CHAST' => '+1245', 'CKT' => '-1000', |
66
|
|
|
|
|
|
|
'CLST' => '-0300', 'CLT' => '-0400', 'COT' => '-0500', |
67
|
|
|
|
|
|
|
'CST' => 'Ambiguous', 'CSuT' => '+1030', 'CUT' => '+0000', |
68
|
|
|
|
|
|
|
'CVT' => '-0100', 'CXT' => '+0700', 'ChST' => '+1000', |
69
|
|
|
|
|
|
|
'D' => '+0400', 'DAVT' => '+0700', 'DDUT' => '+1000', |
70
|
|
|
|
|
|
|
'DNT' => '+0100', 'DST' => '+0200', 'E' => '+0500', |
71
|
|
|
|
|
|
|
'EASST' => '-0500', 'EAST' => 'Ambiguous', 'EAT' => '+0300', |
72
|
|
|
|
|
|
|
'ECT' => 'Ambiguous', 'EDT' => 'Ambiguous', 'EEST' => '+0300', |
73
|
|
|
|
|
|
|
'EET' => '+0200', 'EETDST' => '+0300', 'EGST' => '+0000', |
74
|
|
|
|
|
|
|
'EGT' => '-0100', 'EMT' => '+0100', 'EST' => 'Ambiguous', |
75
|
|
|
|
|
|
|
'ESuT' => '+1100', 'F' => '+0600', 'FDT' => 'Ambiguous', |
76
|
|
|
|
|
|
|
'FJST' => '+1300', 'FJT' => '+1200', 'FKST' => '-0300', |
77
|
|
|
|
|
|
|
'FKT' => '-0400', 'FST' => 'Ambiguous', 'FWT' => '+0100', |
78
|
|
|
|
|
|
|
'G' => '+0700', 'GALT' => '-0600', 'GAMT' => '-0900', |
79
|
|
|
|
|
|
|
'GEST' => '+0500', 'GET' => '+0400', 'GFT' => '-0300', |
80
|
|
|
|
|
|
|
'GILT' => '+1200', 'GMT' => '+0000', 'GST' => 'Ambiguous', |
81
|
|
|
|
|
|
|
'GT' => '+0000', 'GYT' => '-0400', 'GZ' => '+0000', |
82
|
|
|
|
|
|
|
'H' => '+0800', 'HAA' => '-0300', 'HAC' => '-0500', |
83
|
|
|
|
|
|
|
'HAE' => '-0400', 'HAP' => '-0700', 'HAR' => '-0600', |
84
|
|
|
|
|
|
|
'HAT' => '-0230', 'HAY' => '-0800', 'HDT' => '-0930', |
85
|
|
|
|
|
|
|
'HFE' => '+0200', 'HFH' => '+0100', 'HG' => '+0000', |
86
|
|
|
|
|
|
|
'HKT' => '+0800', 'HL' => 'local', 'HNA' => '-0400', |
87
|
|
|
|
|
|
|
'HNC' => '-0600', 'HNE' => '-0500', 'HNP' => '-0800', |
88
|
|
|
|
|
|
|
'HNR' => '-0700', 'HNT' => '-0330', 'HNY' => '-0900', |
89
|
|
|
|
|
|
|
'HOE' => '+0100', 'HST' => '-1000', 'I' => '+0900', |
90
|
|
|
|
|
|
|
'ICT' => '+0700', 'IDLE' => '+1200', 'IDLW' => '-1200', |
91
|
|
|
|
|
|
|
'IDT' => 'Ambiguous', 'IOT' => '+0500', 'IRDT' => '+0430', |
92
|
|
|
|
|
|
|
'IRKST' => '+0900', 'IRKT' => '+0800', 'IRST' => '+0430', |
93
|
|
|
|
|
|
|
'IRT' => '+0330', 'IST' => 'Ambiguous', 'IT' => '+0330', |
94
|
|
|
|
|
|
|
'ITA' => '+0100', 'JAVT' => '+0700', 'JAYT' => '+0900', |
95
|
|
|
|
|
|
|
'JST' => '+0900', 'JT' => '+0700', 'K' => '+1000', |
96
|
|
|
|
|
|
|
'KDT' => '+1000', 'KGST' => '+0600', 'KGT' => '+0500', |
97
|
|
|
|
|
|
|
'KOST' => '+1200', 'KRAST' => '+0800', 'KRAT' => '+0700', |
98
|
|
|
|
|
|
|
'KST' => '+0900', 'L' => '+1100', 'LHDT' => '+1100', |
99
|
|
|
|
|
|
|
'LHST' => '+1030', 'LIGT' => '+1000', 'LINT' => '+1400', |
100
|
|
|
|
|
|
|
'LKT' => '+0600', 'LST' => 'local', 'LT' => 'local', |
101
|
|
|
|
|
|
|
'M' => '+1200', 'MAGST' => '+1200', 'MAGT' => '+1100', |
102
|
|
|
|
|
|
|
'MAL' => '+0800', 'MART' => '-0930', 'MAT' => '+0300', |
103
|
|
|
|
|
|
|
'MAWT' => '+0600', 'MDT' => '-0600', 'MED' => '+0200', |
104
|
|
|
|
|
|
|
'MEDST' => '+0200', 'MEST' => '+0200', 'MESZ' => '+0200', |
105
|
|
|
|
|
|
|
'MET' => 'Ambiguous', 'MEWT' => '+0100', 'MEX' => '-0600', |
106
|
|
|
|
|
|
|
'MEZ' => '+0100', 'MHT' => '+1200', 'MMT' => '+0630', |
107
|
|
|
|
|
|
|
'MPT' => '+1000', 'MSD' => '+0400', 'MSK' => '+0300', |
108
|
|
|
|
|
|
|
'MSKS' => '+0400', 'MST' => '-0700', 'MT' => '+0830', |
109
|
|
|
|
|
|
|
'MUT' => '+0400', 'MVT' => '+0500', 'MYT' => '+0800', |
110
|
|
|
|
|
|
|
'N' => '-0100', 'NCT' => '+1100', 'NDT' => '-0230', |
111
|
|
|
|
|
|
|
'NFT' => 'Ambiguous', 'NOR' => '+0100', 'NOVST' => '+0700', |
112
|
|
|
|
|
|
|
'NOVT' => '+0600', 'NPT' => '+0545', 'NRT' => '+1200', |
113
|
|
|
|
|
|
|
'NST' => 'Ambiguous', 'NSUT' => '+0630', 'NT' => '-1100', |
114
|
|
|
|
|
|
|
'NUT' => '-1100', 'NZDT' => '+1300', 'NZST' => '+1200', |
115
|
|
|
|
|
|
|
'NZT' => '+1200', 'O' => '-0200', 'OESZ' => '+0300', |
116
|
|
|
|
|
|
|
'OEZ' => '+0200', 'OMSST' => '+0700', 'OMST' => '+0600', |
117
|
|
|
|
|
|
|
'OZ' => 'local', 'P' => '-0300', 'PDT' => '-0700', |
118
|
|
|
|
|
|
|
'PET' => '-0500', 'PETST' => '+1300', 'PETT' => '+1200', |
119
|
|
|
|
|
|
|
'PGT' => '+1000', 'PHOT' => '+1300', 'PHT' => '+0800', |
120
|
|
|
|
|
|
|
'PKT' => '+0500', 'PMDT' => '-0200', 'PMT' => '-0300', |
121
|
|
|
|
|
|
|
'PNT' => '-0830', 'PONT' => '+1100', 'PST' => 'Ambiguous', |
122
|
|
|
|
|
|
|
'PWT' => '+0900', 'PYST' => '-0300', 'PYT' => '-0400', |
123
|
|
|
|
|
|
|
'Q' => '-0400', 'R' => '-0500', 'R1T' => '+0200', |
124
|
|
|
|
|
|
|
'R2T' => '+0300', 'RET' => '+0400', 'ROK' => '+0900', |
125
|
|
|
|
|
|
|
'S' => '-0600', 'SADT' => '+1030', 'SAST' => 'Ambiguous', |
126
|
|
|
|
|
|
|
'SBT' => '+1100', 'SCT' => '+0400', 'SET' => '+0100', |
127
|
|
|
|
|
|
|
'SGT' => '+0800', 'SRT' => '-0300', 'SST' => 'Ambiguous', |
128
|
|
|
|
|
|
|
'SWT' => '+0100', 'T' => '-0700', 'TFT' => '+0500', |
129
|
|
|
|
|
|
|
'THA' => '+0700', 'THAT' => '-1000', 'TJT' => '+0500', |
130
|
|
|
|
|
|
|
'TKT' => '-1000', 'TMT' => '+0500', 'TOT' => '+1300', |
131
|
|
|
|
|
|
|
'TRUT' => '+1000', 'TST' => '+0300', 'TUC' => '+0000', |
132
|
|
|
|
|
|
|
'TVT' => '+1200', 'U' => '-0800', 'ULAST' => '+0900', |
133
|
|
|
|
|
|
|
'ULAT' => '+0800', 'USZ1' => '+0200', 'USZ1S' => '+0300', |
134
|
|
|
|
|
|
|
'USZ3' => '+0400', 'USZ3S' => '+0500', 'USZ4' => '+0500', |
135
|
|
|
|
|
|
|
'USZ4S' => '+0600', 'USZ5' => '+0600', 'USZ5S' => '+0700', |
136
|
|
|
|
|
|
|
'USZ6' => '+0700', 'USZ6S' => '+0800', 'USZ7' => '+0800', |
137
|
|
|
|
|
|
|
'USZ7S' => '+0900', 'USZ8' => '+0900', 'USZ8S' => '+1000', |
138
|
|
|
|
|
|
|
'USZ9' => '+1000', 'USZ9S' => '+1100', 'UTZ' => '-0300', |
139
|
|
|
|
|
|
|
'UYT' => '-0300', 'UZ10' => '+1100', 'UZ10S' => '+1200', |
140
|
|
|
|
|
|
|
'UZ11' => '+1200', 'UZ11S' => '+1300', 'UZ12' => '+1200', |
141
|
|
|
|
|
|
|
'UZ12S' => '+1300', 'UZT' => '+0500', 'V' => '-0900', |
142
|
|
|
|
|
|
|
'VET' => '-0400', 'VLAST' => '+1100', 'VLAT' => '+1000', |
143
|
|
|
|
|
|
|
'VTZ' => '-0200', 'VUT' => '+1100', 'W' => '-1000', |
144
|
|
|
|
|
|
|
'WAKT' => '+1200', 'WAST' => 'Ambiguous', 'WAT' => '+0100', |
145
|
|
|
|
|
|
|
'WEST' => '+0100', 'WESZ' => '+0100', 'WET' => '+0000', |
146
|
|
|
|
|
|
|
'WETDST' => '+0100', 'WEZ' => '+0000', 'WFT' => '+1200', |
147
|
|
|
|
|
|
|
'WGST' => '-0200', 'WGT' => '-0300', 'WIB' => '+0700', |
148
|
|
|
|
|
|
|
'WIT' => '+0900', 'WITA' => '+0800', 'WST' => 'Ambiguous', |
149
|
|
|
|
|
|
|
'WTZ' => '-0100', 'WUT' => '+0100', 'X' => '-1100', |
150
|
|
|
|
|
|
|
'Y' => '-1200', 'YAKST' => '+1000', 'YAKT' => '+0900', |
151
|
|
|
|
|
|
|
'YAPT' => '+1000', 'YDT' => '-0800', 'YEKST' => '+0600', |
152
|
|
|
|
|
|
|
'YEKT' => '+0500', 'YST' => '-0900', 'Z' => '+0000', |
153
|
|
|
|
|
|
|
); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# Map of CLDR commands to values |
156
|
|
|
|
|
|
|
# Value might be |
157
|
|
|
|
|
|
|
# - Regular expression: usually taken from %PART |
158
|
|
|
|
|
|
|
# - String: DateTime::Locale method names. Method must retun lists of valid values |
159
|
|
|
|
|
|
|
# - Arrayref: List of valid values |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
our %PARSER = ( |
162
|
|
|
|
|
|
|
G1 => 'era_abbreviated', |
163
|
|
|
|
|
|
|
G4 => 'era_wide', |
164
|
|
|
|
|
|
|
G5 => 'era_narrow', |
165
|
|
|
|
|
|
|
y1 => $PARTS{year_long}, |
166
|
|
|
|
|
|
|
y2 => $PARTS{year_short}, |
167
|
|
|
|
|
|
|
y3 => qr/(-?\d{3,4})/o, |
168
|
|
|
|
|
|
|
y4 => qr/(-?\d{4})/o, |
169
|
|
|
|
|
|
|
y5 => qr/(-?\d{5})/o, |
170
|
|
|
|
|
|
|
Y1 => $PARTS{year_long}, |
171
|
|
|
|
|
|
|
u1 => $PARTS{year_long}, |
172
|
|
|
|
|
|
|
Q1 => $PARTS{quarter}, |
173
|
|
|
|
|
|
|
Q3 => 'quarter_format_abbreviated', |
174
|
|
|
|
|
|
|
Q4 => 'quarter_format_wide', |
175
|
|
|
|
|
|
|
q1 => $PARTS{quarter}, |
176
|
|
|
|
|
|
|
q3 => 'quarter_stand_alone_abbreviated', |
177
|
|
|
|
|
|
|
q4 => 'quarter_stand_alone_wide', |
178
|
|
|
|
|
|
|
M1 => $PARTS{month}, |
179
|
|
|
|
|
|
|
M3 => 'month_format_abbreviated', |
180
|
|
|
|
|
|
|
M4 => 'month_format_wide', |
181
|
|
|
|
|
|
|
M5 => 'month_format_narrow', |
182
|
|
|
|
|
|
|
L1 => $PARTS{month}, |
183
|
|
|
|
|
|
|
L3 => 'month_stand_alone_abbreviated', |
184
|
|
|
|
|
|
|
L4 => 'month_stand_alone_wide', |
185
|
|
|
|
|
|
|
L5 => 'month_stand_alone_narrow', |
186
|
|
|
|
|
|
|
w1 => $PARTS{week_year}, |
187
|
|
|
|
|
|
|
W1 => $PARTS{week_month}, |
188
|
|
|
|
|
|
|
d1 => $PARTS{day_month}, |
189
|
|
|
|
|
|
|
D1 => $PARTS{day_year}, |
190
|
|
|
|
|
|
|
F1 => $PARTS{week_month}, |
191
|
|
|
|
|
|
|
E1 => 'day_format_abbreviated', |
192
|
|
|
|
|
|
|
E4 => 'day_format_wide', |
193
|
|
|
|
|
|
|
E5 => 'day_format_narrow', |
194
|
|
|
|
|
|
|
e1 => $PARTS{day_week}, |
195
|
|
|
|
|
|
|
e3 => 'day_format_abbreviated', |
196
|
|
|
|
|
|
|
e4 => 'day_format_wide', |
197
|
|
|
|
|
|
|
e5 => 'day_format_narrow', |
198
|
|
|
|
|
|
|
c1 => $PARTS{day_week}, |
199
|
|
|
|
|
|
|
c3 => 'day_stand_alone_abbreviated', |
200
|
|
|
|
|
|
|
c4 => 'day_stand_alone_wide', |
201
|
|
|
|
|
|
|
c5 => 'day_stand_alone_narrow', |
202
|
|
|
|
|
|
|
a1 => 'am_pm_abbreviated', |
203
|
|
|
|
|
|
|
h1 => $PARTS{hour_12}, |
204
|
|
|
|
|
|
|
H1 => $PARTS{hour_23}, |
205
|
|
|
|
|
|
|
K1 => $PARTS{hour_11}, |
206
|
|
|
|
|
|
|
k1 => $PARTS{hour_24}, |
207
|
|
|
|
|
|
|
#j1 => Handled dyamically, |
208
|
|
|
|
|
|
|
m1 => $PARTS{minute}, |
209
|
|
|
|
|
|
|
s1 => $PARTS{second}, |
210
|
|
|
|
|
|
|
S1 => $PARTS{number}, #! |
211
|
|
|
|
|
|
|
Z1 => [ grep { $_ ne 'Ambiguous' } values %ZONEMAP ], |
212
|
|
|
|
|
|
|
Z4 => $PARTS{timezone2}, |
213
|
|
|
|
|
|
|
Z5 => qr/([+-]\d\d:\d\d)/o, |
214
|
|
|
|
|
|
|
z1 => [ qr/[+-][0-9]{2,4}/, keys %ZONEMAP ], |
215
|
|
|
|
|
|
|
z4 => [ DateTime::TimeZone->all_names ], |
216
|
|
|
|
|
|
|
); |
217
|
|
|
|
|
|
|
$PARSER{v1} = $PARSER{V1} = $PARSER{z1}; |
218
|
|
|
|
|
|
|
$PARSER{v4} = $PARSER{V4} = $PARSER{z4}; |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=encoding utf8 |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 NAME |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
DateTime::Format::CLDR - Parse and format CLDR time patterns |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 SYNOPSIS |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
use DateTime::Format::CLDR; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# 1. Basic example |
232
|
|
|
|
|
|
|
my $cldr1 = DateTime::Format::CLDR->new( |
233
|
|
|
|
|
|
|
pattern => 'HH:mm:ss', |
234
|
|
|
|
|
|
|
locale => 'de_AT', |
235
|
|
|
|
|
|
|
time_zone => 'Europe/Vienna', |
236
|
|
|
|
|
|
|
); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
my $dt1 = $cldr1->parse_datetime('23:16:42'); |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
print $cldr1->format_datetime($dt1); |
241
|
|
|
|
|
|
|
# 23:16:42 |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# 2. Get pattern from selected locale |
244
|
|
|
|
|
|
|
# pattern is taken from 'date_format_medium' in DateTime::Locale::de_AT |
245
|
|
|
|
|
|
|
my $cldr2 = DateTime::Format::CLDR->new( |
246
|
|
|
|
|
|
|
locale => 'de_AT', |
247
|
|
|
|
|
|
|
); |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
print $cldr2->parse_datetime('23.11.2007'); |
250
|
|
|
|
|
|
|
# 2007-11-23T00:00:00 |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
# 3. Croak when things go wrong |
253
|
|
|
|
|
|
|
my $cldr3 = DateTime::Format::CLDR->new( |
254
|
|
|
|
|
|
|
locale => 'de_AT', |
255
|
|
|
|
|
|
|
on_error => 'croak', |
256
|
|
|
|
|
|
|
); |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$cldr3->parse_datetime('23.33.2007'); |
259
|
|
|
|
|
|
|
# Croaks |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
# 4. Use DateTime::Locale |
262
|
|
|
|
|
|
|
my $locale = DateTime::Locale->load('en_GB'); |
263
|
|
|
|
|
|
|
my $cldr4 = DateTime::Format::CLDR->new( |
264
|
|
|
|
|
|
|
pattern => $locale->datetime_format_medium, |
265
|
|
|
|
|
|
|
locale => $locale, |
266
|
|
|
|
|
|
|
); |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
print $cldr4->parse_datetime('22 Dec 1995 09:05:02'); |
269
|
|
|
|
|
|
|
# 1995-12-22T09:05:02 |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 DESCRIPTION |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
This module provides a parser (and also a formater) for datetime strings |
274
|
|
|
|
|
|
|
using patterns as defined by the Unicode CLDR Project |
275
|
|
|
|
|
|
|
(Common Locale Data Repository). L<http://unicode.org/cldr/>. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
CLDR format is supported by L<DateTime> and L<DateTime::Locale> starting with |
278
|
|
|
|
|
|
|
version 0.40. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head1 METHODS |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head2 Constructor |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head3 new |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
DateTime::Format::CLDR->new(%PARAMS); |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
The following parameters are used by DateTime::Format::CLDR: |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=over |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=item * locale |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Locale. |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
See L<locale> accessor. |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=item * pattern (optional) |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
CLDR pattern. If you don't provide a pattern the C<date_format_medium> |
301
|
|
|
|
|
|
|
pattern from L<DateTime::Local> for the selected locale will be used. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
See L<pattern> accessor. |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=item * time_zone (optional) |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
Timezone that should be used by default. If your pattern contains |
308
|
|
|
|
|
|
|
timezone information this attribute will be ignored. |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
See L<time_zone> accessor. |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=item * on_error (optional) |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
Set the error behaviour. |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
See L<on_error> accessor. |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=item * incomplete (optional) |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
Set the behaviour how to handle incomplete date information. |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
See L<incomplete> accessor. |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=back |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
=cut |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
sub new { ## no perlcritic(RequireArgUnpacking) |
329
|
118
|
|
|
118
|
1
|
159701
|
my $class = shift; |
330
|
118
|
|
|
|
|
4486
|
my %args = validate( @_, { |
331
|
|
|
|
|
|
|
locale => { type => SCALAR | OBJECT, default => 'en' }, |
332
|
|
|
|
|
|
|
pattern => { type => SCALAR, optional => 1 }, |
333
|
|
|
|
|
|
|
time_zone => { type => SCALAR | OBJECT, optional => 1 }, |
334
|
|
|
|
|
|
|
on_error => { type => SCALAR | CODEREF, optional => 1, default => 'undef' }, |
335
|
|
|
|
|
|
|
incomplete => { type => SCALAR | CODEREF, optional => 1, default => 1 }, |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
); |
338
|
|
|
|
|
|
|
|
339
|
118
|
|
|
|
|
923
|
my $self = bless \%args, $class; |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
# Set default values |
342
|
118
|
|
66
|
|
|
1002
|
$args{time_zone} ||= DateTime::TimeZone->new( name => 'floating' ); |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
# Pass on to accessors |
345
|
118
|
|
|
|
|
8249
|
$self->time_zone($args{time_zone}); |
346
|
118
|
|
|
|
|
488
|
$self->locale($args{locale}); |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
# Set default values |
349
|
118
|
100
|
|
|
|
587
|
unless (defined $args{pattern}) { |
350
|
6
|
50
|
|
|
|
22
|
if ($self->locale->can($DEFAULT_FORMAT)) { |
351
|
6
|
|
|
|
|
20
|
$args{pattern} = $self->locale->$DEFAULT_FORMAT; |
352
|
|
|
|
|
|
|
} else { |
353
|
0
|
|
|
|
|
0
|
croak("Method '$DEFAULT_FORMAT' not available in ".ref($self->loclale)); |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
|
357
|
118
|
|
|
|
|
522
|
$self->pattern($args{pattern}); |
358
|
118
|
|
|
|
|
453
|
$self->on_error($args{on_error}); |
359
|
118
|
|
|
|
|
432
|
$self->incomplete($args{incomplete}); |
360
|
118
|
|
|
|
|
317
|
$self->{errmsg} = undef; |
361
|
|
|
|
|
|
|
|
362
|
118
|
|
|
|
|
409
|
return $self; |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
=head2 Accessors |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
=head3 pattern |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
Get/set CLDR pattern. See L<"CLDR PATTERNS"> or L<DateTime/"CLDR Patterns"> |
370
|
|
|
|
|
|
|
for details about patterns. |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
$cldr->pattern('d MMM y HH:mm:ss'); |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
It is possible to retrieve patterns from L<DateTime::Locale> |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
$dl = DateTime::Locale->load('es_AR'); |
377
|
|
|
|
|
|
|
$cldr->pattern($dl->datetime_format_full); |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
=cut |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
sub pattern { |
382
|
133
|
|
|
133
|
1
|
7786
|
my ($self,$pattern) = @_; |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
# Set pattern |
385
|
133
|
100
|
|
|
|
418
|
if (defined $pattern) { |
386
|
119
|
|
|
|
|
277
|
$self->{pattern} = $pattern; |
387
|
119
|
|
|
|
|
242
|
undef $self->{_built_pattern}; |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
|
390
|
133
|
|
|
|
|
319
|
return $self->{pattern}; |
391
|
|
|
|
|
|
|
} |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
=head3 time_zone |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
Get/set time_zone. Returns a C<DateTime::TimeZone> object. |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
Accepts either a timezone name or a C<DateTime::TimeZone> object. |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
$cldr->time_zone('America/Argentina/Mendoza'); |
400
|
|
|
|
|
|
|
OR |
401
|
|
|
|
|
|
|
my $tz = DateTime::TimeZone->new(name => 'America/Argentina/Mendoza'); |
402
|
|
|
|
|
|
|
$cldr->time_zone($tz); |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
=cut |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
sub time_zone { |
407
|
123
|
|
|
123
|
1
|
3305
|
my ($self,$time_zone) = @_; |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
# Set timezone |
410
|
123
|
100
|
|
|
|
432
|
if (defined $time_zone) { |
411
|
121
|
100
|
66
|
|
|
1083
|
if (ref $time_zone |
412
|
|
|
|
|
|
|
&& $time_zone->isa('DateTime::TimeZone')) { |
413
|
114
|
|
|
|
|
352
|
$self->{time_zone} = $time_zone; |
414
|
|
|
|
|
|
|
} else { |
415
|
7
|
50
|
|
|
|
67
|
$self->{time_zone} = DateTime::TimeZone->new( name => $time_zone ) |
416
|
|
|
|
|
|
|
or croak("Could not create timezone from $time_zone"); |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
} |
419
|
|
|
|
|
|
|
|
420
|
121
|
|
|
|
|
58377
|
return $self->{time_zone}; |
421
|
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
=head3 locale |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
Get/set a locale. Returns a C<DateTime::Locale> object. |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
Accepts either a locale name or a C<DateTime::Locale::*> object. |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
$cldr->locale('fr_CA'); |
430
|
|
|
|
|
|
|
OR |
431
|
|
|
|
|
|
|
$dl = DateTime::Locale->load('fr_CA'); |
432
|
|
|
|
|
|
|
$cldr->locale($dl); |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
=cut |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
sub locale { |
437
|
134
|
|
|
134
|
1
|
1513
|
my ($self,$locale) = @_; |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
# Set locale |
440
|
134
|
100
|
|
|
|
427
|
if (defined $locale) { |
441
|
120
|
100
|
33
|
|
|
2177
|
unless (ref $locale |
|
|
|
66
|
|
|
|
|
442
|
|
|
|
|
|
|
&& ($locale->isa('DateTime::Locale::Base') || $locale->isa('DateTime::Locale::FromData'))) { |
443
|
106
|
50
|
|
|
|
697
|
$self->{locale} = DateTime::Locale->load( $locale ) |
444
|
|
|
|
|
|
|
or croak("Could not create locale from $locale"); |
445
|
|
|
|
|
|
|
} else { |
446
|
14
|
|
|
|
|
40
|
$self->{locale} = $locale; |
447
|
|
|
|
|
|
|
} |
448
|
119
|
|
|
|
|
11391
|
undef $self->{_built_pattern}; |
449
|
|
|
|
|
|
|
} |
450
|
|
|
|
|
|
|
|
451
|
133
|
|
|
|
|
368
|
return $self->{locale}; |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
=head3 on_error |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
Get/set the error behaviour. |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
Accepts the following values |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
=over |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
=item * 'undef' (Literal) (default) |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
Returns undef on error and sets L<errmsg> |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
=item * 'croak' |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
Croak on error |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
=item * CODEREF |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
Run the given coderef on error. |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
=back |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
=cut |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
sub on_error { |
479
|
120
|
|
|
120
|
1
|
1069
|
my ($self,$on_error) = @_; |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
# Set locale |
482
|
120
|
100
|
|
|
|
365
|
if (defined $on_error) { |
483
|
119
|
100
|
100
|
|
|
913
|
croak("The value supplied to on_error must be either 'croak', 'undef' or a code reference.") |
|
|
|
100
|
|
|
|
|
484
|
|
|
|
|
|
|
unless ref($on_error) eq 'CODE' |
485
|
|
|
|
|
|
|
or $on_error eq 'croak' |
486
|
|
|
|
|
|
|
or $on_error eq 'undef'; |
487
|
118
|
|
|
|
|
290
|
return $self->{on_error}; |
488
|
|
|
|
|
|
|
} |
489
|
1
|
|
|
|
|
5
|
return $self->{on_error}; |
490
|
|
|
|
|
|
|
} |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
=head3 incomplete |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
Set the behaviour how to handle incomplete Date information. |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
Accepts the following values |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
=over |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
=item * '1' (default) |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
Sets the missing values to '1'. Thus if you only parse a time sting you would |
503
|
|
|
|
|
|
|
get '0001-01-01' as the date. |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
=item * 'incomplete' |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
Create a L<DateTime::Incomplete> object instead. |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
=item * CODEREF |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
Run the given coderef on incomplete values. The code reference will be |
512
|
|
|
|
|
|
|
called with the C<DateTime::Format::CLDR> object and a hash of parsed values |
513
|
|
|
|
|
|
|
as supplied to C<DateTime-E<gt>new>. It should return a modified hash which |
514
|
|
|
|
|
|
|
will be passed to C<DateTime-E<gt>new>. |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=back |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=cut |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
sub incomplete { |
521
|
120
|
|
|
120
|
1
|
1234
|
my ($self,$incomplete) = @_; |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
# Set locale |
524
|
120
|
100
|
|
|
|
340
|
if (defined $incomplete) { |
525
|
119
|
100
|
100
|
|
|
767
|
croak("The value supplied to incomplete must be either 'incomplete', '1' or a code reference.") |
|
|
|
100
|
|
|
|
|
526
|
|
|
|
|
|
|
unless ref($incomplete) eq 'CODE' |
527
|
|
|
|
|
|
|
or $incomplete eq '1' |
528
|
|
|
|
|
|
|
or $incomplete eq 'incomplete'; |
529
|
118
|
|
|
|
|
261
|
return $self->{incomplete}; |
530
|
|
|
|
|
|
|
} |
531
|
1
|
|
|
|
|
5
|
return $self->{incomplete}; |
532
|
|
|
|
|
|
|
} |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
=head2 Public Methods |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
=head3 parse_datetime |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
my $datetime = $cldr->parse_datetime($string); |
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
Parses a string and returns a C<DateTime> object on success (If you provide |
541
|
|
|
|
|
|
|
incomplete data and set the L<incomplete> attribute accordingly it will |
542
|
|
|
|
|
|
|
return a C<DateTime::Incomplete> object). If the string cannot be parsed |
543
|
|
|
|
|
|
|
an error will be thrown (depending on the C<on_error> attribute). |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
=cut |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
sub parse_datetime { ## no perlcritic(RequireArgUnpacking) |
548
|
12883
|
|
|
12883
|
1
|
9694794
|
my ( $self, $string ) = validate_pos( @_, 1, { type => SCALAR } ); |
549
|
|
|
|
|
|
|
|
550
|
12883
|
|
|
|
|
62401
|
my $pattern = $self->_build_pattern(); |
551
|
|
|
|
|
|
|
|
552
|
12883
|
|
|
|
|
29545
|
my $datetime_initial = $string; |
553
|
12883
|
|
|
|
|
28680
|
my %datetime_info = (); |
554
|
12883
|
|
|
|
|
27399
|
my %datetime_check = (); |
555
|
|
|
|
|
|
|
my $datetime_error = sub { |
556
|
7
|
|
|
7
|
|
21
|
my $occurence = shift; |
557
|
7
|
|
|
|
|
16
|
my $error = $datetime_initial; |
558
|
7
|
|
|
|
|
29
|
substr($error,(length($occurence) * -1),0," HERE-->"); |
559
|
7
|
|
|
|
|
41
|
return $self->_local_croak("Could not get datetime for $datetime_initial (Error marked by 'HERE-->'): '$error'"); |
560
|
12883
|
|
|
|
|
67057
|
}; |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
# Set default datetime values |
563
|
|
|
|
|
|
|
my %datetime = ( |
564
|
|
|
|
|
|
|
hour => 0, |
565
|
|
|
|
|
|
|
minute => 0, |
566
|
|
|
|
|
|
|
second => 0, |
567
|
|
|
|
|
|
|
time_zone => $self->{time_zone}, |
568
|
|
|
|
|
|
|
locale => $self->{locale}, |
569
|
12883
|
|
|
|
|
67571
|
nanosecond => 0, |
570
|
|
|
|
|
|
|
); |
571
|
|
|
|
|
|
|
|
572
|
12883
|
|
|
|
|
24067
|
PART: foreach my $part (@{$pattern}) { |
|
12883
|
|
|
|
|
31375
|
|
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
#my $before = $string; |
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
# Pattern |
577
|
163747
|
100
|
|
|
|
1452371
|
if (ref $part eq 'ARRAY') { |
|
|
100
|
|
|
|
|
|
578
|
77532
|
|
|
|
|
124645
|
my ($regexp,$command,$index) = @{$part}; |
|
77532
|
|
|
|
|
205319
|
|
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
#print "TRY TO MATCH '$string' AGAINST '$regexp' WITH $command\n"; |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
# Match regexp part |
583
|
77532
|
100
|
|
|
|
7389749
|
return $datetime_error->($string) |
584
|
|
|
|
|
|
|
unless ($string =~ s/^ \s* $regexp//ix); |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
# Get capture |
587
|
77528
|
|
|
|
|
388574
|
my $capture = $1; |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
# Pattern is a list: get index instead of value |
590
|
77528
|
100
|
|
|
|
282911
|
if (ref $PARSER{$command.$index} eq '') { |
591
|
14044
|
|
|
|
|
35761
|
my $function = $PARSER{$command.$index}; |
592
|
14044
|
|
|
|
|
24100
|
my $count = 1; |
593
|
14044
|
|
|
|
|
25006
|
my $tmpcapture; |
594
|
14044
|
|
|
|
|
23011
|
foreach my $element (@{$self->{locale}->$function}) { |
|
14044
|
|
|
|
|
70915
|
|
595
|
98441
|
100
|
|
|
|
363131
|
if (lc($element) eq lc($capture)) { |
596
|
14045
|
100
|
|
|
|
41333
|
if (defined $tmpcapture) { |
597
|
1
|
|
|
|
|
7
|
$self->_local_carp("Expression '$capture' is ambigous for pattern '$command$index' "); |
598
|
1
|
|
|
|
|
4
|
next PART; |
599
|
|
|
|
|
|
|
} |
600
|
14044
|
|
|
|
|
26248
|
$tmpcapture = $count; |
601
|
|
|
|
|
|
|
} |
602
|
98440
|
|
|
|
|
163998
|
$count ++; |
603
|
|
|
|
|
|
|
} |
604
|
14043
|
|
|
|
|
30187
|
$capture = $tmpcapture; |
605
|
|
|
|
|
|
|
} |
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
# Run patterns |
608
|
77527
|
100
|
100
|
|
|
1100818
|
if ($command eq 'G' ) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
609
|
15
|
|
|
|
|
39
|
$datetime_info{era} = $capture; |
610
|
|
|
|
|
|
|
} elsif ($command eq 'y' && $index == 2) { |
611
|
750
|
|
|
|
|
1775
|
$datetime{year} = $capture; |
612
|
750
|
100
|
|
|
|
2107
|
if ($datetime{year} >= 70) { |
613
|
372
|
|
|
|
|
883
|
$datetime{year} += 1900; |
614
|
|
|
|
|
|
|
} else { |
615
|
378
|
|
|
|
|
1028
|
$datetime{year} += 2000; |
616
|
|
|
|
|
|
|
} |
617
|
|
|
|
|
|
|
} elsif ($command eq 'y' ) { |
618
|
9210
|
|
|
|
|
32045
|
$datetime{year} = $capture; |
619
|
|
|
|
|
|
|
} elsif ($command eq 'Q' || $command eq 'q') { |
620
|
30
|
|
|
|
|
104
|
$datetime_check{quarter} = $capture; |
621
|
|
|
|
|
|
|
} elsif ($command eq 'M' || $command eq 'L') { |
622
|
9982
|
|
|
|
|
34562
|
$datetime{month} = $capture; |
623
|
|
|
|
|
|
|
} elsif ($command eq 'w') { |
624
|
5
|
|
|
|
|
17
|
$datetime_check{week_number} = $capture; |
625
|
|
|
|
|
|
|
} elsif ($command eq 'W') { |
626
|
5
|
|
|
|
|
30
|
$datetime_check{week_of_month} = $capture; |
627
|
|
|
|
|
|
|
} elsif ($command eq 'd') { |
628
|
9944
|
|
|
|
|
39853
|
$datetime{day} = $capture; |
629
|
|
|
|
|
|
|
} elsif ($command eq 'D') { |
630
|
5
|
|
|
|
|
15
|
$datetime_check{day_of_year} = $capture; |
631
|
|
|
|
|
|
|
} elsif ($command eq 'e' && $index == 1) { |
632
|
5
|
|
|
|
|
19
|
my $fdow = $self->{locale}->first_day_of_week(); |
633
|
5
|
|
|
|
|
24
|
$capture -= (8 - $fdow); |
634
|
5
|
100
|
|
|
|
16
|
$capture += 7 if $capture < 1; |
635
|
5
|
|
|
|
|
18
|
$datetime_check{day_of_week} = $capture; |
636
|
|
|
|
|
|
|
} elsif ($command eq 'E' || $command eq 'c' || $command eq 'e') { |
637
|
2223
|
|
|
|
|
9694
|
$datetime_check{day_of_week} = $capture; |
638
|
|
|
|
|
|
|
} elsif ($command eq 'F') { |
639
|
5
|
|
|
|
|
19
|
$datetime_check{weekday_of_month} = $capture; |
640
|
|
|
|
|
|
|
} elsif ($command eq 'a' ) { |
641
|
5868
|
|
|
|
|
20658
|
$datetime_info{ampm} = $capture; |
642
|
|
|
|
|
|
|
} elsif ($command eq 'h') { # 1-12 |
643
|
5864
|
100
|
|
|
|
20653
|
$capture = 0 if $capture == 12; |
644
|
5864
|
|
|
|
|
21526
|
$datetime_info{hour12} = $capture; |
645
|
|
|
|
|
|
|
} elsif ($command eq 'K') { # 0-11 |
646
|
4
|
|
|
|
|
13
|
$datetime_info{hour12} = $capture; |
647
|
|
|
|
|
|
|
} elsif ($command eq 'H') { # 0-23 |
648
|
6800
|
|
|
|
|
36971
|
$datetime{hour} = $capture; |
649
|
|
|
|
|
|
|
} elsif ($command eq 'k') { # 1-24 |
650
|
8
|
|
|
|
|
23
|
$datetime_info{hour24} = $capture; |
651
|
|
|
|
|
|
|
} elsif ($command eq 'm') { |
652
|
12310
|
|
|
|
|
40405
|
$datetime{minute} = $capture; |
653
|
|
|
|
|
|
|
} elsif ($command eq 's') { |
654
|
9489
|
|
|
|
|
30980
|
$datetime{second} = $capture; |
655
|
|
|
|
|
|
|
} elsif ($command eq 'S' ) { |
656
|
12
|
|
|
|
|
76
|
$datetime{nanosecond} = int("0.$capture" * 1000000000); |
657
|
|
|
|
|
|
|
} elsif ($command eq 'Z') { |
658
|
360
|
100
|
|
|
|
1006
|
if ($index == 4) { |
659
|
120
|
|
|
|
|
323
|
$capture = $2; |
660
|
|
|
|
|
|
|
} |
661
|
360
|
|
|
|
|
1598
|
$datetime{time_zone} = DateTime::TimeZone->new( name => $capture ); |
662
|
|
|
|
|
|
|
} elsif (($command eq 'z' || $command eq 'v' || $command eq 'V') && $index == 1) { |
663
|
2317
|
100
|
66
|
|
|
19208
|
if ($capture =~ m/^[+-]\d\d(\d\d)?/) { |
|
|
100
|
|
|
|
|
|
664
|
48
|
100
|
|
|
|
170
|
$capture .= '00' |
665
|
|
|
|
|
|
|
if ! defined $1; |
666
|
48
|
|
|
|
|
229
|
$datetime{time_zone} = DateTime::TimeZone->new(name => $capture); |
667
|
|
|
|
|
|
|
} elsif (! defined $ZONEMAP{$capture} |
668
|
|
|
|
|
|
|
|| $ZONEMAP{$capture} eq 'Ambiguous') { |
669
|
1
|
|
|
|
|
9
|
$self->_local_carp("Ambiguous timezone: $capture $command"); |
670
|
|
|
|
|
|
|
} else { |
671
|
2268
|
|
|
|
|
13304
|
$datetime{time_zone} = DateTime::TimeZone->new(name => $ZONEMAP{$capture}); |
672
|
|
|
|
|
|
|
} |
673
|
|
|
|
|
|
|
} elsif ($command eq 'z' || $command eq 'v' || $command eq 'V') { |
674
|
2316
|
|
|
|
|
15715
|
$datetime{time_zone} = DateTime::TimeZone->new(name => $capture); |
675
|
|
|
|
|
|
|
} else { |
676
|
0
|
|
|
|
|
0
|
return $self->_local_croak("Could not get datetime for '$datetime_initial': Unknown pattern $command$index"); |
677
|
|
|
|
|
|
|
} |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
# String |
680
|
|
|
|
|
|
|
} elsif ($string !~ s/^ \s* $part//ix) { |
681
|
2
|
|
|
|
|
10
|
return $datetime_error->($string); |
682
|
|
|
|
|
|
|
} |
683
|
|
|
|
|
|
|
#print "BEFORE: '$before' AFTER: '$string' PATTERN: '$part'\n"; |
684
|
|
|
|
|
|
|
} |
685
|
|
|
|
|
|
|
|
686
|
12877
|
100
|
|
|
|
1088045
|
return $datetime_error->($string) |
687
|
|
|
|
|
|
|
if $string ne ''; |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
# Handle 12 hour time notations |
690
|
12876
|
100
|
66
|
|
|
53999
|
if (defined $datetime_info{hour12} |
691
|
|
|
|
|
|
|
&& defined $datetime_info{ampm}) { |
692
|
5868
|
|
|
|
|
14121
|
$datetime{hour} = $datetime_info{hour12}; |
693
|
|
|
|
|
|
|
$datetime{hour} += 12 |
694
|
5868
|
100
|
66
|
|
|
31093
|
if $datetime_info{ampm} == 2 && $datetime{hour} < 12; |
695
|
|
|
|
|
|
|
} |
696
|
12876
|
100
|
|
|
|
36352
|
if (defined $datetime_info{hour24}) { |
697
|
8
|
|
|
|
|
16
|
$datetime{hour} = $datetime_info{hour24}; |
698
|
8
|
100
|
|
|
|
49
|
if ($datetime{hour} == 24) { |
699
|
3
|
|
|
|
|
8
|
$datetime{hour} = 0; |
700
|
|
|
|
|
|
|
} |
701
|
|
|
|
|
|
|
} |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
# Handle 24:00:00 time notations |
704
|
12876
|
100
|
|
|
|
40517
|
if ($datetime{hour} == 24) { |
705
|
3
|
100
|
66
|
|
|
16
|
if ($datetime{minute} == 0 |
|
|
|
66
|
|
|
|
|
706
|
|
|
|
|
|
|
&& $datetime{second} == 0 |
707
|
|
|
|
|
|
|
&& $datetime{nanosecond} == 0) { |
708
|
2
|
|
|
|
|
4
|
$datetime{hour} = 0; |
709
|
2
|
|
|
|
|
5
|
$datetime_info{dayadd} = 1; |
710
|
|
|
|
|
|
|
} else { |
711
|
1
|
|
|
|
|
7
|
return $self->_local_croak("Could not get datetime for $datetime_initial: Invalid 24-hour notation") |
712
|
|
|
|
|
|
|
} |
713
|
|
|
|
|
|
|
} |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
# Handle era |
716
|
12875
|
50
|
66
|
|
|
41023
|
if (defined $datetime_info{era} |
|
|
|
33
|
|
|
|
|
717
|
|
|
|
|
|
|
&& $datetime_info{era} == 0 |
718
|
|
|
|
|
|
|
&& defined $datetime{year}) { |
719
|
0
|
|
|
|
|
0
|
$datetime{year} *= -1; |
720
|
|
|
|
|
|
|
} |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
# Handle incomplete datetime information |
723
|
12875
|
100
|
100
|
|
|
75294
|
unless (defined $datetime{year} |
|
|
|
100
|
|
|
|
|
724
|
|
|
|
|
|
|
&& defined $datetime{month} |
725
|
|
|
|
|
|
|
&& defined $datetime{day}) { |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
# I want given/when in 5.8 |
728
|
2935
|
100
|
|
|
|
8740
|
if (ref $self->{incomplete} eq 'CODE') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
729
|
1
|
|
|
|
|
5
|
%datetime = &{$self->{incomplete}}($self,%datetime); |
|
1
|
|
|
|
|
5
|
|
730
|
|
|
|
|
|
|
} elsif ($self->{incomplete} eq '1') { |
731
|
2933
|
|
50
|
|
|
14239
|
$datetime{day} ||= 1; |
732
|
2933
|
|
100
|
|
|
11718
|
$datetime{month} ||= 1; |
733
|
2933
|
|
100
|
|
|
9476
|
$datetime{year} ||= 1; |
734
|
|
|
|
|
|
|
} elsif ($self->{incomplete} eq 'incomplete') { |
735
|
1
|
|
|
|
|
589
|
require DateTime::Incomplete; |
736
|
1
|
|
|
|
|
40769
|
my $dt = eval { |
737
|
1
|
|
|
|
|
12
|
return DateTime::Incomplete->new(%datetime); |
738
|
|
|
|
|
|
|
}; |
739
|
1
|
50
|
33
|
|
|
76
|
return $self->_local_croak("Could not get datetime for $datetime_initial: $@") |
740
|
|
|
|
|
|
|
if $@ || ref $dt ne 'DateTime::Incomplete'; |
741
|
1
|
|
|
|
|
15
|
return $dt; |
742
|
|
|
|
|
|
|
} else { |
743
|
0
|
|
|
|
|
0
|
return $self->_local_croak("Could not get datetime for $datetime_initial: Invalid incomplete setting"); |
744
|
|
|
|
|
|
|
} |
745
|
|
|
|
|
|
|
} |
746
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
# Build datetime |
748
|
12874
|
|
|
|
|
26137
|
my $dt = eval { |
749
|
12874
|
|
|
|
|
75491
|
return DateTime->new(%datetime); |
750
|
|
|
|
|
|
|
}; |
751
|
12874
|
100
|
66
|
|
|
6702746
|
return $self->_local_croak("Could not get datetime for $datetime_initial: $@") |
752
|
|
|
|
|
|
|
if $@ || ref $dt ne 'DateTime'; |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
# Postprocessing |
755
|
12871
|
100
|
|
|
|
41056
|
if ($datetime_info{dayadd}) { |
756
|
2
|
|
|
|
|
9
|
$dt->add( days => 1 ); |
757
|
|
|
|
|
|
|
} |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
# Perform checks |
760
|
12871
|
|
|
|
|
39288
|
foreach my $check ( keys %datetime_check ) { |
761
|
2278
|
100
|
|
|
|
11108
|
unless ($dt->$check == $datetime_check{$check}) { |
762
|
2
|
|
|
|
|
26
|
return $self->_local_croak("Datetime '$check' does not match ('$datetime_check{$check}' vs. '".$dt->$check."') for '$datetime_initial'"); |
763
|
|
|
|
|
|
|
} |
764
|
|
|
|
|
|
|
} |
765
|
|
|
|
|
|
|
|
766
|
12869
|
|
|
|
|
117358
|
return $dt; |
767
|
|
|
|
|
|
|
} |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
=head3 format_datetime |
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
my $string = $cldr->format_datetime($datetime); |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
Formats a C<DateTime> object using the set locale and pattern. (not the |
774
|
|
|
|
|
|
|
time_zone) |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
=cut |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
sub format_datetime { |
779
|
12805
|
|
|
12805
|
1
|
23749438
|
my ( $self, $dt ) = @_; |
780
|
|
|
|
|
|
|
|
781
|
12805
|
50
|
33
|
|
|
126155
|
$dt = DateTime->now |
|
|
|
33
|
|
|
|
|
782
|
|
|
|
|
|
|
unless defined $dt && ref $dt && $dt->isa('DateTime'); |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
#see http://rt.cpan.org/Public/Bug/Display.html?id=49605 |
785
|
|
|
|
|
|
|
#my ( $self, $dt ) = validate_pos( @_, 1, { default => DateTime->now, type => OBJECT } ); |
786
|
12805
|
|
|
|
|
44336
|
$dt = $dt->clone; |
787
|
12805
|
|
|
|
|
169770
|
$dt->set_locale($self->{locale}); |
788
|
|
|
|
|
|
|
|
789
|
12805
|
|
|
|
|
1442468
|
return $dt->format_cldr($self->{pattern}); |
790
|
|
|
|
|
|
|
} |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
=head3 errmsg |
794
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
my $string = $cldr->errmsg(); |
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
Stores the last error message. Especially useful if the on_error behavior of the |
798
|
|
|
|
|
|
|
object is 'undef', so you can work out why things went wrong. |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
=cut |
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
sub errmsg { |
803
|
1
|
|
|
1
|
1
|
1422
|
return $_[0]->{errmsg}; |
804
|
|
|
|
|
|
|
} |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
|
807
|
|
|
|
|
|
|
=head2 Exportable functions |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
There are no methods exported by default, however the following are available: |
810
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
=head3 cldr_format |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
use DateTime::Format::CLDR qw(cldr_format); |
814
|
|
|
|
|
|
|
&cldr_format($pattern,$datetime); |
815
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
=cut |
817
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
sub cldr_format { |
819
|
1
|
|
|
1
|
1
|
747
|
my ($pattern, $datetime) = @_; |
820
|
|
|
|
|
|
|
|
821
|
1
|
|
|
|
|
6
|
return $datetime->format_cldr($pattern); |
822
|
|
|
|
|
|
|
} |
823
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
=head3 cldr_parse |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
use DateTime::Format::CLDR qw(cldr_parse); |
827
|
|
|
|
|
|
|
&cldr_parse($pattern,$string); |
828
|
|
|
|
|
|
|
OR |
829
|
|
|
|
|
|
|
&cldr_parse($pattern,$string,$locale); |
830
|
|
|
|
|
|
|
|
831
|
|
|
|
|
|
|
Default locale is 'en'. |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
=cut |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
sub cldr_parse { |
836
|
1
|
|
|
1
|
1
|
1275
|
my ($pattern, $string, $locale) = @_; |
837
|
|
|
|
|
|
|
|
838
|
1
|
|
50
|
|
|
5
|
$locale ||= 'en'; |
839
|
1
|
|
|
|
|
11
|
return DateTime::Format::CLDR->new( |
840
|
|
|
|
|
|
|
pattern => $pattern, |
841
|
|
|
|
|
|
|
locale => $locale, |
842
|
|
|
|
|
|
|
on_error=>'croak', |
843
|
|
|
|
|
|
|
)->parse_datetime($string); |
844
|
|
|
|
|
|
|
} |
845
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
# --------------------------------------------------------------------------- |
848
|
|
|
|
|
|
|
# Private methods |
849
|
|
|
|
|
|
|
# --------------------------------------------------------------------------- |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
# Parse the pattern and return a data sctructure that can be easily used |
852
|
|
|
|
|
|
|
# by parse_datetime |
853
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
sub _build_pattern { |
855
|
12883
|
|
|
12883
|
|
30243
|
my ($self) = @_; |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
# Return cached pattern |
858
|
|
|
|
|
|
|
return $self->{_built_pattern} |
859
|
12883
|
100
|
|
|
|
55650
|
if defined $self->{_built_pattern}; |
860
|
|
|
|
|
|
|
|
861
|
117
|
|
|
|
|
306
|
$self->{_built_pattern} = []; |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
# Try to parse pattern one element each time |
864
|
117
|
|
|
|
|
800
|
while ($self->{pattern} =~ m/\G |
865
|
|
|
|
|
|
|
(?: |
866
|
|
|
|
|
|
|
'((?:[^']|'')*)' # quote escaped bit of text |
867
|
|
|
|
|
|
|
# it needs to end with one |
868
|
|
|
|
|
|
|
# quote not followed by |
869
|
|
|
|
|
|
|
# another |
870
|
|
|
|
|
|
|
| |
871
|
|
|
|
|
|
|
(([a-zA-Z])\3*) # could be a pattern |
872
|
|
|
|
|
|
|
| |
873
|
|
|
|
|
|
|
(.) # anything else |
874
|
|
|
|
|
|
|
) |
875
|
|
|
|
|
|
|
/sxg) { |
876
|
901
|
|
|
|
|
2498
|
my ($string,$pattern,$rest) = ($1,$2,$4); |
877
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
|
879
|
|
|
|
|
|
|
# Found quoted string |
880
|
901
|
100
|
|
|
|
2455
|
if ($string) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
881
|
10
|
|
|
|
|
29
|
$string =~ s/\'\'/\'/g; |
882
|
10
|
|
|
|
|
22
|
push @{$self->{_built_pattern}}, _quotestring($string); |
|
10
|
|
|
|
|
28
|
|
883
|
|
|
|
|
|
|
|
884
|
|
|
|
|
|
|
# Found pattern |
885
|
|
|
|
|
|
|
} elsif ($pattern) { |
886
|
|
|
|
|
|
|
# Get length and command |
887
|
499
|
|
|
|
|
833
|
my $length = length $pattern; |
888
|
499
|
|
|
|
|
955
|
my $command = substr $pattern,0,1; |
889
|
499
|
|
|
|
|
820
|
my ($rule,$regexp,$index); |
890
|
|
|
|
|
|
|
|
891
|
|
|
|
|
|
|
# Inflate 'j' pattern depending on locale |
892
|
499
|
100
|
|
|
|
1197
|
if ($command eq 'j') { |
893
|
1
|
50
|
|
|
|
5
|
$command = ($self->{locale}->prefers_24_hour_time()) ? 'H':'h'; |
894
|
|
|
|
|
|
|
} |
895
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
# Find most appropriate command |
897
|
499
|
|
|
|
|
1331
|
for (my $count = $length; $count > 0; $count --) { |
898
|
768
|
100
|
|
|
|
2359
|
if (defined $PARSER{$command.$count}) { |
899
|
499
|
|
|
|
|
951
|
$rule = $PARSER{$command.$count}; |
900
|
499
|
|
|
|
|
791
|
$index = $count; |
901
|
499
|
|
|
|
|
783
|
last; |
902
|
|
|
|
|
|
|
} |
903
|
|
|
|
|
|
|
} |
904
|
|
|
|
|
|
|
|
905
|
499
|
50
|
|
|
|
1192
|
return $self->_local_croak("Broken pattern: $command $length") |
906
|
|
|
|
|
|
|
unless $rule; |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
# Pattern definition is regular expression |
909
|
499
|
100
|
|
|
|
1253
|
if (ref $rule eq 'Regexp') { |
|
|
100
|
|
|
|
|
|
910
|
|
|
|
|
|
|
#$regexp = '0*'.$rule; # Match leading zeros |
911
|
428
|
|
|
|
|
720
|
$regexp = $rule; |
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
# Pattern definition is array of possible values |
914
|
|
|
|
|
|
|
} elsif (ref $rule eq 'ARRAY') { |
915
|
|
|
|
|
|
|
|
916
|
22
|
|
|
|
|
72
|
$regexp = _quoteslist($rule); |
917
|
|
|
|
|
|
|
# Try to find matching element (long elements first) |
918
|
|
|
|
|
|
|
|
919
|
|
|
|
|
|
|
# Pattern definition is DateTime::Locale method (returning an array) |
920
|
|
|
|
|
|
|
} else { |
921
|
49
|
|
|
|
|
245
|
$regexp = _quoteslist($self->{locale}->$rule()); |
922
|
|
|
|
|
|
|
} |
923
|
|
|
|
|
|
|
|
924
|
499
|
|
|
|
|
754
|
push @{$self->{_built_pattern}},[$regexp,$command,$index]; |
|
499
|
|
|
|
|
2831
|
|
925
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
#Â Found unqoted string |
927
|
|
|
|
|
|
|
} elsif ($rest) { |
928
|
392
|
|
|
|
|
612
|
push @{$self->{_built_pattern}}, _quotestring($rest); |
|
392
|
|
|
|
|
950
|
|
929
|
|
|
|
|
|
|
} |
930
|
|
|
|
|
|
|
} |
931
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
#use Data::Dumper; |
933
|
|
|
|
|
|
|
#print STDERR Data::Dumper::Dumper($self->{_built_pattern})."\n"; |
934
|
|
|
|
|
|
|
|
935
|
117
|
|
|
|
|
308
|
return $self->{_built_pattern}; |
936
|
|
|
|
|
|
|
} |
937
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
# Turn array into regexp |
939
|
|
|
|
|
|
|
|
940
|
|
|
|
|
|
|
sub _quoteslist { |
941
|
71
|
|
|
71
|
|
305
|
my ($list) = @_; |
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
return |
944
|
|
|
|
|
|
|
'('. |
945
|
|
|
|
|
|
|
(join |
946
|
|
|
|
|
|
|
'|', |
947
|
7437
|
|
|
|
|
12882
|
map { _quotestring($_) } |
948
|
71
|
|
|
|
|
164
|
sort { length $b <=> length $a } @{$list} |
|
37111
|
|
|
|
|
51714
|
|
|
71
|
|
|
|
|
2536
|
|
949
|
|
|
|
|
|
|
). |
950
|
|
|
|
|
|
|
')'; |
951
|
|
|
|
|
|
|
} |
952
|
|
|
|
|
|
|
|
953
|
|
|
|
|
|
|
# Quote regexp |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
sub _quotestring { |
956
|
7839
|
|
|
7839
|
|
12907
|
my ($quote) = @_; |
957
|
7839
|
100
|
|
|
|
16578
|
return $quote |
958
|
|
|
|
|
|
|
if ref($quote) eq 'Regexp'; |
959
|
|
|
|
|
|
|
|
960
|
7830
|
|
|
|
|
21517
|
$quote =~ s/([^[:alnum:][:space:]])/\\$1/g; |
961
|
7830
|
|
|
|
|
14091
|
$quote =~ s/\s+/\\s+/g; |
962
|
7830
|
|
|
|
|
17212
|
return $quote; |
963
|
|
|
|
|
|
|
} |
964
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
# Error |
966
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
sub _local_croak { |
968
|
13
|
|
|
13
|
|
55
|
my ($self,$message) = @_; |
969
|
|
|
|
|
|
|
|
970
|
13
|
|
|
|
|
34
|
$self->{errmsg} = $message; |
971
|
|
|
|
|
|
|
|
972
|
1
|
|
|
|
|
4
|
return &{$self->{on_error}}($self,$message,@_) |
973
|
13
|
100
|
|
|
|
49
|
if ref($self->{on_error}) eq 'CODE'; |
974
|
|
|
|
|
|
|
|
975
|
|
|
|
|
|
|
croak($message) |
976
|
12
|
100
|
|
|
|
307
|
if $self->{on_error} eq 'croak'; |
977
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
return undef |
979
|
4
|
50
|
|
|
|
46
|
if ($self->{on_error} eq 'undef'); |
980
|
|
|
|
|
|
|
|
981
|
0
|
|
|
|
|
0
|
return; |
982
|
|
|
|
|
|
|
} |
983
|
|
|
|
|
|
|
|
984
|
|
|
|
|
|
|
# Warning |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
sub _local_carp { |
987
|
2
|
|
|
2
|
|
6
|
my ($self,$message) = @_; |
988
|
|
|
|
|
|
|
|
989
|
2
|
|
|
|
|
7
|
$self->{errmsg} = $message; |
990
|
|
|
|
|
|
|
|
991
|
0
|
|
|
|
|
0
|
return &{$self->{on_error}}($self,$message,@_) |
992
|
2
|
50
|
|
|
|
6
|
if ref($self->{on_error}) eq 'CODE'; |
993
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
carp($message) |
995
|
2
|
50
|
|
|
|
51
|
if $self->{on_error} eq 'croak'; |
996
|
|
|
|
|
|
|
|
997
|
|
|
|
|
|
|
return undef |
998
|
2
|
50
|
|
|
|
1289
|
if ($self->{on_error} eq 'undef'); |
999
|
|
|
|
|
|
|
|
1000
|
2
|
|
|
|
|
8
|
return; |
1001
|
|
|
|
|
|
|
} |
1002
|
|
|
|
|
|
|
|
1003
|
|
|
|
|
|
|
|
1004
|
|
|
|
|
|
|
|
1005
|
|
|
|
|
|
|
|
1006
|
|
|
|
|
|
|
1; |
1007
|
|
|
|
|
|
|
|
1008
|
|
|
|
|
|
|
=head1 CLDR PATTERNS |
1009
|
|
|
|
|
|
|
|
1010
|
|
|
|
|
|
|
=head2 Parsing |
1011
|
|
|
|
|
|
|
|
1012
|
|
|
|
|
|
|
Some patterns like day of week, quarter, ect. cannot be used to construct |
1013
|
|
|
|
|
|
|
a date. However these patterns can be parsed, and a warning will be |
1014
|
|
|
|
|
|
|
issued if they do not match the parsed date. |
1015
|
|
|
|
|
|
|
|
1016
|
|
|
|
|
|
|
Ambigous patterns (eg. narrow day of week formats for many locales) will |
1017
|
|
|
|
|
|
|
be parsed but ignored in datetime calculation. |
1018
|
|
|
|
|
|
|
|
1019
|
|
|
|
|
|
|
=head2 Supported CLDR Patterns |
1020
|
|
|
|
|
|
|
|
1021
|
|
|
|
|
|
|
See L<DateTime/"CLDR Patterns">. |
1022
|
|
|
|
|
|
|
|
1023
|
|
|
|
|
|
|
CLDR provides the following patterns: |
1024
|
|
|
|
|
|
|
|
1025
|
|
|
|
|
|
|
=over 4 |
1026
|
|
|
|
|
|
|
|
1027
|
|
|
|
|
|
|
=item * G{1,3} |
1028
|
|
|
|
|
|
|
|
1029
|
|
|
|
|
|
|
The abbreviated era (BC, AD). |
1030
|
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
|
=item * GGGG |
1032
|
|
|
|
|
|
|
|
1033
|
|
|
|
|
|
|
The wide era (Before Christ, Anno Domini). |
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
=item * GGGGG |
1036
|
|
|
|
|
|
|
|
1037
|
|
|
|
|
|
|
The narrow era, if it exists (and it mostly doesn't). |
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
Not used to construct a date. |
1040
|
|
|
|
|
|
|
|
1041
|
|
|
|
|
|
|
=item * y and y{3,} |
1042
|
|
|
|
|
|
|
|
1043
|
|
|
|
|
|
|
The year, zero-prefixed as needed. |
1044
|
|
|
|
|
|
|
|
1045
|
|
|
|
|
|
|
=item * yy |
1046
|
|
|
|
|
|
|
|
1047
|
|
|
|
|
|
|
This is a special case. It always produces a two-digit year, so "1976" |
1048
|
|
|
|
|
|
|
becomes "76". |
1049
|
|
|
|
|
|
|
|
1050
|
|
|
|
|
|
|
=item * Y{1,} |
1051
|
|
|
|
|
|
|
|
1052
|
|
|
|
|
|
|
The week of the year, from C<< $dt->week_year() >>. |
1053
|
|
|
|
|
|
|
|
1054
|
|
|
|
|
|
|
=item * u{1,} |
1055
|
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
|
Same as "y" except that "uu" is not a special case. |
1057
|
|
|
|
|
|
|
|
1058
|
|
|
|
|
|
|
=item * Q{1,2} |
1059
|
|
|
|
|
|
|
|
1060
|
|
|
|
|
|
|
The quarter as a number (1..4). |
1061
|
|
|
|
|
|
|
|
1062
|
|
|
|
|
|
|
Not used to construct a date. |
1063
|
|
|
|
|
|
|
|
1064
|
|
|
|
|
|
|
=item * QQQ |
1065
|
|
|
|
|
|
|
|
1066
|
|
|
|
|
|
|
The abbreviated format form for the quarter. |
1067
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
Not used to construct a date. |
1069
|
|
|
|
|
|
|
|
1070
|
|
|
|
|
|
|
=item * QQQQ |
1071
|
|
|
|
|
|
|
|
1072
|
|
|
|
|
|
|
The wide format form for the quarter. |
1073
|
|
|
|
|
|
|
|
1074
|
|
|
|
|
|
|
Not used to construct a date. |
1075
|
|
|
|
|
|
|
|
1076
|
|
|
|
|
|
|
=item * q{1,2} |
1077
|
|
|
|
|
|
|
|
1078
|
|
|
|
|
|
|
The quarter as a number (1..4). |
1079
|
|
|
|
|
|
|
|
1080
|
|
|
|
|
|
|
Not used to construct a date. |
1081
|
|
|
|
|
|
|
|
1082
|
|
|
|
|
|
|
=item * qqq |
1083
|
|
|
|
|
|
|
|
1084
|
|
|
|
|
|
|
The abbreviated stand-alone form for the quarter. |
1085
|
|
|
|
|
|
|
|
1086
|
|
|
|
|
|
|
Not used to construct a date. |
1087
|
|
|
|
|
|
|
|
1088
|
|
|
|
|
|
|
=item * qqqq |
1089
|
|
|
|
|
|
|
|
1090
|
|
|
|
|
|
|
The wide stand-alone form for the quarter. |
1091
|
|
|
|
|
|
|
|
1092
|
|
|
|
|
|
|
Not used to construct a date. |
1093
|
|
|
|
|
|
|
|
1094
|
|
|
|
|
|
|
=item * M{1,2} |
1095
|
|
|
|
|
|
|
|
1096
|
|
|
|
|
|
|
The numerical month. |
1097
|
|
|
|
|
|
|
|
1098
|
|
|
|
|
|
|
=item * MMM |
1099
|
|
|
|
|
|
|
|
1100
|
|
|
|
|
|
|
The abbreviated format form for the month. |
1101
|
|
|
|
|
|
|
|
1102
|
|
|
|
|
|
|
=item * MMMM |
1103
|
|
|
|
|
|
|
|
1104
|
|
|
|
|
|
|
The wide format form for the month. |
1105
|
|
|
|
|
|
|
|
1106
|
|
|
|
|
|
|
=item * MMMMM |
1107
|
|
|
|
|
|
|
|
1108
|
|
|
|
|
|
|
The narrow format form for the month. |
1109
|
|
|
|
|
|
|
|
1110
|
|
|
|
|
|
|
=item * L{1,2} |
1111
|
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
The numerical month. |
1113
|
|
|
|
|
|
|
|
1114
|
|
|
|
|
|
|
=item * LLL |
1115
|
|
|
|
|
|
|
|
1116
|
|
|
|
|
|
|
The abbreviated stand-alone form for the month. |
1117
|
|
|
|
|
|
|
|
1118
|
|
|
|
|
|
|
=item * LLLL |
1119
|
|
|
|
|
|
|
|
1120
|
|
|
|
|
|
|
The wide stand-alone form for the month. |
1121
|
|
|
|
|
|
|
|
1122
|
|
|
|
|
|
|
=item * LLLLL |
1123
|
|
|
|
|
|
|
|
1124
|
|
|
|
|
|
|
The narrow stand-alone form for the month. |
1125
|
|
|
|
|
|
|
|
1126
|
|
|
|
|
|
|
=item * w{1,2} |
1127
|
|
|
|
|
|
|
|
1128
|
|
|
|
|
|
|
The week of the year, from C<< $dt->week_number() >>. |
1129
|
|
|
|
|
|
|
|
1130
|
|
|
|
|
|
|
Not used to construct a date. |
1131
|
|
|
|
|
|
|
|
1132
|
|
|
|
|
|
|
=item * W |
1133
|
|
|
|
|
|
|
|
1134
|
|
|
|
|
|
|
The week of the month, from C<< $dt->week_of_month() >>. |
1135
|
|
|
|
|
|
|
|
1136
|
|
|
|
|
|
|
Not used to construct a date. |
1137
|
|
|
|
|
|
|
|
1138
|
|
|
|
|
|
|
=item * d{1,2} |
1139
|
|
|
|
|
|
|
|
1140
|
|
|
|
|
|
|
The numeric day of of the month. |
1141
|
|
|
|
|
|
|
|
1142
|
|
|
|
|
|
|
=item * D{1,3} |
1143
|
|
|
|
|
|
|
|
1144
|
|
|
|
|
|
|
The numeric day of of the year. |
1145
|
|
|
|
|
|
|
|
1146
|
|
|
|
|
|
|
Not used to construct a date. |
1147
|
|
|
|
|
|
|
|
1148
|
|
|
|
|
|
|
=item * F |
1149
|
|
|
|
|
|
|
|
1150
|
|
|
|
|
|
|
The day of the week in the month, from C<< $dt->weekday_of_month() >>. |
1151
|
|
|
|
|
|
|
|
1152
|
|
|
|
|
|
|
Not used to construct a date. |
1153
|
|
|
|
|
|
|
|
1154
|
|
|
|
|
|
|
=item * g{1,} |
1155
|
|
|
|
|
|
|
|
1156
|
|
|
|
|
|
|
The modified Julian day, from C<< $dt->mjd() >>. |
1157
|
|
|
|
|
|
|
|
1158
|
|
|
|
|
|
|
Not supported by DateTime::Format::CLDR |
1159
|
|
|
|
|
|
|
|
1160
|
|
|
|
|
|
|
=item * E{1,3} |
1161
|
|
|
|
|
|
|
|
1162
|
|
|
|
|
|
|
The abbreviated format form for the day of the week. |
1163
|
|
|
|
|
|
|
|
1164
|
|
|
|
|
|
|
Not used to construct a date. |
1165
|
|
|
|
|
|
|
|
1166
|
|
|
|
|
|
|
=item * EEEE |
1167
|
|
|
|
|
|
|
|
1168
|
|
|
|
|
|
|
The wide format form for the day of the week. |
1169
|
|
|
|
|
|
|
|
1170
|
|
|
|
|
|
|
Not used to construct a date. |
1171
|
|
|
|
|
|
|
|
1172
|
|
|
|
|
|
|
=item * EEEEE |
1173
|
|
|
|
|
|
|
|
1174
|
|
|
|
|
|
|
The narrow format form for the day of the week. |
1175
|
|
|
|
|
|
|
|
1176
|
|
|
|
|
|
|
Not used to construct a date. |
1177
|
|
|
|
|
|
|
|
1178
|
|
|
|
|
|
|
=item * e{1,2} |
1179
|
|
|
|
|
|
|
|
1180
|
|
|
|
|
|
|
The I<local> day of the week, from 1 to 7. This number depends on what |
1181
|
|
|
|
|
|
|
day is considered the first day of the week, which varies by |
1182
|
|
|
|
|
|
|
locale. For example, in the US, Sunday is the first day of the week, |
1183
|
|
|
|
|
|
|
so this returns 2 for Monday. |
1184
|
|
|
|
|
|
|
|
1185
|
|
|
|
|
|
|
Not used to construct a date. |
1186
|
|
|
|
|
|
|
|
1187
|
|
|
|
|
|
|
=item * eee |
1188
|
|
|
|
|
|
|
|
1189
|
|
|
|
|
|
|
The abbreviated format form for the day of the week. |
1190
|
|
|
|
|
|
|
|
1191
|
|
|
|
|
|
|
Not used to construct a date. |
1192
|
|
|
|
|
|
|
|
1193
|
|
|
|
|
|
|
=item * eeee |
1194
|
|
|
|
|
|
|
|
1195
|
|
|
|
|
|
|
The wide format form for the day of the week. |
1196
|
|
|
|
|
|
|
|
1197
|
|
|
|
|
|
|
Not used to construct a date. |
1198
|
|
|
|
|
|
|
|
1199
|
|
|
|
|
|
|
=item * eeeee |
1200
|
|
|
|
|
|
|
|
1201
|
|
|
|
|
|
|
The narrow format form for the day of the week. |
1202
|
|
|
|
|
|
|
|
1203
|
|
|
|
|
|
|
Not used to construct a date. |
1204
|
|
|
|
|
|
|
|
1205
|
|
|
|
|
|
|
=item * c |
1206
|
|
|
|
|
|
|
|
1207
|
|
|
|
|
|
|
The numeric day of the week (not localized). |
1208
|
|
|
|
|
|
|
|
1209
|
|
|
|
|
|
|
Not used to construct a date. |
1210
|
|
|
|
|
|
|
|
1211
|
|
|
|
|
|
|
=item * ccc |
1212
|
|
|
|
|
|
|
|
1213
|
|
|
|
|
|
|
The abbreviated stand-alone form for the day of the week. |
1214
|
|
|
|
|
|
|
|
1215
|
|
|
|
|
|
|
Not used to construct a date. |
1216
|
|
|
|
|
|
|
|
1217
|
|
|
|
|
|
|
=item * cccc |
1218
|
|
|
|
|
|
|
|
1219
|
|
|
|
|
|
|
The wide stand-alone form for the day of the week. |
1220
|
|
|
|
|
|
|
|
1221
|
|
|
|
|
|
|
Not used to construct a date. |
1222
|
|
|
|
|
|
|
|
1223
|
|
|
|
|
|
|
=item * ccccc |
1224
|
|
|
|
|
|
|
|
1225
|
|
|
|
|
|
|
The narrow format form for the day of the week. |
1226
|
|
|
|
|
|
|
|
1227
|
|
|
|
|
|
|
Not used to construct a date. |
1228
|
|
|
|
|
|
|
|
1229
|
|
|
|
|
|
|
=item * a |
1230
|
|
|
|
|
|
|
|
1231
|
|
|
|
|
|
|
The localized form of AM or PM for the time. |
1232
|
|
|
|
|
|
|
|
1233
|
|
|
|
|
|
|
=item * h{1,2} |
1234
|
|
|
|
|
|
|
|
1235
|
|
|
|
|
|
|
The hour from 1-12. |
1236
|
|
|
|
|
|
|
|
1237
|
|
|
|
|
|
|
=item * H{1,2} |
1238
|
|
|
|
|
|
|
|
1239
|
|
|
|
|
|
|
The hour from 0-23. |
1240
|
|
|
|
|
|
|
|
1241
|
|
|
|
|
|
|
=item * K{1,2} |
1242
|
|
|
|
|
|
|
|
1243
|
|
|
|
|
|
|
The hour from 0-11. |
1244
|
|
|
|
|
|
|
|
1245
|
|
|
|
|
|
|
=item * k{1,2} |
1246
|
|
|
|
|
|
|
|
1247
|
|
|
|
|
|
|
The hour from 1-24. Note that hour 24 is equivalent to midnight on the date |
1248
|
|
|
|
|
|
|
being parsed, not midnight of the next day. |
1249
|
|
|
|
|
|
|
|
1250
|
|
|
|
|
|
|
=item * j{1,2} |
1251
|
|
|
|
|
|
|
|
1252
|
|
|
|
|
|
|
The hour, in 12 or 24 hour form, based on the preferred form for the |
1253
|
|
|
|
|
|
|
locale. In other words, this is equivalent to either "h{1,2}" or |
1254
|
|
|
|
|
|
|
"H{1,2}". |
1255
|
|
|
|
|
|
|
|
1256
|
|
|
|
|
|
|
=item * m{1,2} |
1257
|
|
|
|
|
|
|
|
1258
|
|
|
|
|
|
|
The minute. |
1259
|
|
|
|
|
|
|
|
1260
|
|
|
|
|
|
|
=item * s{1,2} |
1261
|
|
|
|
|
|
|
|
1262
|
|
|
|
|
|
|
The second. |
1263
|
|
|
|
|
|
|
|
1264
|
|
|
|
|
|
|
=item * S{1,} |
1265
|
|
|
|
|
|
|
|
1266
|
|
|
|
|
|
|
The fractional portion of the seconds, rounded based on the length of the |
1267
|
|
|
|
|
|
|
specifier. This returned without a leading decimal point, but may have |
1268
|
|
|
|
|
|
|
leading or trailing zeroes. |
1269
|
|
|
|
|
|
|
|
1270
|
|
|
|
|
|
|
=item * A{1,} |
1271
|
|
|
|
|
|
|
|
1272
|
|
|
|
|
|
|
The millisecond of the day, based on the current time. In other words, if it |
1273
|
|
|
|
|
|
|
is 12:00:00.00, this returns 43200000. |
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
Not supported by DateTime::Format::CLDR |
1276
|
|
|
|
|
|
|
|
1277
|
|
|
|
|
|
|
=item * z{1,3} |
1278
|
|
|
|
|
|
|
|
1279
|
|
|
|
|
|
|
The time zone short name. |
1280
|
|
|
|
|
|
|
|
1281
|
|
|
|
|
|
|
=item * zzzz |
1282
|
|
|
|
|
|
|
|
1283
|
|
|
|
|
|
|
The time zone long name. |
1284
|
|
|
|
|
|
|
|
1285
|
|
|
|
|
|
|
=item * Z{1,3} |
1286
|
|
|
|
|
|
|
|
1287
|
|
|
|
|
|
|
The time zone offset. |
1288
|
|
|
|
|
|
|
|
1289
|
|
|
|
|
|
|
=item * ZZZZ |
1290
|
|
|
|
|
|
|
|
1291
|
|
|
|
|
|
|
The time zone short name and the offset as one string, so something like |
1292
|
|
|
|
|
|
|
"CDT-0500". |
1293
|
|
|
|
|
|
|
|
1294
|
|
|
|
|
|
|
=item * v{1,3} |
1295
|
|
|
|
|
|
|
|
1296
|
|
|
|
|
|
|
The time zone short name. |
1297
|
|
|
|
|
|
|
|
1298
|
|
|
|
|
|
|
=item * vvvv |
1299
|
|
|
|
|
|
|
|
1300
|
|
|
|
|
|
|
The time zone long name. |
1301
|
|
|
|
|
|
|
|
1302
|
|
|
|
|
|
|
=item * V{1,3} |
1303
|
|
|
|
|
|
|
|
1304
|
|
|
|
|
|
|
The time zone short name. |
1305
|
|
|
|
|
|
|
|
1306
|
|
|
|
|
|
|
=item * VVVV |
1307
|
|
|
|
|
|
|
|
1308
|
|
|
|
|
|
|
The time zone long name. |
1309
|
|
|
|
|
|
|
|
1310
|
|
|
|
|
|
|
=back |
1311
|
|
|
|
|
|
|
|
1312
|
|
|
|
|
|
|
=head1 CAVEATS |
1313
|
|
|
|
|
|
|
|
1314
|
|
|
|
|
|
|
Patterns without separators (like 'dMy' or 'yMd') are ambigous for some |
1315
|
|
|
|
|
|
|
dates and might fail. |
1316
|
|
|
|
|
|
|
|
1317
|
|
|
|
|
|
|
Quote from the Author of C<DateTime::Format::Strptime> which also applies to |
1318
|
|
|
|
|
|
|
this module: |
1319
|
|
|
|
|
|
|
|
1320
|
|
|
|
|
|
|
"If your module uses this module to parse a known format: stop it. This module |
1321
|
|
|
|
|
|
|
is clunky and slow because it can parse almost anything. Parsing a known |
1322
|
|
|
|
|
|
|
format is not so difficult, is it? You'll make your module faster if you do. |
1323
|
|
|
|
|
|
|
And you're not left at the whim of my potentially broken code." |
1324
|
|
|
|
|
|
|
|
1325
|
|
|
|
|
|
|
=head1 SUPPORT |
1326
|
|
|
|
|
|
|
|
1327
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
1328
|
|
|
|
|
|
|
C<datetime-format-cldr@rt.cpan.org>, or through the web interface at |
1329
|
|
|
|
|
|
|
L<http://rt.cpan.org/Public/Bug/Report.html?Queue=DateTime::Format::CLDR>. |
1330
|
|
|
|
|
|
|
I will be notified and then you'll automatically be notified of the progress |
1331
|
|
|
|
|
|
|
on your report as I make changes. |
1332
|
|
|
|
|
|
|
|
1333
|
|
|
|
|
|
|
=head1 SEE ALSO |
1334
|
|
|
|
|
|
|
|
1335
|
|
|
|
|
|
|
datetime@perl.org mailing list |
1336
|
|
|
|
|
|
|
|
1337
|
|
|
|
|
|
|
L<http://datetime.perl.org/> |
1338
|
|
|
|
|
|
|
|
1339
|
|
|
|
|
|
|
L<DateTime>, L<DateTime::Locale>, L<DateTime::TimeZone> |
1340
|
|
|
|
|
|
|
and L<DateTime::Format::Strptime> |
1341
|
|
|
|
|
|
|
|
1342
|
|
|
|
|
|
|
=head1 AUTHOR |
1343
|
|
|
|
|
|
|
|
1344
|
|
|
|
|
|
|
Maroš Kollár |
1345
|
|
|
|
|
|
|
CPAN ID: MAROS |
1346
|
|
|
|
|
|
|
maros [at] k-1.com |
1347
|
|
|
|
|
|
|
|
1348
|
|
|
|
|
|
|
http://www.k-1.com |
1349
|
|
|
|
|
|
|
|
1350
|
|
|
|
|
|
|
=head1 COPYRIGHT |
1351
|
|
|
|
|
|
|
|
1352
|
|
|
|
|
|
|
DateTime::Format::CLDR is Copyright (c) 2008-2012 Maroš Kollár |
1353
|
|
|
|
|
|
|
- L<http://www.k-1.com> |
1354
|
|
|
|
|
|
|
|
1355
|
|
|
|
|
|
|
=head1 LICENCE |
1356
|
|
|
|
|
|
|
|
1357
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify |
1358
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
1359
|
|
|
|
|
|
|
|
1360
|
|
|
|
|
|
|
=cut |