line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::ParseDate; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.000; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
54267
|
use Carp; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
395
|
|
6
|
4
|
|
|
4
|
|
1790
|
use Time::Timezone; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
272
|
|
7
|
4
|
|
|
4
|
|
1783
|
use Time::JulianDay; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
487
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
@EXPORT = qw(parsedate); |
11
|
|
|
|
|
|
|
@EXPORT_OK = qw(pd_raw %mtable %umult %wdays); |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
39
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
134
|
|
14
|
|
|
|
|
|
|
#use diagnostics; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# constants |
17
|
4
|
|
|
4
|
|
19
|
use vars qw(%mtable %umult %wdays $VERSION); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
288
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$VERSION = 2013.1113; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# globals |
22
|
4
|
|
|
4
|
|
18
|
use vars qw($debug); |
|
4
|
|
|
|
|
80
|
|
|
4
|
|
|
|
|
163
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# dynamically-scoped |
25
|
4
|
|
|
4
|
|
21
|
use vars qw($parse); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
24085
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my %mtable; |
28
|
|
|
|
|
|
|
my %umult; |
29
|
|
|
|
|
|
|
my %wdays; |
30
|
|
|
|
|
|
|
my $y2k; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
CONFIG: { |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
%mtable = qw( |
35
|
|
|
|
|
|
|
Jan 1 Jan. 1 January 1 |
36
|
|
|
|
|
|
|
Feb 2 Feb. 2 February 2 |
37
|
|
|
|
|
|
|
Mar 3 Mar. 3 March 3 |
38
|
|
|
|
|
|
|
Apr 4 Apr. 4 April 4 |
39
|
|
|
|
|
|
|
May 5 |
40
|
|
|
|
|
|
|
Jun 6 Jun. 6 June 6 |
41
|
|
|
|
|
|
|
Jul 7 Jul. 7 July 7 |
42
|
|
|
|
|
|
|
Aug 8 Aug. 8 August 8 |
43
|
|
|
|
|
|
|
Sep 9 Sep. 9 September 9 Sept 9 |
44
|
|
|
|
|
|
|
Oct 10 Oct. 10 October 10 |
45
|
|
|
|
|
|
|
Nov 11 Nov. 11 November 11 |
46
|
|
|
|
|
|
|
Dec 12 Dec. 12 December 12 ); |
47
|
|
|
|
|
|
|
%umult = qw( |
48
|
|
|
|
|
|
|
sec 1 second 1 |
49
|
|
|
|
|
|
|
min 60 minute 60 |
50
|
|
|
|
|
|
|
hour 3600 |
51
|
|
|
|
|
|
|
day 86400 |
52
|
|
|
|
|
|
|
week 604800 |
53
|
|
|
|
|
|
|
fortnight 1209600); |
54
|
|
|
|
|
|
|
%wdays = qw( |
55
|
|
|
|
|
|
|
sun 0 sunday 0 |
56
|
|
|
|
|
|
|
mon 1 monday 1 |
57
|
|
|
|
|
|
|
tue 2 tuesday 2 |
58
|
|
|
|
|
|
|
wed 3 wednesday 3 |
59
|
|
|
|
|
|
|
thu 4 thursday 4 |
60
|
|
|
|
|
|
|
fri 5 friday 5 |
61
|
|
|
|
|
|
|
sat 6 saturday 6 |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$y2k = 946684800; # turn of the century |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $break = qr{(?:\s+|\Z|\b(?![-:.,/]\d))}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub parsedate |
70
|
|
|
|
|
|
|
{ |
71
|
287
|
|
|
287
|
0
|
8612
|
my ($t, %options) = @_; |
72
|
|
|
|
|
|
|
|
73
|
287
|
|
|
|
|
321
|
my ($y, $m, $d); # year, month - 1..12, day |
74
|
0
|
|
|
|
|
0
|
my ($H, $M, $S); # hour, minute, second |
75
|
0
|
|
|
|
|
0
|
my $tz; # timezone |
76
|
0
|
|
|
|
|
0
|
my $tzo; # timezone offset |
77
|
0
|
|
|
|
|
0
|
my ($rd, $rs); # relative days, relative seconds |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
my $rel; # time&|date is relative |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
my $isspec; |
82
|
287
|
100
|
|
|
|
626
|
my $now = defined($options{NOW}) ? $options{NOW} : time; |
83
|
287
|
|
|
|
|
316
|
my $passes = 0; |
84
|
287
|
100
|
|
|
|
521
|
my $uk = defined($options{UK}) ? $options{UK} : 0; |
85
|
|
|
|
|
|
|
|
86
|
287
|
|
|
|
|
387
|
local $parse = ''; # will be dynamically scoped. |
87
|
|
|
|
|
|
|
|
88
|
287
|
100
|
|
|
|
2643
|
if ($t =~ s#^ ([ \d]\d) |
|
|
100
|
|
|
|
|
|
89
|
|
|
|
|
|
|
/ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) |
90
|
|
|
|
|
|
|
/ (\d\d\d\d) |
91
|
|
|
|
|
|
|
: (\d\d) |
92
|
|
|
|
|
|
|
: (\d\d) |
93
|
|
|
|
|
|
|
: (\d\d) |
94
|
|
|
|
|
|
|
(?: |
95
|
|
|
|
|
|
|
[ ] |
96
|
|
|
|
|
|
|
([-+] \d\d\d\d) |
97
|
|
|
|
|
|
|
(?: \("?(?:(?:[A-Z]{1,4}[TCW56])|IDLE)\))? |
98
|
|
|
|
|
|
|
)? |
99
|
|
|
|
|
|
|
$break |
100
|
|
|
|
|
|
|
##xi) { #"emacs |
101
|
|
|
|
|
|
|
# [ \d]/Mon/yyyy:hh:mm:ss [-+]\d\d\d\d |
102
|
|
|
|
|
|
|
# This is the format for www server logging. |
103
|
|
|
|
|
|
|
|
104
|
9
|
100
|
50
|
|
|
76
|
($d, $m, $y, $H, $M, $S, $tzo) = ($1, $mtable{"\u\L$2"}, $3, $4, $5, $6, $7 ? &mkoff($7) : ($tzo || undef)); |
105
|
9
|
50
|
|
|
|
28
|
$parse .= " ".__LINE__ if $debug; |
106
|
|
|
|
|
|
|
} elsif ($t =~ s#^(\d\d)/(\d\d)/(\d\d)\.(\d\d)\:(\d\d)($break)##) { |
107
|
|
|
|
|
|
|
# yy/mm/dd.hh:mm |
108
|
|
|
|
|
|
|
# I support this format because it's used by wbak/rbak |
109
|
|
|
|
|
|
|
# on Apollo Domain OS. Silly, but historical. |
110
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
5
|
($y, $m, $d, $H, $M, $S) = ($1, $2, $3, $4, $5, 0); |
112
|
1
|
50
|
|
|
|
4
|
$parse .= " ".__LINE__ if $debug; |
113
|
|
|
|
|
|
|
} else { |
114
|
277
|
|
|
|
|
317
|
while(1) { |
115
|
818
|
100
|
66
|
|
|
3612
|
if (! defined $m and ! defined $rd and ! defined $y |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
33
|
|
|
|
|
116
|
|
|
|
|
|
|
and ! ($passes == 0 and $options{'TIMEFIRST'})) |
117
|
|
|
|
|
|
|
{ |
118
|
|
|
|
|
|
|
# no month defined. |
119
|
315
|
100
|
|
|
|
871
|
if (&parse_date_only(\$t, \$y, \$m, \$d, $uk)) { |
120
|
195
|
50
|
|
|
|
380
|
$parse .= " ".__LINE__ if $debug; |
121
|
195
|
|
|
|
|
253
|
next; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
623
|
100
|
66
|
|
|
1720
|
if (! defined $H and ! defined $rs) { |
125
|
322
|
100
|
|
|
|
945
|
if (&parse_time_only(\$t, \$H, \$M, \$S, |
126
|
|
|
|
|
|
|
\$tz, %options)) |
127
|
|
|
|
|
|
|
{ |
128
|
155
|
50
|
|
|
|
280
|
$parse .= " ".__LINE__ if $debug; |
129
|
155
|
|
|
|
|
204
|
next; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
468
|
50
|
66
|
|
|
1363
|
next if $passes == 0 and $options{'TIMEFIRST'}; |
133
|
468
|
100
|
|
|
|
909
|
if (! defined $y) { |
134
|
246
|
100
|
|
|
|
651
|
if (&parse_year_only(\$t, \$y, $now, %options)) { |
135
|
31
|
50
|
|
|
|
90
|
$parse .= " ".__LINE__ if $debug; |
136
|
31
|
|
|
|
|
38
|
next; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
437
|
100
|
100
|
|
|
2823
|
if (! defined $tz and ! defined $tzo and ! defined $rs |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
140
|
|
|
|
|
|
|
and (defined $m or defined $H)) |
141
|
|
|
|
|
|
|
{ |
142
|
197
|
100
|
|
|
|
416
|
if (&parse_tz_only(\$t, \$tz, \$tzo)) { |
143
|
63
|
50
|
|
|
|
115
|
$parse .= " ".__LINE__ if $debug; |
144
|
63
|
|
|
|
|
76
|
next; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
374
|
100
|
66
|
|
|
1019
|
if (! defined $H and ! defined $rs) { |
148
|
167
|
100
|
|
|
|
569
|
if (&parse_time_offset(\$t, \$rs, %options)) { |
149
|
38
|
|
|
|
|
46
|
$rel = 1; |
150
|
38
|
50
|
|
|
|
89
|
$parse .= " ".__LINE__ if $debug; |
151
|
38
|
|
|
|
|
43
|
next; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
336
|
50
|
66
|
|
|
962
|
if (! defined $m and ! defined $rd and ! defined $y) { |
|
|
|
66
|
|
|
|
|
155
|
82
|
100
|
|
|
|
271
|
if (&parse_date_offset(\$t, $now, \$y, |
156
|
|
|
|
|
|
|
\$m, \$d, \$rd, \$rs, %options)) |
157
|
|
|
|
|
|
|
{ |
158
|
57
|
|
|
|
|
71
|
$rel = 1; |
159
|
57
|
50
|
|
|
|
106
|
$parse .= " ".__LINE__ if $debug; |
160
|
57
|
|
|
|
|
75
|
next; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
279
|
100
|
100
|
|
|
933
|
if (defined $M or defined $rd) { |
164
|
199
|
100
|
|
|
|
895
|
if ($t =~ s/^\s*(?:at|\@|\+)($break)//x) { |
165
|
2
|
|
|
|
|
3
|
$rel = 1; |
166
|
2
|
50
|
|
|
|
6
|
$parse .= " ".__LINE__ if $debug; |
167
|
2
|
|
|
|
|
3
|
next; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
277
|
|
|
|
|
349
|
last; |
171
|
|
|
|
|
|
|
} continue { |
172
|
541
|
|
|
|
|
582
|
$passes++; |
173
|
541
|
50
|
|
|
|
1386
|
&debug_display($tz, $tzo, $H, $M, $S, $m, $d, $y, $rs, $rd, $rel, $passes, $parse, $t) if $debug; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
277
|
100
|
|
|
|
796
|
if ($passes == 0) { |
178
|
3
|
50
|
|
|
|
9
|
print "nothing matched\n" if $debug; |
179
|
3
|
50
|
|
|
|
9
|
return (undef, "no match on time/date") |
180
|
|
|
|
|
|
|
if wantarray(); |
181
|
3
|
|
|
|
|
11
|
return undef; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
284
|
50
|
|
|
|
550
|
&debug_display($tz, $tzo, $H, $M, $S, $m, $d, $y, $rs, $rd, $rel, $passes, $parse, $t) if $debug; |
186
|
|
|
|
|
|
|
|
187
|
284
|
|
|
|
|
481
|
$t =~ s/^\s+//; |
188
|
|
|
|
|
|
|
|
189
|
284
|
100
|
|
|
|
572
|
if ($t ne '') { |
190
|
|
|
|
|
|
|
# we didn't manage to eat the string |
191
|
15
|
50
|
|
|
|
36
|
print "NOT WHOLE\n" if $debug; |
192
|
15
|
100
|
|
|
|
35
|
if ($options{WHOLE}) { |
193
|
2
|
50
|
|
|
|
6
|
return (undef, "characters left over after parse") |
194
|
|
|
|
|
|
|
if wantarray(); |
195
|
|
|
|
|
|
|
return undef |
196
|
2
|
|
|
|
|
8
|
} |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# define a date if there isn't one already |
200
|
|
|
|
|
|
|
|
201
|
282
|
100
|
66
|
|
|
719
|
if (! defined $y and ! defined $m and ! defined $rd) { |
|
|
|
66
|
|
|
|
|
202
|
22
|
50
|
|
|
|
49
|
print "no date defined, trying to find one." if $debug; |
203
|
22
|
50
|
66
|
|
|
69
|
if (defined $rs or defined $H) { |
204
|
|
|
|
|
|
|
# we do have a time. |
205
|
22
|
50
|
|
|
|
54
|
if ($options{DATE_REQUIRED}) { |
206
|
0
|
0
|
|
|
|
0
|
return (undef, "no date specified") |
207
|
|
|
|
|
|
|
if wantarray(); |
208
|
0
|
|
|
|
|
0
|
return undef; |
209
|
|
|
|
|
|
|
} |
210
|
22
|
100
|
|
|
|
46
|
if (defined $rs) { |
211
|
17
|
50
|
|
|
|
40
|
print "simple offset: $rs\n" if $debug; |
212
|
17
|
|
|
|
|
25
|
my $rv = $now + $rs; |
213
|
17
|
50
|
|
|
|
36
|
return ($rv, $t) if wantarray(); |
214
|
17
|
|
|
|
|
74
|
return $rv; |
215
|
|
|
|
|
|
|
} |
216
|
5
|
|
|
|
|
10
|
$rd = 0; |
217
|
|
|
|
|
|
|
} else { |
218
|
0
|
0
|
|
|
|
0
|
print "no time either!\n" if $debug; |
219
|
0
|
0
|
|
|
|
0
|
return (undef, "no time specified") |
220
|
|
|
|
|
|
|
if wantarray(); |
221
|
0
|
|
|
|
|
0
|
return undef; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
265
|
50
|
66
|
|
|
725
|
if ($options{TIME_REQUIRED} && ! defined($rs) |
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
226
|
|
|
|
|
|
|
&& ! defined($H) && ! defined($rd)) |
227
|
|
|
|
|
|
|
{ |
228
|
0
|
0
|
|
|
|
0
|
return (undef, "no time found") |
229
|
|
|
|
|
|
|
if wantarray(); |
230
|
0
|
|
|
|
|
0
|
return undef; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
265
|
|
|
|
|
286
|
my $secs; |
234
|
|
|
|
|
|
|
my $jd; |
235
|
|
|
|
|
|
|
|
236
|
265
|
100
|
|
|
|
473
|
if (defined $rd) { |
237
|
49
|
100
|
66
|
|
|
282
|
if (defined $rs || ! (defined($H) || defined($M) || defined($S))) { |
|
|
|
100
|
|
|
|
|
238
|
42
|
50
|
|
|
|
80
|
print "fully relative\n" if $debug; |
239
|
42
|
|
|
|
|
40
|
my ($j, $in, $it); |
240
|
42
|
100
|
|
|
|
69
|
my $definedrs = defined($rs) ? $rs : 0; |
241
|
42
|
|
|
|
|
45
|
my ($isdst_now, $isdst_then); |
242
|
42
|
|
|
|
|
59
|
my $r = $now + $rd * 86400 + $definedrs; |
243
|
|
|
|
|
|
|
# |
244
|
|
|
|
|
|
|
# It's possible that there was a timezone shift |
245
|
|
|
|
|
|
|
# during the time specified. If so, keep the |
246
|
|
|
|
|
|
|
# hours the "same". |
247
|
|
|
|
|
|
|
# |
248
|
42
|
|
|
|
|
154
|
$isdst_now = (localtime($r))[8]; |
249
|
42
|
|
|
|
|
126
|
$isdst_then = (localtime($now))[8]; |
250
|
42
|
100
|
66
|
|
|
158
|
if (($isdst_now == $isdst_then) || $options{GMT}) |
251
|
|
|
|
|
|
|
{ |
252
|
28
|
50
|
|
|
|
57
|
return ($r, $t) if wantarray(); |
253
|
28
|
|
|
|
|
179
|
return $r |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
14
|
50
|
|
|
|
38
|
print "localtime changed DST during time period!\n" if $debug; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
21
|
50
|
|
|
|
50
|
print "relative date\n" if $debug; |
260
|
21
|
100
|
|
|
|
121
|
$jd = $options{GMT} |
261
|
|
|
|
|
|
|
? gm_julian_day($now) |
262
|
|
|
|
|
|
|
: local_julian_day($now); |
263
|
21
|
50
|
|
|
|
49
|
print "jd($now) = $jd\n" if $debug; |
264
|
21
|
|
|
|
|
37
|
$jd += $rd; |
265
|
|
|
|
|
|
|
} else { |
266
|
216
|
100
|
|
|
|
463
|
unless (defined $y) { |
267
|
19
|
100
|
|
|
|
49
|
if ($options{PREFER_PAST}) { |
|
|
100
|
|
|
|
|
|
268
|
4
|
|
|
|
|
6
|
my ($day, $mon011); |
269
|
4
|
|
|
|
|
11
|
($day, $mon011, $y) = (&righttime($now))[3,4,5]; |
270
|
|
|
|
|
|
|
|
271
|
4
|
50
|
|
|
|
43
|
print "calc year -past $day-$d $mon011-$m $y\n" if $debug; |
272
|
4
|
100
|
100
|
|
|
31
|
$y -= 1 if ($mon011+1 < $m) || |
|
|
|
66
|
|
|
|
|
273
|
|
|
|
|
|
|
(($mon011+1 == $m) && ($day < $d)); |
274
|
|
|
|
|
|
|
} elsif ($options{PREFER_FUTURE}) { |
275
|
3
|
50
|
|
|
|
9
|
print "calc year -future\n" if $debug; |
276
|
3
|
|
|
|
|
4
|
my ($day, $mon011); |
277
|
3
|
|
|
|
|
7
|
($day, $mon011, $y) = (&righttime($now))[3,4,5]; |
278
|
3
|
100
|
33
|
|
|
20
|
$y += 1 if ($mon011 >= $m) || |
|
|
|
66
|
|
|
|
|
279
|
|
|
|
|
|
|
(($mon011+1 == $m) && ($day > $d)); |
280
|
|
|
|
|
|
|
} else { |
281
|
12
|
50
|
|
|
|
61
|
print "calc year -this\n" if $debug; |
282
|
12
|
|
|
|
|
44
|
$y = (localtime($now))[5]; |
283
|
|
|
|
|
|
|
} |
284
|
19
|
|
|
|
|
29
|
$y += 1900; |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
216
|
100
|
|
|
|
583
|
$y = expand_two_digit_year($y, $now, %options) |
288
|
|
|
|
|
|
|
if $y < 100; |
289
|
|
|
|
|
|
|
|
290
|
216
|
100
|
|
|
|
459
|
if ($options{VALIDATE}) { |
291
|
6
|
|
|
|
|
60
|
require Time::DaysInMonth; |
292
|
6
|
|
|
|
|
27
|
my $dim = Time::DaysInMonth::days_in($y, $m); |
293
|
6
|
100
|
33
|
|
|
93
|
if ($y < 1000 or $m < 1 or $d < 1 |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
294
|
|
|
|
|
|
|
or $y > 9999 or $m > 12 or $d > $dim) |
295
|
|
|
|
|
|
|
{ |
296
|
2
|
50
|
|
|
|
7
|
return (undef, "illegal YMD: $y, $m, $d") |
297
|
|
|
|
|
|
|
if wantarray(); |
298
|
2
|
|
|
|
|
9
|
return undef; |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
} |
301
|
214
|
|
|
|
|
619
|
$jd = julian_day($y, $m, $d); |
302
|
214
|
50
|
|
|
|
514
|
print "jd($y, $m, $d) = $jd\n" if $debug; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
# put time into HMS |
306
|
|
|
|
|
|
|
|
307
|
235
|
100
|
|
|
|
495
|
if (! defined($H)) { |
308
|
72
|
100
|
100
|
|
|
270
|
if (defined($rd) || defined($rs)) { |
309
|
28
|
|
|
|
|
79
|
($S, $M, $H) = &righttime($now, %options); |
310
|
28
|
50
|
|
|
|
87
|
print "HMS set to $H $M $S\n" if $debug; |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
} |
313
|
|
|
|
|
|
|
|
314
|
235
|
|
|
|
|
256
|
my $carry; |
315
|
|
|
|
|
|
|
|
316
|
235
|
0
|
|
|
|
424
|
print "before ", (defined($rs) ? "$rs" : ""), |
|
|
50
|
|
|
|
|
|
317
|
|
|
|
|
|
|
" $jd $H $M $S\n" |
318
|
|
|
|
|
|
|
if $debug; |
319
|
|
|
|
|
|
|
# |
320
|
|
|
|
|
|
|
# add in relative seconds. Do it this way because we want to |
321
|
|
|
|
|
|
|
# preserve the localtime across DST changes. |
322
|
|
|
|
|
|
|
# |
323
|
|
|
|
|
|
|
|
324
|
235
|
100
|
|
|
|
438
|
$S = 0 unless $S; # -w |
325
|
235
|
100
|
|
|
|
409
|
$M = 0 unless $M; # -w |
326
|
235
|
100
|
|
|
|
404
|
$H = 0 unless $H; # -w |
327
|
|
|
|
|
|
|
|
328
|
235
|
100
|
100
|
|
|
559
|
if ($options{VALIDATE} and |
|
|
|
66
|
|
|
|
|
329
|
|
|
|
|
|
|
($S < 0 or $M < 0 or $H < 0 or $S > 59 or $M > 59 or $H > 23)) |
330
|
|
|
|
|
|
|
{ |
331
|
2
|
50
|
|
|
|
6
|
return (undef, "illegal HMS: $H, $M, $S") if wantarray(); |
332
|
2
|
|
|
|
|
10
|
return undef; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
233
|
100
|
|
|
|
422
|
$S += $rs if defined $rs; |
336
|
233
|
|
100
|
|
|
707
|
$carry = int($S / 60) - ($S < 0 && $S % 60 && 1); |
337
|
233
|
|
|
|
|
285
|
$S -= $carry * 60; |
338
|
233
|
|
|
|
|
262
|
$M += $carry; |
339
|
233
|
|
100
|
|
|
622
|
$carry = int($M / 60) - ($M < 0 && $M % 60 && 1); |
340
|
233
|
|
|
|
|
254
|
$M %= 60; |
341
|
233
|
|
|
|
|
234
|
$H += $carry; |
342
|
233
|
|
50
|
|
|
601
|
$carry = int($H / 24) - ($H < 0 && $H % 24 && 1); |
343
|
233
|
|
|
|
|
261
|
$H %= 24; |
344
|
233
|
|
|
|
|
225
|
$jd += $carry; |
345
|
|
|
|
|
|
|
|
346
|
233
|
50
|
|
|
|
507
|
print "after rs $jd $H $M $S\n" if $debug; |
347
|
|
|
|
|
|
|
|
348
|
233
|
|
|
|
|
696
|
$secs = jd_secondsgm($jd, $H, $M, $S); |
349
|
233
|
50
|
|
|
|
499
|
print "jd_secondsgm($jd, $H, $M, $S) = $secs\n" if $debug; |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
# |
352
|
|
|
|
|
|
|
# If we see something link 3pm CST then and we want to end |
353
|
|
|
|
|
|
|
# up with a GMT seconds, then we convert the 3pm to GMT and |
354
|
|
|
|
|
|
|
# subtract in the offset for CST. We subtract because we |
355
|
|
|
|
|
|
|
# are converting from CST to GMT. |
356
|
|
|
|
|
|
|
# |
357
|
233
|
|
|
|
|
239
|
my $tzadj; |
358
|
233
|
100
|
|
|
|
499
|
if ($tz) { |
|
|
100
|
|
|
|
|
|
359
|
43
|
|
|
|
|
130
|
$tzadj = tz_offset($tz, $secs); |
360
|
43
|
50
|
|
|
|
84
|
if (defined $tzadj) { |
361
|
43
|
50
|
|
|
|
83
|
print "adjusting secs for $tz: $tzadj\n" if $debug; |
362
|
43
|
|
|
|
|
125
|
$tzadj = tz_offset($tz, $secs-$tzadj); |
363
|
43
|
|
|
|
|
67
|
$secs -= $tzadj; |
364
|
|
|
|
|
|
|
} else { |
365
|
0
|
0
|
|
|
|
0
|
print "unknown timezone: $tz\n" if $debug; |
366
|
0
|
|
|
|
|
0
|
undef $secs; |
367
|
0
|
|
|
|
|
0
|
undef $t; |
368
|
|
|
|
|
|
|
} |
369
|
|
|
|
|
|
|
} elsif (defined $tzo) { |
370
|
27
|
50
|
|
|
|
61
|
print "adjusting time for offset: $tzo\n" if $debug; |
371
|
27
|
|
|
|
|
67
|
$secs -= $tzo; |
372
|
|
|
|
|
|
|
} else { |
373
|
163
|
100
|
|
|
|
348
|
unless ($options{GMT}) { |
374
|
160
|
100
|
|
|
|
284
|
if ($options{ZONE}) { |
375
|
38
|
|
100
|
|
|
132
|
$tzadj = tz_offset($options{ZONE}, $secs) || 0; |
376
|
38
|
|
|
|
|
130
|
$tzadj = tz_offset($options{ZONE}, $secs-$tzadj); |
377
|
38
|
50
|
|
|
|
93
|
unless (defined($tzadj)) { |
378
|
0
|
0
|
|
|
|
0
|
return (undef, "could not convert '$options{ZONE}' to time offset") |
379
|
|
|
|
|
|
|
if wantarray(); |
380
|
0
|
|
|
|
|
0
|
return undef; |
381
|
|
|
|
|
|
|
} |
382
|
38
|
50
|
|
|
|
78
|
print "adjusting secs for $options{ZONE}: $tzadj\n" if $debug; |
383
|
38
|
|
|
|
|
63
|
$secs -= $tzadj; |
384
|
|
|
|
|
|
|
} else { |
385
|
122
|
|
|
|
|
370
|
$tzadj = tz_local_offset($secs); |
386
|
122
|
50
|
|
|
|
286
|
print "adjusting secs for local offset: $tzadj\n" if $debug; |
387
|
|
|
|
|
|
|
# |
388
|
|
|
|
|
|
|
# Just in case we are very close to a time |
389
|
|
|
|
|
|
|
# change... |
390
|
|
|
|
|
|
|
# |
391
|
122
|
|
|
|
|
354
|
$tzadj = tz_local_offset($secs-$tzadj); |
392
|
122
|
|
|
|
|
202
|
$secs -= $tzadj; |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
} |
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
|
397
|
233
|
50
|
|
|
|
488
|
print "returning $secs.\n" if $debug; |
398
|
|
|
|
|
|
|
|
399
|
233
|
100
|
|
|
|
448
|
return ($secs, $t) if wantarray(); |
400
|
232
|
|
|
|
|
1011
|
return $secs; |
401
|
|
|
|
|
|
|
} |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
sub mkoff |
405
|
|
|
|
|
|
|
{ |
406
|
28
|
|
|
28
|
0
|
43
|
my($offset) = @_; |
407
|
|
|
|
|
|
|
|
408
|
28
|
50
|
33
|
|
|
202
|
if (defined $offset and $offset =~ s#^([-+])(\d\d):?(\d\d)$##) { |
409
|
28
|
100
|
|
|
|
163
|
return ($1 eq '+' ? |
410
|
|
|
|
|
|
|
3600 * $2 + 60 * $3 |
411
|
|
|
|
|
|
|
: -3600 * $2 + -60 * $3 ); |
412
|
|
|
|
|
|
|
} |
413
|
0
|
|
|
|
|
0
|
return undef; |
414
|
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
sub parse_tz_only |
417
|
|
|
|
|
|
|
{ |
418
|
197
|
|
|
197
|
0
|
279
|
my($tr, $tz, $tzo) = @_; |
419
|
|
|
|
|
|
|
|
420
|
197
|
|
|
|
|
341
|
$$tr =~ s#^\s+##; |
421
|
197
|
|
|
|
|
193
|
my $o; |
422
|
|
|
|
|
|
|
|
423
|
197
|
100
|
|
|
|
2587
|
if ($$tr =~ s#^ |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
424
|
|
|
|
|
|
|
([-+]\d\d:?\d\d) |
425
|
|
|
|
|
|
|
\s+ |
426
|
|
|
|
|
|
|
\( |
427
|
|
|
|
|
|
|
"? |
428
|
|
|
|
|
|
|
(?: |
429
|
|
|
|
|
|
|
(?: |
430
|
|
|
|
|
|
|
[A-Z]{1,4}[TCW56] |
431
|
|
|
|
|
|
|
) |
432
|
|
|
|
|
|
|
| |
433
|
|
|
|
|
|
|
IDLE |
434
|
|
|
|
|
|
|
) |
435
|
|
|
|
|
|
|
\) |
436
|
|
|
|
|
|
|
$break |
437
|
|
|
|
|
|
|
##x) { #"emacs |
438
|
4
|
|
|
|
|
10
|
$$tzo = &mkoff($1); |
439
|
4
|
50
|
|
|
|
12
|
printf "matched at %d.\n", __LINE__ if $debug; |
440
|
4
|
|
|
|
|
14
|
return 1; |
441
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^GMT\s*([-+]\d{1,2})($break)##x) { |
442
|
6
|
|
|
|
|
13
|
$o = $1; |
443
|
6
|
50
|
33
|
|
|
30
|
if ($o < 24 and $o !~ /^0/) { |
444
|
|
|
|
|
|
|
# probably hours. |
445
|
6
|
50
|
|
|
|
14
|
printf "adjusted at %d. ($o 00)\n", __LINE__ if $debug; |
446
|
6
|
|
|
|
|
7
|
$o = "${o}00"; |
447
|
|
|
|
|
|
|
} |
448
|
6
|
|
|
|
|
62
|
$o =~ s/\b(\d\d\d)/0$1/; |
449
|
6
|
|
|
|
|
13
|
$$tzo = &mkoff($o); |
450
|
6
|
50
|
|
|
|
14
|
printf "matched at %d. ($$tzo, $o)\n", __LINE__ if $debug; |
451
|
6
|
|
|
|
|
19
|
return 1; |
452
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?:GMT\s*)?([-+]\d\d:?\d\d)($break)##x) { |
453
|
13
|
|
|
|
|
24
|
$o = $1; |
454
|
13
|
|
|
|
|
29
|
$$tzo = &mkoff($o); |
455
|
13
|
50
|
|
|
|
34
|
printf "matched at %d.\n", __LINE__ if $debug; |
456
|
13
|
|
|
|
|
42
|
return 1; |
457
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^"?((?:[A-Z]{1,4}[TCW56])|IDLE)$break##x) { #" |
458
|
40
|
|
|
|
|
73
|
$$tz = $1; |
459
|
40
|
100
|
66
|
|
|
202
|
$$tz .= " DST" |
460
|
|
|
|
|
|
|
if $$tz eq 'MET' && $$tr =~ s#^DST$break##x; |
461
|
40
|
50
|
|
|
|
86
|
printf "matched at %d: '$$tz'.\n", __LINE__ if $debug; |
462
|
40
|
|
|
|
|
138
|
return 1; |
463
|
|
|
|
|
|
|
} |
464
|
134
|
|
|
|
|
480
|
return 0; |
465
|
|
|
|
|
|
|
} |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
sub parse_date_only |
468
|
|
|
|
|
|
|
{ |
469
|
315
|
|
|
315
|
0
|
457
|
my ($tr, $yr, $mr, $dr, $uk) = @_; |
470
|
|
|
|
|
|
|
|
471
|
315
|
|
|
|
|
673
|
$$tr =~ s#^\s+##; |
472
|
|
|
|
|
|
|
|
473
|
315
|
100
|
|
|
|
9560
|
if ($$tr =~ s#^(\d\d\d\d)([-./])(\d\d?)\2(\d\d?)(T|$break)##) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
474
|
|
|
|
|
|
|
# yyyy/mm/dd |
475
|
|
|
|
|
|
|
|
476
|
39
|
|
|
|
|
184
|
($$yr, $$mr, $$dr) = ($1, $3, $4); |
477
|
39
|
50
|
|
|
|
98
|
printf "matched at %d.\n", __LINE__ if $debug; |
478
|
39
|
|
|
|
|
144
|
return 1; |
479
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(\d\d?)([-./])(\d\d?)\2(\d\d\d\d?)($break)##) { |
480
|
|
|
|
|
|
|
# mm/dd/yyyy - is this safe? No. |
481
|
|
|
|
|
|
|
# -- or dd/mm/yyyy! If $1>12, then it's unambiguous. |
482
|
|
|
|
|
|
|
# Otherwise check option UK for UK style date. |
483
|
15
|
100
|
100
|
|
|
84
|
if ($uk || $1>12) { |
484
|
8
|
|
|
|
|
34
|
($$yr, $$mr, $$dr) = ($4, $3, $1); |
485
|
|
|
|
|
|
|
} else { |
486
|
7
|
|
|
|
|
31
|
($$yr, $$mr, $$dr) = ($4, $1, $3); |
487
|
|
|
|
|
|
|
} |
488
|
15
|
50
|
|
|
|
42
|
printf "matched at %d.\n", __LINE__ if $debug; |
489
|
15
|
|
|
|
|
49
|
return 1; |
490
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(\d\d\d\d)/(\d\d?)$break##x) { |
491
|
|
|
|
|
|
|
# yyyy/mm |
492
|
|
|
|
|
|
|
|
493
|
1
|
|
|
|
|
5
|
($$yr, $$mr, $$dr) = ($1, $2, 1); |
494
|
1
|
50
|
|
|
|
4
|
printf "matched at %d.\n", __LINE__ if $debug; |
495
|
1
|
|
|
|
|
5
|
return 1; |
496
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?xi) |
497
|
|
|
|
|
|
|
(?: |
498
|
|
|
|
|
|
|
(?:Mon|Monday|Tue|Tuesday|Wed|Wednesday| |
499
|
|
|
|
|
|
|
Thu|Thursday|Fri|Friday| |
500
|
|
|
|
|
|
|
Sat|Saturday|Sun|Sunday),? |
501
|
|
|
|
|
|
|
\s+ |
502
|
|
|
|
|
|
|
)? |
503
|
|
|
|
|
|
|
(\d\d?) |
504
|
|
|
|
|
|
|
(\s+ | - | \. | /) |
505
|
|
|
|
|
|
|
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\.? |
506
|
|
|
|
|
|
|
(?: |
507
|
|
|
|
|
|
|
\2 |
508
|
|
|
|
|
|
|
(\d\d (?:\d\d)? ) |
509
|
|
|
|
|
|
|
)? |
510
|
|
|
|
|
|
|
$break |
511
|
|
|
|
|
|
|
##) { |
512
|
|
|
|
|
|
|
# [Dow,] dd Mon [yy[yy]] |
513
|
26
|
|
|
|
|
142
|
($$yr, $$mr, $$dr) = ($4, $mtable{"\u\L$3"}, $1); |
514
|
|
|
|
|
|
|
|
515
|
26
|
50
|
|
|
|
67
|
printf "%d: %s - %s - %s\n", __LINE__, $1, $2, $3 if $debug; |
516
|
26
|
50
|
33
|
|
|
65
|
print "y undef\n" if ($debug && ! defined($$yr)); |
517
|
26
|
|
|
|
|
107
|
return 1; |
518
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?xi) |
519
|
|
|
|
|
|
|
(?: |
520
|
|
|
|
|
|
|
(?:Mon|Monday|Tue|Tuesday|Wed|Wednesday| |
521
|
|
|
|
|
|
|
Thu|Thursday|Fri|Friday| |
522
|
|
|
|
|
|
|
Sat|Saturday|Sun|Sunday),? |
523
|
|
|
|
|
|
|
\s+ |
524
|
|
|
|
|
|
|
)? |
525
|
|
|
|
|
|
|
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\.? |
526
|
|
|
|
|
|
|
((\s)+ | - | \. | /) |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
(\d\d?) |
529
|
|
|
|
|
|
|
,? |
530
|
|
|
|
|
|
|
(?: |
531
|
|
|
|
|
|
|
(?: \2|\3+) |
532
|
|
|
|
|
|
|
(\d\d (?: \d\d)?) |
533
|
|
|
|
|
|
|
)? |
534
|
|
|
|
|
|
|
$break |
535
|
|
|
|
|
|
|
##) { |
536
|
|
|
|
|
|
|
# [Dow,] Mon dd [yyyy] |
537
|
|
|
|
|
|
|
# [Dow,] Mon d, [yy] |
538
|
44
|
|
|
|
|
235
|
($$yr, $$mr, $$dr) = ($5, $mtable{"\u\L$1"}, $4); |
539
|
44
|
50
|
|
|
|
108
|
printf "%d: %s - %s - %s\n", __LINE__, $1, $2, $4 if $debug; |
540
|
44
|
50
|
33
|
|
|
106
|
print "y undef\n" if ($debug && ! defined($$yr)); |
541
|
44
|
|
|
|
|
163
|
return 1; |
542
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?xi) |
543
|
|
|
|
|
|
|
(January|Jan\.?|February|Feb\.?|March|Mar\.?|April|Apr\.?|May| |
544
|
|
|
|
|
|
|
June|Jun\.?|July|Jul\.?|August|Aug\.?|September|Sep\.?| |
545
|
|
|
|
|
|
|
October|Oct\.?|November|Nov\.?|December|Dec\.?) |
546
|
|
|
|
|
|
|
\s+ |
547
|
|
|
|
|
|
|
(\d+) |
548
|
|
|
|
|
|
|
(?:st|nd|rd|th)? |
549
|
|
|
|
|
|
|
\,? |
550
|
|
|
|
|
|
|
(?: |
551
|
|
|
|
|
|
|
\s+ |
552
|
|
|
|
|
|
|
(?: |
553
|
|
|
|
|
|
|
(\d\d\d\d) |
554
|
|
|
|
|
|
|
|(?:\' (\d\d)) |
555
|
|
|
|
|
|
|
) |
556
|
|
|
|
|
|
|
)? |
557
|
|
|
|
|
|
|
$break |
558
|
|
|
|
|
|
|
##) { |
559
|
|
|
|
|
|
|
# Month day{st,nd,rd,th}, 'yy |
560
|
|
|
|
|
|
|
# Month day{st,nd,rd,th}, year |
561
|
|
|
|
|
|
|
# Month day, year |
562
|
|
|
|
|
|
|
# Mon. day, year |
563
|
9
|
|
66
|
|
|
71
|
($$yr, $$mr, $$dr) = ($3 || $4, $mtable{"\u\L$1"}, $2); |
564
|
9
|
50
|
|
|
|
25
|
printf "%d: %s - %s - %s - %s\n", __LINE__, $1, $2, $3, $4 if $debug; |
565
|
9
|
50
|
33
|
|
|
26
|
print "y undef\n" if ($debug && ! defined($$yr)); |
566
|
9
|
50
|
|
|
|
19
|
printf "matched at %d.\n", __LINE__ if $debug; |
567
|
9
|
|
|
|
|
37
|
return 1; |
568
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(\d\d?)([-/.])(\d\d?)\2(\d\d?)($break)##x) { |
569
|
46
|
100
|
100
|
|
|
373
|
if ($1 > 31 || (!$uk && $1 > 12 && $4 < 32)) { |
|
|
100
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
570
|
|
|
|
|
|
|
# yy/mm/dd |
571
|
17
|
|
|
|
|
68
|
($$yr, $$mr, $$dr) = ($1, $3, $4); |
572
|
|
|
|
|
|
|
} elsif ($1 > 12 || $uk) { |
573
|
|
|
|
|
|
|
# dd/mm/yy |
574
|
4
|
|
|
|
|
18
|
($$yr, $$mr, $$dr) = ($4, $3, $1); |
575
|
|
|
|
|
|
|
} else { |
576
|
|
|
|
|
|
|
# mm/dd/yy |
577
|
25
|
|
|
|
|
98
|
($$yr, $$mr, $$dr) = ($4, $1, $3); |
578
|
|
|
|
|
|
|
} |
579
|
46
|
50
|
|
|
|
108
|
printf "matched at %d.\n", __LINE__ if $debug; |
580
|
46
|
|
|
|
|
182
|
return 1; |
581
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(\d\d?)/(\d\d?)($break)##x) { |
582
|
5
|
100
|
33
|
|
|
61
|
if ($1 > 31 || (!$uk && $1 > 12)) { |
|
|
100
|
66
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
583
|
|
|
|
|
|
|
# yy/mm |
584
|
1
|
|
|
|
|
4
|
($$yr, $$mr, $$dr) = ($1, $2, 1); |
585
|
|
|
|
|
|
|
} elsif ($2 > 31 || ($uk && $2 > 12)) { |
586
|
|
|
|
|
|
|
# mm/yy |
587
|
1
|
|
|
|
|
4
|
($$yr, $$mr, $$dr) = ($2, $1, 1); |
588
|
|
|
|
|
|
|
} elsif ($1 > 12 || $uk) { |
589
|
|
|
|
|
|
|
# dd/mm |
590
|
0
|
|
|
|
|
0
|
($$mr, $$dr) = ($2, $1); |
591
|
|
|
|
|
|
|
} else { |
592
|
|
|
|
|
|
|
# mm/dd |
593
|
3
|
|
|
|
|
11
|
($$mr, $$dr) = ($1, $2); |
594
|
|
|
|
|
|
|
} |
595
|
5
|
50
|
|
|
|
13
|
printf "matched at %d.\n", __LINE__ if $debug; |
596
|
5
|
|
|
|
|
18
|
return 1; |
597
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(\d\d)(\d\d)(\d\d)($break)##x) { |
598
|
8
|
100
|
33
|
|
|
41
|
if ($1 > 31 || (!$uk && $1 > 12)) { |
|
|
50
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
599
|
|
|
|
|
|
|
# YYMMDD |
600
|
7
|
|
|
|
|
36
|
($$yr, $$mr, $$dr) = ($1, $2, $3); |
601
|
|
|
|
|
|
|
} elsif ($1 > 12 || $uk) { |
602
|
|
|
|
|
|
|
# DDMMYY |
603
|
0
|
|
|
|
|
0
|
($$yr, $$mr, $$dr) = ($3, $2, $1); |
604
|
|
|
|
|
|
|
} else { |
605
|
|
|
|
|
|
|
# MMDDYY |
606
|
1
|
|
|
|
|
4
|
($$yr, $$mr, $$dr) = ($3, $1, $2); |
607
|
|
|
|
|
|
|
} |
608
|
8
|
50
|
|
|
|
25
|
printf "matched at %d.\n", __LINE__ if $debug; |
609
|
8
|
|
|
|
|
35
|
return 1; |
610
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?xi) |
611
|
|
|
|
|
|
|
(\d{1,2}) |
612
|
|
|
|
|
|
|
(\s+ | - | \. | /) |
613
|
|
|
|
|
|
|
(January|Jan\.?|February|Feb\.?|March|Mar\.?|April|Apr\.?|May| |
614
|
|
|
|
|
|
|
June|Jun\.?|July|Jul\.?|August|Aug\.?|September|Sep\.?| |
615
|
|
|
|
|
|
|
October|Oct\.?|November|Nov\.?|December|Dec\.?) |
616
|
|
|
|
|
|
|
(?: |
617
|
|
|
|
|
|
|
\2 |
618
|
|
|
|
|
|
|
( |
619
|
|
|
|
|
|
|
\d\d |
620
|
|
|
|
|
|
|
(?:\d\d)? |
621
|
|
|
|
|
|
|
) |
622
|
|
|
|
|
|
|
) |
623
|
|
|
|
|
|
|
$break |
624
|
|
|
|
|
|
|
##) { |
625
|
|
|
|
|
|
|
# dd Month [yr] |
626
|
1
|
|
|
|
|
8
|
($$yr, $$mr, $$dr) = ($4, $mtable{"\u\L$3"}, $1); |
627
|
1
|
50
|
|
|
|
4
|
printf "matched at %d.\n", __LINE__ if $debug; |
628
|
1
|
|
|
|
|
5
|
return 1; |
629
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?xi) |
630
|
|
|
|
|
|
|
(\d+) |
631
|
|
|
|
|
|
|
(?:st|nd|rd|th)? |
632
|
|
|
|
|
|
|
\s+ |
633
|
|
|
|
|
|
|
(January|Jan\.?|February|Feb\.?|March|Mar\.?|April|Apr\.?|May| |
634
|
|
|
|
|
|
|
June|Jun\.?|July|Jul\.?|August|Aug\.?|September|Sep\.?| |
635
|
|
|
|
|
|
|
October|Oct\.?|November|Nov\.?|December|Dec\.?) |
636
|
|
|
|
|
|
|
(?: |
637
|
|
|
|
|
|
|
\,? |
638
|
|
|
|
|
|
|
\s+ |
639
|
|
|
|
|
|
|
(\d\d\d\d) |
640
|
|
|
|
|
|
|
)? |
641
|
|
|
|
|
|
|
$break |
642
|
|
|
|
|
|
|
##) { |
643
|
|
|
|
|
|
|
# day{st,nd,rd,th}, Month year |
644
|
1
|
|
|
|
|
7
|
($$yr, $$mr, $$dr) = ($3, $mtable{"\u\L$2"}, $1); |
645
|
1
|
50
|
|
|
|
5
|
printf "%d: %s - %s - %s - %s\n", __LINE__, $1, $2, $3, $4 if $debug; |
646
|
1
|
50
|
33
|
|
|
5
|
print "y undef\n" if ($debug && ! defined($$yr)); |
647
|
1
|
50
|
|
|
|
4
|
printf "matched at %d.\n", __LINE__ if $debug; |
648
|
1
|
|
|
|
|
5
|
return 1; |
649
|
|
|
|
|
|
|
} |
650
|
120
|
|
|
|
|
604
|
return 0; |
651
|
|
|
|
|
|
|
} |
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
sub parse_time_only |
654
|
|
|
|
|
|
|
{ |
655
|
322
|
|
|
322
|
0
|
746
|
my ($tr, $hr, $mr, $sr, $tzr, %options) = @_; |
656
|
|
|
|
|
|
|
|
657
|
322
|
|
|
|
|
634
|
$$tr =~ s#^\s+##; |
658
|
|
|
|
|
|
|
|
659
|
322
|
100
|
|
|
|
3469
|
if ($$tr =~ s!^(?x) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
660
|
|
|
|
|
|
|
(?: |
661
|
|
|
|
|
|
|
(?: |
662
|
|
|
|
|
|
|
([012]\d) (?# $1) |
663
|
|
|
|
|
|
|
(?: |
664
|
|
|
|
|
|
|
([0-5]\d) (?# $2) |
665
|
|
|
|
|
|
|
(?: |
666
|
|
|
|
|
|
|
([0-5]\d) (?# $3) |
667
|
|
|
|
|
|
|
)? |
668
|
|
|
|
|
|
|
) |
669
|
|
|
|
|
|
|
\s* |
670
|
|
|
|
|
|
|
([apAP][mM])? (?# $4) |
671
|
|
|
|
|
|
|
) | (?: |
672
|
|
|
|
|
|
|
(\d{1,2}) (?# $5) |
673
|
|
|
|
|
|
|
(?: |
674
|
|
|
|
|
|
|
\: |
675
|
|
|
|
|
|
|
(\d\d) (?# $6) |
676
|
|
|
|
|
|
|
(?: |
677
|
|
|
|
|
|
|
\: |
678
|
|
|
|
|
|
|
(\d\d) (?# $7) |
679
|
|
|
|
|
|
|
( |
680
|
|
|
|
|
|
|
(?# don't barf on database sub-second timings) |
681
|
|
|
|
|
|
|
[:.,] |
682
|
|
|
|
|
|
|
\d+ |
683
|
|
|
|
|
|
|
)? (?# $8) |
684
|
|
|
|
|
|
|
)? |
685
|
|
|
|
|
|
|
) |
686
|
|
|
|
|
|
|
\s* |
687
|
|
|
|
|
|
|
([apAP][mM])? (?# $9) |
688
|
|
|
|
|
|
|
) | (?: |
689
|
|
|
|
|
|
|
(\d{1,2}) (?# $10) |
690
|
|
|
|
|
|
|
([apAP][mM]) (?# ${11}) |
691
|
|
|
|
|
|
|
) |
692
|
|
|
|
|
|
|
) |
693
|
|
|
|
|
|
|
(?: |
694
|
|
|
|
|
|
|
\s+ |
695
|
|
|
|
|
|
|
"? |
696
|
|
|
|
|
|
|
( (?# ${12}) |
697
|
|
|
|
|
|
|
(?: [A-Z]{1,4}[TCW56] ) |
698
|
|
|
|
|
|
|
| |
699
|
|
|
|
|
|
|
IDLE |
700
|
|
|
|
|
|
|
) |
701
|
|
|
|
|
|
|
)? |
702
|
|
|
|
|
|
|
$break |
703
|
|
|
|
|
|
|
!!) { #"emacs |
704
|
|
|
|
|
|
|
# HH[[:]MM[:SS]]meridian [zone] |
705
|
151
|
|
|
|
|
163
|
my $ampm; |
706
|
151
|
|
100
|
|
|
797
|
$$hr = $1 || $5 || $10 || 0; # 10 is undef, but 5 is defined.. |
707
|
151
|
|
100
|
|
|
644
|
$$mr = $2 || $6 || 0; |
708
|
151
|
|
100
|
|
|
638
|
$$sr = $3 || $7 || 0; |
709
|
151
|
100
|
100
|
|
|
484
|
if (defined($8) && exists($options{SUBSECOND}) && $options{SUBSECOND}) { |
|
|
|
66
|
|
|
|
|
710
|
7
|
|
|
|
|
18
|
my($frac) = $8; |
711
|
7
|
|
|
|
|
16
|
substr($frac,0,1) = '.'; |
712
|
7
|
|
|
|
|
25
|
$$sr += $frac; |
713
|
|
|
|
|
|
|
} |
714
|
151
|
50
|
|
|
|
282
|
print "S = $$sr\n" if $debug; |
715
|
151
|
|
100
|
|
|
895
|
$ampm = $4 || $9 || $11 || ''; |
716
|
151
|
|
|
|
|
198
|
$$tzr = $12; |
717
|
151
|
100
|
100
|
|
|
426
|
$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12; |
|
|
|
66
|
|
|
|
|
718
|
151
|
100
|
100
|
|
|
427
|
$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM"; |
719
|
151
|
50
|
|
|
|
287
|
printf "matched at %d, rem = %s.\n", __LINE__, $$tr if $debug; |
720
|
151
|
|
|
|
|
604
|
return 1; |
721
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^noon$break##ix) { |
722
|
|
|
|
|
|
|
# noon |
723
|
2
|
|
|
|
|
5
|
($$hr, $$mr, $$sr) = (12, 0, 0); |
724
|
2
|
50
|
|
|
|
7
|
printf "matched at %d.\n", __LINE__ if $debug; |
725
|
2
|
|
|
|
|
8
|
return 1; |
726
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^midnight$break##ix) { |
727
|
|
|
|
|
|
|
# midnight |
728
|
2
|
|
|
|
|
6
|
($$hr, $$mr, $$sr) = (0, 0, 0); |
729
|
2
|
50
|
|
|
|
6
|
printf "matched at %d.\n", __LINE__ if $debug; |
730
|
2
|
|
|
|
|
7
|
return 1; |
731
|
|
|
|
|
|
|
} |
732
|
167
|
|
|
|
|
672
|
return 0; |
733
|
|
|
|
|
|
|
} |
734
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
sub parse_time_offset |
736
|
|
|
|
|
|
|
{ |
737
|
167
|
|
|
167
|
0
|
379
|
my ($tr, $rsr, %options) = @_; |
738
|
|
|
|
|
|
|
|
739
|
167
|
|
|
|
|
274
|
$$tr =~ s/^\s+//; |
740
|
|
|
|
|
|
|
|
741
|
167
|
50
|
|
|
|
397
|
return 0 if $options{NO_RELATIVE}; |
742
|
|
|
|
|
|
|
|
743
|
167
|
100
|
|
|
|
1386
|
if ($$tr =~ s{^(?xi) |
744
|
|
|
|
|
|
|
(?: |
745
|
|
|
|
|
|
|
(-) (?# 1) |
746
|
|
|
|
|
|
|
| |
747
|
|
|
|
|
|
|
[+] |
748
|
|
|
|
|
|
|
)? |
749
|
|
|
|
|
|
|
\s* |
750
|
|
|
|
|
|
|
(?: |
751
|
|
|
|
|
|
|
(\d+(?:\.\d+)?) (?# 2) |
752
|
|
|
|
|
|
|
| |
753
|
|
|
|
|
|
|
(?:(\d+)\s+(\d+)/(\d+)) (?# 3 4/5) |
754
|
|
|
|
|
|
|
) |
755
|
|
|
|
|
|
|
\s* |
756
|
|
|
|
|
|
|
(sec|second|min|minute|hour)s? (?# 6) |
757
|
|
|
|
|
|
|
( |
758
|
|
|
|
|
|
|
\s+ |
759
|
|
|
|
|
|
|
ago (?# 7) |
760
|
|
|
|
|
|
|
)? |
761
|
|
|
|
|
|
|
$break |
762
|
|
|
|
|
|
|
}{}) { |
763
|
|
|
|
|
|
|
# count units |
764
|
38
|
50
|
|
|
|
94
|
$$rsr = 0 unless defined $$rsr; |
765
|
38
|
50
|
66
|
|
|
120
|
return 0 if defined($5) && $5 == 0; |
766
|
38
|
100
|
|
|
|
109
|
my $num = defined($2) |
767
|
|
|
|
|
|
|
? $2 |
768
|
|
|
|
|
|
|
: $3 + $4/$5; |
769
|
38
|
100
|
|
|
|
101
|
$num = -$num if $1; |
770
|
38
|
|
|
|
|
178
|
$$rsr += $umult{"\L$6"} * $num; |
771
|
|
|
|
|
|
|
|
772
|
38
|
100
|
100
|
|
|
185
|
$$rsr = -$$rsr if $7 || |
773
|
|
|
|
|
|
|
$$tr =~ /\b(day|mon|month|year)s?\s*ago\b/; |
774
|
38
|
50
|
|
|
|
75
|
printf "matched at %d.\n", __LINE__ if $debug; |
775
|
38
|
|
|
|
|
141
|
return 1; |
776
|
|
|
|
|
|
|
} |
777
|
129
|
|
|
|
|
444
|
return 0; |
778
|
|
|
|
|
|
|
} |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
# |
781
|
|
|
|
|
|
|
# What to you do with a date that has a two-digit year? |
782
|
|
|
|
|
|
|
# There's not much that can be done except make a guess. |
783
|
|
|
|
|
|
|
# |
784
|
|
|
|
|
|
|
# Some example situations to handle: |
785
|
|
|
|
|
|
|
# |
786
|
|
|
|
|
|
|
# now year |
787
|
|
|
|
|
|
|
# |
788
|
|
|
|
|
|
|
# 1999 01 |
789
|
|
|
|
|
|
|
# 1999 71 |
790
|
|
|
|
|
|
|
# 2010 71 |
791
|
|
|
|
|
|
|
# 2110 09 |
792
|
|
|
|
|
|
|
# |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
sub expand_two_digit_year |
795
|
|
|
|
|
|
|
{ |
796
|
65
|
|
|
65
|
0
|
188
|
my ($yr, $now, %options) = @_; |
797
|
|
|
|
|
|
|
|
798
|
65
|
50
|
|
|
|
128
|
return $yr if $yr > 100; |
799
|
|
|
|
|
|
|
|
800
|
65
|
|
|
|
|
161
|
my ($y) = (&righttime($now, %options))[5]; |
801
|
65
|
|
|
|
|
117
|
$y += 1900; |
802
|
65
|
|
|
|
|
109
|
my $century = int($y / 100) * 100; |
803
|
65
|
|
|
|
|
89
|
my $within = $y % 100; |
804
|
|
|
|
|
|
|
|
805
|
65
|
|
|
|
|
78
|
my $r = $yr + $century; |
806
|
|
|
|
|
|
|
|
807
|
65
|
100
|
|
|
|
199
|
if ($options{PREFER_PAST}) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
808
|
3
|
100
|
|
|
|
10
|
if ($yr > $within) { |
809
|
2
|
|
|
|
|
6
|
$r = $yr + $century - 100; |
810
|
|
|
|
|
|
|
} |
811
|
|
|
|
|
|
|
} elsif ($options{PREFER_FUTURE}) { |
812
|
|
|
|
|
|
|
# being strict here would be silly |
813
|
3
|
100
|
|
|
|
11
|
if ($yr < $within-20) { |
814
|
|
|
|
|
|
|
# it's 2019 and the date is '08' |
815
|
1
|
|
|
|
|
4
|
$r = $yr + $century + 100; |
816
|
|
|
|
|
|
|
} |
817
|
|
|
|
|
|
|
} elsif ($options{UNAMBIGUOUS}) { |
818
|
|
|
|
|
|
|
# we really shouldn't guess |
819
|
0
|
|
|
|
|
0
|
return undef; |
820
|
|
|
|
|
|
|
} else { |
821
|
|
|
|
|
|
|
# prefer the current century in most cases |
822
|
|
|
|
|
|
|
|
823
|
59
|
100
|
100
|
|
|
194
|
if ($within > 80 && $within - $yr > 60) { |
824
|
1
|
|
|
|
|
2
|
$r = $yr + $century + 100; |
825
|
|
|
|
|
|
|
} |
826
|
|
|
|
|
|
|
|
827
|
59
|
100
|
100
|
|
|
222
|
if ($within < 30 && $yr - $within > 59) { |
828
|
35
|
|
|
|
|
51
|
$r = $yr + $century - 100; |
829
|
|
|
|
|
|
|
} |
830
|
|
|
|
|
|
|
} |
831
|
65
|
50
|
|
|
|
141
|
print "two digit year '$yr' expanded into $r\n" if $debug; |
832
|
65
|
|
|
|
|
158
|
return $r; |
833
|
|
|
|
|
|
|
} |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
sub calc |
837
|
|
|
|
|
|
|
{ |
838
|
33
|
|
|
33
|
0
|
116
|
my ($rsr, $yr, $mr, $dr, $rdr, $now, $units, $count, %options) = @_; |
839
|
|
|
|
|
|
|
|
840
|
33
|
50
|
|
|
|
67
|
confess unless $units; |
841
|
33
|
|
|
|
|
49
|
$units = "\L$units"; |
842
|
33
|
50
|
|
|
|
64
|
print "calc based on $units\n" if $debug; |
843
|
|
|
|
|
|
|
|
844
|
33
|
100
|
66
|
|
|
152
|
if ($units eq 'day') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
845
|
17
|
|
|
|
|
22
|
$$rdr = $count; |
846
|
|
|
|
|
|
|
} elsif ($units eq 'week') { |
847
|
3
|
|
|
|
|
2165
|
$$rdr = $count * 7; |
848
|
|
|
|
|
|
|
} elsif ($umult{$units}) { |
849
|
0
|
|
|
|
|
0
|
$$rsr = $count * $umult{$units}; |
850
|
|
|
|
|
|
|
} elsif ($units eq 'mon' || $units eq 'month') { |
851
|
7
|
|
|
|
|
28
|
($$yr, $$mr, $$dr) = &monthoff($now, $count, %options); |
852
|
7
|
100
|
|
|
|
24
|
$$rsr = 0 unless $$rsr; |
853
|
|
|
|
|
|
|
} elsif ($units eq 'year') { |
854
|
6
|
|
|
|
|
23
|
($$yr, $$mr, $$dr) = &monthoff($now, $count * 12, %options); |
855
|
6
|
50
|
|
|
|
21
|
$$rsr = 0 unless $$rsr; |
856
|
|
|
|
|
|
|
} else { |
857
|
0
|
|
|
|
|
0
|
carp "interal error"; |
858
|
|
|
|
|
|
|
} |
859
|
33
|
50
|
|
|
|
115
|
print "calced rsr $$rsr rdr $$rdr, yr $$yr mr $$mr dr $$dr.\n" if $debug; |
860
|
|
|
|
|
|
|
} |
861
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
sub monthoff |
863
|
|
|
|
|
|
|
{ |
864
|
13
|
|
|
13
|
0
|
52
|
my ($now, $months, %options) = @_; |
865
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
# months are 0..11 |
867
|
13
|
|
|
|
|
34
|
my ($d, $m11, $y) = (&righttime($now, %options)) [ 3,4,5 ] ; |
868
|
|
|
|
|
|
|
|
869
|
13
|
|
|
|
|
27
|
$y += 1900; |
870
|
|
|
|
|
|
|
|
871
|
13
|
50
|
|
|
|
30
|
print "m11 = $m11 + $months, y = $y\n" if $debug; |
872
|
|
|
|
|
|
|
|
873
|
13
|
|
|
|
|
15
|
$m11 += $months; |
874
|
|
|
|
|
|
|
|
875
|
13
|
50
|
|
|
|
34
|
print "m11 = $m11, y = $y\n" if $debug; |
876
|
13
|
100
|
100
|
|
|
59
|
if ($m11 > 11 || $m11 < 0) { |
877
|
6
|
100
|
100
|
|
|
41
|
$y -= 1 if $m11 < 0 && ($m11 % 12 != 0); |
878
|
6
|
|
|
|
|
13
|
$y += int($m11/12); |
879
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
# this is required to work around a bug in perl 5.003 |
881
|
4
|
|
|
4
|
|
40
|
no integer; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
29
|
|
882
|
6
|
|
|
|
|
10
|
$m11 %= 12; |
883
|
|
|
|
|
|
|
} |
884
|
13
|
50
|
|
|
|
54
|
print "m11 = $m11, y = $y\n" if $debug; |
885
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
# |
887
|
|
|
|
|
|
|
# What is "1 month from January 31st?" |
888
|
|
|
|
|
|
|
# I think the answer is February 28th most years. |
889
|
|
|
|
|
|
|
# |
890
|
|
|
|
|
|
|
# Similarly, what is one year from February 29th, 1980? |
891
|
|
|
|
|
|
|
# I think it's February 28th, 1981. |
892
|
|
|
|
|
|
|
# |
893
|
|
|
|
|
|
|
# If you disagree, change the following code. |
894
|
|
|
|
|
|
|
# |
895
|
13
|
100
|
33
|
|
|
60
|
if ($d > 30 or ($d > 28 && $m11 == 1)) { |
|
|
|
66
|
|
|
|
|
896
|
4
|
|
|
|
|
1085
|
require Time::DaysInMonth; |
897
|
4
|
|
|
|
|
16
|
my $dim = Time::DaysInMonth::days_in($y, $m11+1); |
898
|
4
|
50
|
|
|
|
12
|
print "dim($y,$m11+1)= $dim\n" if $debug; |
899
|
4
|
100
|
|
|
|
12
|
$d = $dim if $d > $dim; |
900
|
|
|
|
|
|
|
} |
901
|
13
|
|
|
|
|
55
|
return ($y, $m11+1, $d); |
902
|
|
|
|
|
|
|
} |
903
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
sub righttime |
905
|
|
|
|
|
|
|
{ |
906
|
195
|
|
|
195
|
0
|
398
|
my ($time, %options) = @_; |
907
|
195
|
100
|
|
|
|
357
|
if ($options{GMT}) { |
908
|
3
|
|
|
|
|
14
|
return gmtime($time); |
909
|
|
|
|
|
|
|
} else { |
910
|
192
|
|
|
|
|
968
|
return localtime($time); |
911
|
|
|
|
|
|
|
} |
912
|
|
|
|
|
|
|
} |
913
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
sub parse_year_only |
915
|
|
|
|
|
|
|
{ |
916
|
246
|
|
|
246
|
0
|
595
|
my ($tr, $yr, $now, %options) = @_; |
917
|
|
|
|
|
|
|
|
918
|
246
|
|
|
|
|
439
|
$$tr =~ s#^\s+##; |
919
|
|
|
|
|
|
|
|
920
|
246
|
100
|
|
|
|
1528
|
if ($$tr =~ s#^(\d\d\d\d)$break##) { |
|
|
50
|
|
|
|
|
|
921
|
31
|
|
|
|
|
50
|
$$yr = $1; |
922
|
31
|
50
|
|
|
|
57
|
printf "matched at %d.\n", __LINE__ if $debug; |
923
|
31
|
|
|
|
|
101
|
return 1; |
924
|
|
|
|
|
|
|
} elsif ($$tr =~ s#\'(\d\d)$break##) { |
925
|
0
|
|
|
|
|
0
|
$$yr = expand_two_digit_year($1, $now, %options); |
926
|
0
|
0
|
|
|
|
0
|
printf "matched at %d.\n", __LINE__ if $debug; |
927
|
0
|
|
|
|
|
0
|
return 1; |
928
|
|
|
|
|
|
|
} |
929
|
215
|
|
|
|
|
732
|
return 0; |
930
|
|
|
|
|
|
|
} |
931
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
sub parse_date_offset |
933
|
|
|
|
|
|
|
{ |
934
|
82
|
|
|
82
|
0
|
224
|
my ($tr, $now, $yr, $mr, $dr, $rdr, $rsr, %options) = @_; |
935
|
|
|
|
|
|
|
|
936
|
82
|
50
|
|
|
|
190
|
return 0 if $options{NO_RELATIVE}; |
937
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
# now - current seconds_since_epoch |
939
|
|
|
|
|
|
|
# yr - year return |
940
|
|
|
|
|
|
|
# mr - month return |
941
|
|
|
|
|
|
|
# dr - day return |
942
|
|
|
|
|
|
|
# rdr - relative day return |
943
|
|
|
|
|
|
|
# rsr - relative second return |
944
|
|
|
|
|
|
|
|
945
|
82
|
|
|
|
|
83
|
my $j; |
946
|
82
|
|
|
|
|
195
|
my $wday = (&righttime($now, %options))[6]; |
947
|
|
|
|
|
|
|
|
948
|
82
|
|
|
|
|
251
|
$$tr =~ s#^\s+##; |
949
|
|
|
|
|
|
|
|
950
|
82
|
100
|
66
|
|
|
3415
|
if ($$tr =~ s#^(?xi) |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
951
|
|
|
|
|
|
|
\s* |
952
|
|
|
|
|
|
|
(\d+) |
953
|
|
|
|
|
|
|
\s* |
954
|
|
|
|
|
|
|
(day|week|month|year)s? |
955
|
|
|
|
|
|
|
( |
956
|
|
|
|
|
|
|
\s+ |
957
|
|
|
|
|
|
|
ago |
958
|
|
|
|
|
|
|
)? |
959
|
|
|
|
|
|
|
$break |
960
|
|
|
|
|
|
|
##) { |
961
|
10
|
|
|
|
|
30
|
my $amt = $1 + 0; |
962
|
10
|
|
|
|
|
17
|
my $units = $2; |
963
|
10
|
100
|
100
|
|
|
60
|
$amt = -$amt if $3 || |
964
|
|
|
|
|
|
|
$$tr =~ m#\b(sec|second|min|minute|hour)s?\s*ago\b#; |
965
|
10
|
|
|
|
|
33
|
&calc($rsr, $yr, $mr, $dr, $rdr, $now, $units, |
966
|
|
|
|
|
|
|
$amt, %options); |
967
|
10
|
50
|
|
|
|
24
|
printf "matched at %d.\n", __LINE__ if $debug; |
968
|
10
|
|
|
|
|
40
|
return 1; |
969
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?xi) |
970
|
|
|
|
|
|
|
(?: |
971
|
|
|
|
|
|
|
(?: |
972
|
|
|
|
|
|
|
now |
973
|
|
|
|
|
|
|
\s+ |
974
|
|
|
|
|
|
|
)? |
975
|
|
|
|
|
|
|
(\+ | \-) |
976
|
|
|
|
|
|
|
\s* |
977
|
|
|
|
|
|
|
)? |
978
|
|
|
|
|
|
|
(\d+) |
979
|
|
|
|
|
|
|
\s* |
980
|
|
|
|
|
|
|
(day|week|month|year)s? |
981
|
|
|
|
|
|
|
$break |
982
|
|
|
|
|
|
|
##) { |
983
|
16
|
|
50
|
|
|
66
|
my $one = $1 || ''; |
984
|
16
|
|
50
|
|
|
46
|
my $two = $2 || ''; |
985
|
16
|
|
|
|
|
34
|
my $amt = "$one$two"+0; |
986
|
16
|
|
|
|
|
55
|
&calc($rsr, $yr, $mr, $dr, $rdr, $now, $3, |
987
|
|
|
|
|
|
|
$amt, %options); |
988
|
16
|
50
|
|
|
|
36
|
printf "matched at %d.\n", __LINE__ if $debug; |
989
|
16
|
|
|
|
|
66
|
return 1; |
990
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?xi) |
991
|
|
|
|
|
|
|
(Mon|Tue|Wed|Thu|Fri|Sat|Sun|Monday|Tuesday |
992
|
|
|
|
|
|
|
|Wednesday|Thursday|Friday|Saturday|Sunday) |
993
|
|
|
|
|
|
|
\s+ |
994
|
|
|
|
|
|
|
after |
995
|
|
|
|
|
|
|
\s+ |
996
|
|
|
|
|
|
|
next |
997
|
|
|
|
|
|
|
$break |
998
|
|
|
|
|
|
|
##) { |
999
|
|
|
|
|
|
|
# Dow "after next" |
1000
|
1
|
50
|
|
|
|
10
|
$$rdr = $wdays{"\L$1"} - $wday + ( $wdays{"\L$1"} > $wday ? 7 : 14); |
1001
|
1
|
50
|
|
|
|
5
|
printf "matched at %d.\n", __LINE__ if $debug; |
1002
|
1
|
|
|
|
|
6
|
return 1; |
1003
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?xi) |
1004
|
|
|
|
|
|
|
(Mon|Tue|Wed|Thu|Fri|Sat|Sun|Monday|Tuesday |
1005
|
|
|
|
|
|
|
|Wednesday|Thursday|Friday|Saturday|Sunday) |
1006
|
|
|
|
|
|
|
\s+ |
1007
|
|
|
|
|
|
|
before |
1008
|
|
|
|
|
|
|
\s+ |
1009
|
|
|
|
|
|
|
last |
1010
|
|
|
|
|
|
|
$break |
1011
|
|
|
|
|
|
|
##) { |
1012
|
|
|
|
|
|
|
# Dow "before last" |
1013
|
2
|
100
|
|
|
|
14
|
$$rdr = $wdays{"\L$1"} - $wday - ( $wdays{"\L$1"} < $wday ? 7 : 14); |
1014
|
2
|
50
|
|
|
|
6
|
printf "matched at %d.\n", __LINE__ if $debug; |
1015
|
2
|
|
|
|
|
10
|
return 1; |
1016
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?xi) |
1017
|
|
|
|
|
|
|
next\s+ |
1018
|
|
|
|
|
|
|
(Mon|Tue|Wed|Thu|Fri|Sat|Sun|Monday|Tuesday |
1019
|
|
|
|
|
|
|
|Wednesday|Thursday|Friday|Saturday|Sunday) |
1020
|
|
|
|
|
|
|
$break |
1021
|
|
|
|
|
|
|
##) { |
1022
|
|
|
|
|
|
|
# "next" Dow |
1023
|
4
|
100
|
|
|
|
22
|
$$rdr = $wdays{"\L$1"} - $wday |
1024
|
|
|
|
|
|
|
+ ( $wdays{"\L$1"} > $wday ? 0 : 7); |
1025
|
4
|
50
|
|
|
|
12
|
printf "matched at %d.\n", __LINE__ if $debug; |
1026
|
4
|
|
|
|
|
18
|
return 1; |
1027
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^(?xi) |
1028
|
|
|
|
|
|
|
last\s+ |
1029
|
|
|
|
|
|
|
(Mon|Tue|Wed|Thu|Fri|Sat|Sun|Monday|Tuesday |
1030
|
|
|
|
|
|
|
|Wednesday|Thursday|Friday|Saturday|Sunday) |
1031
|
|
|
|
|
|
|
$break##) { |
1032
|
|
|
|
|
|
|
# "last" Dow |
1033
|
3
|
50
|
|
|
|
8
|
printf "c %d - %d + ( %d < %d ? 0 : -7 \n", $wdays{"\L$1"}, $wday, $wdays{"\L$1"}, $wday if $debug; |
1034
|
3
|
100
|
|
|
|
18
|
$$rdr = $wdays{"\L$1"} - $wday + ( $wdays{"\L$1"} < $wday ? 0 : -7); |
1035
|
3
|
50
|
|
|
|
8
|
printf "matched at %d.\n", __LINE__ if $debug; |
1036
|
3
|
|
|
|
|
14
|
return 1; |
1037
|
|
|
|
|
|
|
} elsif ($options{PREFER_PAST} and $$tr =~ s#^(?xi) |
1038
|
|
|
|
|
|
|
(Mon|Tue|Wed|Thu|Fri|Sat|Sun|Monday|Tuesday |
1039
|
|
|
|
|
|
|
|Wednesday|Thursday|Friday|Saturday|Sunday) |
1040
|
|
|
|
|
|
|
$break##) { |
1041
|
|
|
|
|
|
|
# Dow |
1042
|
3
|
50
|
|
|
|
9
|
printf "c %d - %d + ( %d < %d ? 0 : -7 \n", $wdays{"\L$1"}, $wday, $wdays{"\L$1"}, $wday if $debug; |
1043
|
3
|
100
|
|
|
|
18
|
$$rdr = $wdays{"\L$1"} - $wday + ( $wdays{"\L$1"} < $wday ? 0 : -7); |
1044
|
3
|
50
|
|
|
|
7
|
printf "matched at %d.\n", __LINE__ if $debug; |
1045
|
3
|
|
|
|
|
16
|
return 1; |
1046
|
|
|
|
|
|
|
} elsif ($options{PREFER_FUTURE} and $$tr =~ s#^(?xi) |
1047
|
|
|
|
|
|
|
(Mon|Tue|Wed|Thu|Fri|Sat|Sun|Monday|Tuesday |
1048
|
|
|
|
|
|
|
|Wednesday|Thursday|Friday|Saturday|Sunday) |
1049
|
|
|
|
|
|
|
$break |
1050
|
|
|
|
|
|
|
##) { |
1051
|
|
|
|
|
|
|
# Dow |
1052
|
3
|
100
|
|
|
|
19
|
$$rdr = $wdays{"\L$1"} - $wday |
1053
|
|
|
|
|
|
|
+ ( $wdays{"\L$1"} > $wday ? 0 : 7); |
1054
|
3
|
50
|
|
|
|
9
|
printf "matched at %d.\n", __LINE__ if $debug; |
1055
|
3
|
|
|
|
|
14
|
return 1; |
1056
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^today$break##xi) { |
1057
|
|
|
|
|
|
|
# today |
1058
|
1
|
|
|
|
|
2
|
$$rdr = 0; |
1059
|
1
|
50
|
|
|
|
5
|
printf "matched at %d.\n", __LINE__ if $debug; |
1060
|
1
|
|
|
|
|
6
|
return 1; |
1061
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^tomorrow$break##xi) { |
1062
|
1
|
|
|
|
|
2
|
$$rdr = 1; |
1063
|
1
|
50
|
|
|
|
28
|
printf "matched at %d.\n", __LINE__ if $debug; |
1064
|
1
|
|
|
|
|
6
|
return 1; |
1065
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^yesterday$break##xi) { |
1066
|
1
|
|
|
|
|
2
|
$$rdr = -1; |
1067
|
1
|
50
|
|
|
|
5
|
printf "matched at %d.\n", __LINE__ if $debug; |
1068
|
1
|
|
|
|
|
5
|
return 1; |
1069
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^last\s+(week|month|year)$break##xi) { |
1070
|
4
|
|
|
|
|
17
|
&calc($rsr, $yr, $mr, $dr, $rdr, $now, $1, -1, %options); |
1071
|
4
|
50
|
|
|
|
12
|
printf "matched at %d.\n", __LINE__ if $debug; |
1072
|
4
|
|
|
|
|
21
|
return 1; |
1073
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^next\s+(week|month|year)$break##xi) { |
1074
|
3
|
|
|
|
|
45
|
&calc($rsr, $yr, $mr, $dr, $rdr, $now, $1, 1, %options); |
1075
|
3
|
50
|
|
|
|
11
|
printf "matched at %d.\n", __LINE__ if $debug; |
1076
|
3
|
|
|
|
|
19
|
return 1; |
1077
|
|
|
|
|
|
|
} elsif ($$tr =~ s#^now $break##x) { |
1078
|
5
|
|
|
|
|
5
|
$$rdr = 0; |
1079
|
5
|
|
|
|
|
30
|
return 1; |
1080
|
|
|
|
|
|
|
} |
1081
|
25
|
|
|
|
|
152
|
return 0; |
1082
|
|
|
|
|
|
|
} |
1083
|
|
|
|
|
|
|
|
1084
|
|
|
|
|
|
|
sub debug_display |
1085
|
|
|
|
|
|
|
{ |
1086
|
0
|
|
|
0
|
0
|
|
my ($tz, $tzo, $H, $M, $S, $m, $d, $y, $rs, $rd, $rel, $passes, $parse, $t) = @_; |
1087
|
0
|
|
|
|
|
|
print "---------<<\n"; |
1088
|
0
|
0
|
|
|
|
|
print defined($tz) ? "tz: $tz.\n" : "no tz\n"; |
1089
|
0
|
0
|
|
|
|
|
print defined($tzo) ? "tzo: $tzo.\n" : "no tzo\n"; |
1090
|
0
|
|
|
|
|
|
print "HMS: "; |
1091
|
0
|
0
|
|
|
|
|
print defined($H) ? "$H, " : "no H, "; |
1092
|
0
|
0
|
|
|
|
|
print defined($M) ? "$M, " : "no M, "; |
1093
|
0
|
0
|
|
|
|
|
print defined($S) ? "$S\n" : "no S.\n"; |
1094
|
0
|
|
|
|
|
|
print "mdy: "; |
1095
|
0
|
0
|
|
|
|
|
print defined($m) ? "$m, " : "no m, "; |
1096
|
0
|
0
|
|
|
|
|
print defined($d) ? "$d, " : "no d, "; |
1097
|
0
|
0
|
|
|
|
|
print defined($y) ? "$y\n" : "no y.\n"; |
1098
|
0
|
0
|
|
|
|
|
print defined($rs) ? "rs: $rs.\n" : "no rs\n"; |
1099
|
0
|
0
|
|
|
|
|
print defined($rd) ? "rd: $rd.\n" : "no rd\n"; |
1100
|
0
|
0
|
|
|
|
|
print $rel ? "relative\n" : "not relative\n"; |
1101
|
0
|
|
|
|
|
|
print "passes: $passes\n"; |
1102
|
0
|
|
|
|
|
|
print "parse:$parse\n"; |
1103
|
0
|
|
|
|
|
|
print "t: $t.\n"; |
1104
|
0
|
|
|
|
|
|
print "--------->>\n"; |
1105
|
|
|
|
|
|
|
} |
1106
|
|
|
|
|
|
|
1; |
1107
|
|
|
|
|
|
|
|
1108
|
|
|
|
|
|
|
__END__ |