@timshel_npm/maildev 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +287 -0
- package/bin/maildev +13 -0
- package/dist/app/components/angular/angular.js +20282 -0
- package/dist/app/components/angular/angular.min.js +201 -0
- package/dist/app/components/angular/angular.min.js.map +8 -0
- package/dist/app/components/angular-cookies/angular-cookies.js +202 -0
- package/dist/app/components/angular-cookies/angular-cookies.min.js +8 -0
- package/dist/app/components/angular-cookies/angular-cookies.min.js.map +8 -0
- package/dist/app/components/angular-resource/angular-resource.js +546 -0
- package/dist/app/components/angular-resource/angular-resource.min.js +12 -0
- package/dist/app/components/angular-resource/angular-resource.min.js.map +8 -0
- package/dist/app/components/angular-route/angular-route.js +891 -0
- package/dist/app/components/angular-route/angular-route.min.js +14 -0
- package/dist/app/components/angular-route/angular-route.min.js.map +8 -0
- package/dist/app/components/angular-sanitize/angular-sanitize.js +615 -0
- package/dist/app/components/angular-sanitize/angular-sanitize.min.js +14 -0
- package/dist/app/components/angular-sanitize/angular-sanitize.min.js.map +8 -0
- package/dist/app/components/socket.io/socket.io.min.js +7 -0
- package/dist/app/favicon.ico +0 -0
- package/dist/app/index.html +176 -0
- package/dist/app/scripts/app.js +68 -0
- package/dist/app/scripts/components/address.js +15 -0
- package/dist/app/scripts/controllers/item.js +191 -0
- package/dist/app/scripts/controllers/main.js +259 -0
- package/dist/app/scripts/services.js +84 -0
- package/dist/app/styles/style.css +37 -0
- package/dist/app/views/address.html +3 -0
- package/dist/app/views/item.html +310 -0
- package/dist/app/views/main.html +18 -0
- package/dist/app/webfonts/fa-brands-400.eot +0 -0
- package/dist/app/webfonts/fa-brands-400.svg +3717 -0
- package/dist/app/webfonts/fa-brands-400.ttf +0 -0
- package/dist/app/webfonts/fa-brands-400.woff +0 -0
- package/dist/app/webfonts/fa-brands-400.woff2 +0 -0
- package/dist/app/webfonts/fa-regular-400.eot +0 -0
- package/dist/app/webfonts/fa-regular-400.svg +801 -0
- package/dist/app/webfonts/fa-regular-400.ttf +0 -0
- package/dist/app/webfonts/fa-regular-400.woff +0 -0
- package/dist/app/webfonts/fa-regular-400.woff2 +0 -0
- package/dist/app/webfonts/fa-solid-900.eot +0 -0
- package/dist/app/webfonts/fa-solid-900.svg +5028 -0
- package/dist/app/webfonts/fa-solid-900.ttf +0 -0
- package/dist/app/webfonts/fa-solid-900.woff +0 -0
- package/dist/app/webfonts/fa-solid-900.woff2 +0 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +50 -0
- package/dist/lib/auth.d.ts +4 -0
- package/dist/lib/auth.js +26 -0
- package/dist/lib/helpers/bcc.d.ts +5 -0
- package/dist/lib/helpers/bcc.js +16 -0
- package/dist/lib/helpers/smtp.d.ts +4 -0
- package/dist/lib/helpers/smtp.js +16 -0
- package/dist/lib/helpers/strtotime.d.ts +2 -0
- package/dist/lib/helpers/strtotime.js +1301 -0
- package/dist/lib/logger.d.ts +2 -0
- package/dist/lib/logger.js +30 -0
- package/dist/lib/mailbuffer.d.ts +21 -0
- package/dist/lib/mailbuffer.js +102 -0
- package/dist/lib/mailparser.d.ts +2 -0
- package/dist/lib/mailparser.js +253 -0
- package/dist/lib/mailserver.d.ts +115 -0
- package/dist/lib/mailserver.js +497 -0
- package/dist/lib/options.d.ts +3 -0
- package/dist/lib/options.js +150 -0
- package/dist/lib/outgoing.d.ts +40 -0
- package/dist/lib/outgoing.js +162 -0
- package/dist/lib/routes.d.ts +2 -0
- package/dist/lib/routes.js +139 -0
- package/dist/lib/type.d.ts +228 -0
- package/dist/lib/type.js +2 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.js +65 -0
- package/dist/lib/web.d.ts +32 -0
- package/dist/lib/web.js +90 -0
- package/package.json +109 -0
|
@@ -0,0 +1,1301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// From: https://raw.githubusercontent.com/locutusjs/locutus/main/src/php/datetime/strtotime.js
|
|
3
|
+
const reSpace = "[ \\t]+";
|
|
4
|
+
const reSpaceOpt = "[ \\t]*";
|
|
5
|
+
const reMeridian = "(?:([ap])\\.?m\\.?([\\t ]|$))";
|
|
6
|
+
const reHour24 = "(2[0-4]|[01]?[0-9])";
|
|
7
|
+
const reHour24lz = "([01][0-9]|2[0-4])";
|
|
8
|
+
const reHour12 = "(0?[1-9]|1[0-2])";
|
|
9
|
+
const reMinute = "([0-5]?[0-9])";
|
|
10
|
+
const reMinutelz = "([0-5][0-9])";
|
|
11
|
+
const reSecond = "(60|[0-5]?[0-9])";
|
|
12
|
+
const reSecondlz = "(60|[0-5][0-9])";
|
|
13
|
+
const reFrac = "(?:\\.([0-9]+))";
|
|
14
|
+
const reDayfull = "sunday|monday|tuesday|wednesday|thursday|friday|saturday";
|
|
15
|
+
const reDayabbr = "sun|mon|tue|wed|thu|fri|sat";
|
|
16
|
+
const reDaytext = reDayfull + "|" + reDayabbr + "|weekdays?";
|
|
17
|
+
const reReltextnumber = "first|second|third|fourth|fifth|sixth|seventh|eighth?|ninth|tenth|eleventh|twelfth";
|
|
18
|
+
const reReltexttext = "next|last|previous|this";
|
|
19
|
+
const reReltextunit = "(?:second|sec|minute|min|hour|day|fortnight|forthnight|month|year)s?|weeks|" + reDaytext;
|
|
20
|
+
const reYear = "([0-9]{1,4})";
|
|
21
|
+
const reYear2 = "([0-9]{2})";
|
|
22
|
+
const reYear4 = "([0-9]{4})";
|
|
23
|
+
const reYear4withSign = "([+-]?[0-9]{4})";
|
|
24
|
+
const reMonth = "(1[0-2]|0?[0-9])";
|
|
25
|
+
const reMonthlz = "(0[0-9]|1[0-2])";
|
|
26
|
+
const reDay = "(?:(3[01]|[0-2]?[0-9])(?:st|nd|rd|th)?)";
|
|
27
|
+
const reDaylz = "(0[0-9]|[1-2][0-9]|3[01])";
|
|
28
|
+
const reMonthFull = "january|february|march|april|may|june|july|august|september|october|november|december";
|
|
29
|
+
const reMonthAbbr = "jan|feb|mar|apr|may|jun|jul|aug|sept?|oct|nov|dec";
|
|
30
|
+
const reMonthroman = "i[vx]|vi{0,3}|xi{0,2}|i{1,3}";
|
|
31
|
+
const reMonthText = "(" + reMonthFull + "|" + reMonthAbbr + "|" + reMonthroman + ")";
|
|
32
|
+
const reTzCorrection = "((?:GMT)?([+-])" + reHour24 + ":?" + reMinute + "?)";
|
|
33
|
+
const reTzAbbr = "\\(?([a-zA-Z]{1,6})\\)?";
|
|
34
|
+
const reDayOfYear = "(00[1-9]|0[1-9][0-9]|[12][0-9][0-9]|3[0-5][0-9]|36[0-6])";
|
|
35
|
+
const reWeekOfYear = "(0[1-9]|[1-4][0-9]|5[0-3])";
|
|
36
|
+
const reDateNoYear = reMonthText + "[ .\\t-]*" + reDay + "[,.stndrh\\t ]*";
|
|
37
|
+
function processMeridian(hour, meridian) {
|
|
38
|
+
meridian = meridian && meridian.toLowerCase();
|
|
39
|
+
switch (meridian) {
|
|
40
|
+
case "a":
|
|
41
|
+
hour += hour === 12 ? -12 : 0;
|
|
42
|
+
break;
|
|
43
|
+
case "p":
|
|
44
|
+
hour += hour !== 12 ? 12 : 0;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return hour;
|
|
48
|
+
}
|
|
49
|
+
function processYear(yearStr) {
|
|
50
|
+
let year = +yearStr;
|
|
51
|
+
if (yearStr.length < 4 && year < 100) {
|
|
52
|
+
year += year < 70 ? 2000 : 1900;
|
|
53
|
+
}
|
|
54
|
+
return year;
|
|
55
|
+
}
|
|
56
|
+
function lookupMonth(monthStr) {
|
|
57
|
+
return {
|
|
58
|
+
jan: 0,
|
|
59
|
+
january: 0,
|
|
60
|
+
i: 0,
|
|
61
|
+
feb: 1,
|
|
62
|
+
february: 1,
|
|
63
|
+
ii: 1,
|
|
64
|
+
mar: 2,
|
|
65
|
+
march: 2,
|
|
66
|
+
iii: 2,
|
|
67
|
+
apr: 3,
|
|
68
|
+
april: 3,
|
|
69
|
+
iv: 3,
|
|
70
|
+
may: 4,
|
|
71
|
+
v: 4,
|
|
72
|
+
jun: 5,
|
|
73
|
+
june: 5,
|
|
74
|
+
vi: 5,
|
|
75
|
+
jul: 6,
|
|
76
|
+
july: 6,
|
|
77
|
+
vii: 6,
|
|
78
|
+
aug: 7,
|
|
79
|
+
august: 7,
|
|
80
|
+
viii: 7,
|
|
81
|
+
sep: 8,
|
|
82
|
+
sept: 8,
|
|
83
|
+
september: 8,
|
|
84
|
+
ix: 8,
|
|
85
|
+
oct: 9,
|
|
86
|
+
october: 9,
|
|
87
|
+
x: 9,
|
|
88
|
+
nov: 10,
|
|
89
|
+
november: 10,
|
|
90
|
+
xi: 10,
|
|
91
|
+
dec: 11,
|
|
92
|
+
december: 11,
|
|
93
|
+
xii: 11,
|
|
94
|
+
}[monthStr.toLowerCase()];
|
|
95
|
+
}
|
|
96
|
+
function lookupWeekday(dayStr, desiredSundayNumber = 0) {
|
|
97
|
+
const dayNumbers = {
|
|
98
|
+
mon: 1,
|
|
99
|
+
monday: 1,
|
|
100
|
+
tue: 2,
|
|
101
|
+
tuesday: 2,
|
|
102
|
+
wed: 3,
|
|
103
|
+
wednesday: 3,
|
|
104
|
+
thu: 4,
|
|
105
|
+
thursday: 4,
|
|
106
|
+
fri: 5,
|
|
107
|
+
friday: 5,
|
|
108
|
+
sat: 6,
|
|
109
|
+
saturday: 6,
|
|
110
|
+
sun: 0,
|
|
111
|
+
sunday: 0,
|
|
112
|
+
};
|
|
113
|
+
return dayNumbers[dayStr.toLowerCase()] || desiredSundayNumber;
|
|
114
|
+
}
|
|
115
|
+
function lookupRelative(relText) {
|
|
116
|
+
const relativeNumbers = {
|
|
117
|
+
last: -1,
|
|
118
|
+
previous: -1,
|
|
119
|
+
this: 0,
|
|
120
|
+
first: 1,
|
|
121
|
+
next: 1,
|
|
122
|
+
second: 2,
|
|
123
|
+
third: 3,
|
|
124
|
+
fourth: 4,
|
|
125
|
+
fifth: 5,
|
|
126
|
+
sixth: 6,
|
|
127
|
+
seventh: 7,
|
|
128
|
+
eight: 8,
|
|
129
|
+
eighth: 8,
|
|
130
|
+
ninth: 9,
|
|
131
|
+
tenth: 10,
|
|
132
|
+
eleventh: 11,
|
|
133
|
+
twelfth: 12,
|
|
134
|
+
};
|
|
135
|
+
const relativeBehavior = {
|
|
136
|
+
this: 1,
|
|
137
|
+
};
|
|
138
|
+
const relTextLower = relText.toLowerCase();
|
|
139
|
+
return {
|
|
140
|
+
amount: relativeNumbers[relTextLower],
|
|
141
|
+
behavior: relativeBehavior[relTextLower] || 0,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function processTzCorrection(tzOffset, oldValue) {
|
|
145
|
+
const reTzCorrectionLoose = /(?:GMT)?([+-])(\d+)(:?)(\d{0,2})/i;
|
|
146
|
+
tzOffset = tzOffset && tzOffset.match(reTzCorrectionLoose);
|
|
147
|
+
if (!tzOffset) {
|
|
148
|
+
return oldValue;
|
|
149
|
+
}
|
|
150
|
+
const sign = tzOffset[1] === "-" ? -1 : 1;
|
|
151
|
+
let hours = +tzOffset[2];
|
|
152
|
+
let minutes = +tzOffset[4];
|
|
153
|
+
if (!tzOffset[4] && !tzOffset[3]) {
|
|
154
|
+
minutes = Math.floor(hours % 100);
|
|
155
|
+
hours = Math.floor(hours / 100);
|
|
156
|
+
}
|
|
157
|
+
// timezone offset in seconds
|
|
158
|
+
return sign * (hours * 60 + minutes) * 60;
|
|
159
|
+
}
|
|
160
|
+
// tz abbrevation : tz offset in seconds
|
|
161
|
+
const tzAbbrOffsets = {
|
|
162
|
+
acdt: 37800,
|
|
163
|
+
acst: 34200,
|
|
164
|
+
addt: -7200,
|
|
165
|
+
adt: -10800,
|
|
166
|
+
aedt: 39600,
|
|
167
|
+
aest: 36000,
|
|
168
|
+
ahdt: -32400,
|
|
169
|
+
ahst: -36000,
|
|
170
|
+
akdt: -28800,
|
|
171
|
+
akst: -32400,
|
|
172
|
+
amt: -13840,
|
|
173
|
+
apt: -10800,
|
|
174
|
+
ast: -14400,
|
|
175
|
+
awdt: 32400,
|
|
176
|
+
awst: 28800,
|
|
177
|
+
awt: -10800,
|
|
178
|
+
bdst: 7200,
|
|
179
|
+
bdt: -36000,
|
|
180
|
+
bmt: -14309,
|
|
181
|
+
bst: 3600,
|
|
182
|
+
cast: 34200,
|
|
183
|
+
cat: 7200,
|
|
184
|
+
cddt: -14400,
|
|
185
|
+
cdt: -18000,
|
|
186
|
+
cemt: 10800,
|
|
187
|
+
cest: 7200,
|
|
188
|
+
cet: 3600,
|
|
189
|
+
cmt: -15408,
|
|
190
|
+
cpt: -18000,
|
|
191
|
+
cst: -21600,
|
|
192
|
+
cwt: -18000,
|
|
193
|
+
chst: 36000,
|
|
194
|
+
dmt: -1521,
|
|
195
|
+
eat: 10800,
|
|
196
|
+
eddt: -10800,
|
|
197
|
+
edt: -14400,
|
|
198
|
+
eest: 10800,
|
|
199
|
+
eet: 7200,
|
|
200
|
+
emt: -26248,
|
|
201
|
+
ept: -14400,
|
|
202
|
+
est: -18000,
|
|
203
|
+
ewt: -14400,
|
|
204
|
+
ffmt: -14660,
|
|
205
|
+
fmt: -4056,
|
|
206
|
+
gdt: 39600,
|
|
207
|
+
gmt: 0,
|
|
208
|
+
gst: 36000,
|
|
209
|
+
hdt: -34200,
|
|
210
|
+
hkst: 32400,
|
|
211
|
+
hkt: 28800,
|
|
212
|
+
hmt: -19776,
|
|
213
|
+
hpt: -34200,
|
|
214
|
+
hst: -36000,
|
|
215
|
+
hwt: -34200,
|
|
216
|
+
iddt: 14400,
|
|
217
|
+
idt: 10800,
|
|
218
|
+
imt: 25025,
|
|
219
|
+
ist: 7200,
|
|
220
|
+
jdt: 36000,
|
|
221
|
+
jmt: 8440,
|
|
222
|
+
jst: 32400,
|
|
223
|
+
kdt: 36000,
|
|
224
|
+
kmt: 5736,
|
|
225
|
+
kst: 30600,
|
|
226
|
+
lst: 9394,
|
|
227
|
+
mddt: -18000,
|
|
228
|
+
mdst: 16279,
|
|
229
|
+
mdt: -21600,
|
|
230
|
+
mest: 7200,
|
|
231
|
+
met: 3600,
|
|
232
|
+
mmt: 9017,
|
|
233
|
+
mpt: -21600,
|
|
234
|
+
msd: 14400,
|
|
235
|
+
msk: 10800,
|
|
236
|
+
mst: -25200,
|
|
237
|
+
mwt: -21600,
|
|
238
|
+
nddt: -5400,
|
|
239
|
+
ndt: -9052,
|
|
240
|
+
npt: -9000,
|
|
241
|
+
nst: -12600,
|
|
242
|
+
nwt: -9000,
|
|
243
|
+
nzdt: 46800,
|
|
244
|
+
nzmt: 41400,
|
|
245
|
+
nzst: 43200,
|
|
246
|
+
pddt: -21600,
|
|
247
|
+
pdt: -25200,
|
|
248
|
+
pkst: 21600,
|
|
249
|
+
pkt: 18000,
|
|
250
|
+
plmt: 25590,
|
|
251
|
+
pmt: -13236,
|
|
252
|
+
ppmt: -17340,
|
|
253
|
+
ppt: -25200,
|
|
254
|
+
pst: -28800,
|
|
255
|
+
pwt: -25200,
|
|
256
|
+
qmt: -18840,
|
|
257
|
+
rmt: 5794,
|
|
258
|
+
sast: 7200,
|
|
259
|
+
sdmt: -16800,
|
|
260
|
+
sjmt: -20173,
|
|
261
|
+
smt: -13884,
|
|
262
|
+
sst: -39600,
|
|
263
|
+
tbmt: 10751,
|
|
264
|
+
tmt: 12344,
|
|
265
|
+
uct: 0,
|
|
266
|
+
utc: 0,
|
|
267
|
+
wast: 7200,
|
|
268
|
+
wat: 3600,
|
|
269
|
+
wemt: 7200,
|
|
270
|
+
west: 3600,
|
|
271
|
+
wet: 0,
|
|
272
|
+
wib: 25200,
|
|
273
|
+
wita: 28800,
|
|
274
|
+
wit: 32400,
|
|
275
|
+
wmt: 5040,
|
|
276
|
+
yddt: -25200,
|
|
277
|
+
ydt: -28800,
|
|
278
|
+
ypt: -28800,
|
|
279
|
+
yst: -32400,
|
|
280
|
+
ywt: -28800,
|
|
281
|
+
a: 3600,
|
|
282
|
+
b: 7200,
|
|
283
|
+
c: 10800,
|
|
284
|
+
d: 14400,
|
|
285
|
+
e: 18000,
|
|
286
|
+
f: 21600,
|
|
287
|
+
g: 25200,
|
|
288
|
+
h: 28800,
|
|
289
|
+
i: 32400,
|
|
290
|
+
k: 36000,
|
|
291
|
+
l: 39600,
|
|
292
|
+
m: 43200,
|
|
293
|
+
n: -3600,
|
|
294
|
+
o: -7200,
|
|
295
|
+
p: -10800,
|
|
296
|
+
q: -14400,
|
|
297
|
+
r: -18000,
|
|
298
|
+
s: -21600,
|
|
299
|
+
t: -25200,
|
|
300
|
+
u: -28800,
|
|
301
|
+
v: -32400,
|
|
302
|
+
w: -36000,
|
|
303
|
+
x: -39600,
|
|
304
|
+
y: -43200,
|
|
305
|
+
z: 0,
|
|
306
|
+
};
|
|
307
|
+
const formats = {
|
|
308
|
+
yesterday: {
|
|
309
|
+
regex: /^yesterday/i,
|
|
310
|
+
name: "yesterday",
|
|
311
|
+
callback() {
|
|
312
|
+
this.rd -= 1;
|
|
313
|
+
return this.resetTime();
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
now: {
|
|
317
|
+
regex: /^now/i,
|
|
318
|
+
name: "now",
|
|
319
|
+
// do nothing
|
|
320
|
+
},
|
|
321
|
+
noon: {
|
|
322
|
+
regex: /^noon/i,
|
|
323
|
+
name: "noon",
|
|
324
|
+
callback() {
|
|
325
|
+
return this.resetTime() && this.time(12, 0, 0, 0);
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
midnightOrToday: {
|
|
329
|
+
regex: /^(midnight|today)/i,
|
|
330
|
+
name: "midnight | today",
|
|
331
|
+
callback() {
|
|
332
|
+
return this.resetTime();
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
tomorrow: {
|
|
336
|
+
regex: /^tomorrow/i,
|
|
337
|
+
name: "tomorrow",
|
|
338
|
+
callback() {
|
|
339
|
+
this.rd += 1;
|
|
340
|
+
return this.resetTime();
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
timestamp: {
|
|
344
|
+
regex: /^@(-?\d+)/i,
|
|
345
|
+
name: "timestamp",
|
|
346
|
+
callback(match, timestamp) {
|
|
347
|
+
this.rs += +timestamp;
|
|
348
|
+
this.y = 1970;
|
|
349
|
+
this.m = 0;
|
|
350
|
+
this.d = 1;
|
|
351
|
+
this.dates = 0;
|
|
352
|
+
return this.resetTime() && this.zone(0);
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
firstOrLastDay: {
|
|
356
|
+
regex: /^(first|last) day of/i,
|
|
357
|
+
name: "firstdayof | lastdayof",
|
|
358
|
+
callback(match, day) {
|
|
359
|
+
if (day.toLowerCase() === "first") {
|
|
360
|
+
this.firstOrLastDayOfMonth = 1;
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
this.firstOrLastDayOfMonth = -1;
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
backOrFrontOf: {
|
|
368
|
+
regex: RegExp("^(back|front) of " + reHour24 + reSpaceOpt + reMeridian + "?", "i"),
|
|
369
|
+
name: "backof | frontof",
|
|
370
|
+
callback(match, side, hours, meridian) {
|
|
371
|
+
const back = side.toLowerCase() === "back";
|
|
372
|
+
let hour = +hours;
|
|
373
|
+
let minute = 15;
|
|
374
|
+
if (!back) {
|
|
375
|
+
hour -= 1;
|
|
376
|
+
minute = 45;
|
|
377
|
+
}
|
|
378
|
+
hour = processMeridian(hour, meridian);
|
|
379
|
+
return this.resetTime() && this.time(hour, minute, 0, 0);
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
weekdayOf: {
|
|
383
|
+
regex: RegExp("^(" +
|
|
384
|
+
reReltextnumber +
|
|
385
|
+
"|" +
|
|
386
|
+
reReltexttext +
|
|
387
|
+
")" +
|
|
388
|
+
reSpace +
|
|
389
|
+
"(" +
|
|
390
|
+
reDayfull +
|
|
391
|
+
"|" +
|
|
392
|
+
reDayabbr +
|
|
393
|
+
")" +
|
|
394
|
+
reSpace +
|
|
395
|
+
"of", "i"),
|
|
396
|
+
name: "weekdayof",
|
|
397
|
+
// todo
|
|
398
|
+
},
|
|
399
|
+
mssqltime: {
|
|
400
|
+
regex: RegExp("^" + reHour12 + ":" + reMinutelz + ":" + reSecondlz + "[:.]([0-9]+)" + reMeridian, "i"),
|
|
401
|
+
name: "mssqltime",
|
|
402
|
+
callback(match, hour, minute, second, frac, meridian) {
|
|
403
|
+
return this.time(processMeridian(+hour, meridian), +minute, +second, +frac.substr(0, 3));
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
oracledate: {
|
|
407
|
+
regex: /^(\d{2})-([A-Z]{3})-(\d{2})$/i,
|
|
408
|
+
name: "d-M-y",
|
|
409
|
+
callback(match, day, monthText, year) {
|
|
410
|
+
const month = {
|
|
411
|
+
JAN: 0,
|
|
412
|
+
FEB: 1,
|
|
413
|
+
MAR: 2,
|
|
414
|
+
APR: 3,
|
|
415
|
+
MAY: 4,
|
|
416
|
+
JUN: 5,
|
|
417
|
+
JUL: 6,
|
|
418
|
+
AUG: 7,
|
|
419
|
+
SEP: 8,
|
|
420
|
+
OCT: 9,
|
|
421
|
+
NOV: 10,
|
|
422
|
+
DEC: 11,
|
|
423
|
+
}[monthText.toUpperCase()];
|
|
424
|
+
return this.ymd(2000 + parseInt(year, 10), month, parseInt(day, 10));
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
timeLong12: {
|
|
428
|
+
regex: RegExp("^" + reHour12 + "[:.]" + reMinute + "[:.]" + reSecondlz + reSpaceOpt + reMeridian, "i"),
|
|
429
|
+
name: "timelong12",
|
|
430
|
+
callback(match, hour, minute, second, meridian) {
|
|
431
|
+
return this.time(processMeridian(+hour, meridian), +minute, +second, 0);
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
timeShort12: {
|
|
435
|
+
regex: RegExp("^" + reHour12 + "[:.]" + reMinutelz + reSpaceOpt + reMeridian, "i"),
|
|
436
|
+
name: "timeshort12",
|
|
437
|
+
callback(match, hour, minute, meridian) {
|
|
438
|
+
return this.time(processMeridian(+hour, meridian), +minute, 0, 0);
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
timeTiny12: {
|
|
442
|
+
regex: RegExp("^" + reHour12 + reSpaceOpt + reMeridian, "i"),
|
|
443
|
+
name: "timetiny12",
|
|
444
|
+
callback(match, hour, meridian) {
|
|
445
|
+
return this.time(processMeridian(+hour, meridian), 0, 0, 0);
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
soap: {
|
|
449
|
+
regex: RegExp("^" +
|
|
450
|
+
reYear4 +
|
|
451
|
+
"-" +
|
|
452
|
+
reMonthlz +
|
|
453
|
+
"-" +
|
|
454
|
+
reDaylz +
|
|
455
|
+
"T" +
|
|
456
|
+
reHour24lz +
|
|
457
|
+
":" +
|
|
458
|
+
reMinutelz +
|
|
459
|
+
":" +
|
|
460
|
+
reSecondlz +
|
|
461
|
+
reFrac +
|
|
462
|
+
reTzCorrection +
|
|
463
|
+
"?", "i"),
|
|
464
|
+
name: "soap",
|
|
465
|
+
callback(match, year, month, day, hour, minute, second, frac, tzCorrection) {
|
|
466
|
+
return (this.ymd(+year, month - 1, +day) &&
|
|
467
|
+
this.time(+hour, +minute, +second, +frac.substr(0, 3)) &&
|
|
468
|
+
this.zone(processTzCorrection(tzCorrection)));
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
wddx: {
|
|
472
|
+
regex: RegExp("^" +
|
|
473
|
+
reYear4 +
|
|
474
|
+
"-" +
|
|
475
|
+
reMonth +
|
|
476
|
+
"-" +
|
|
477
|
+
reDay +
|
|
478
|
+
"T" +
|
|
479
|
+
reHour24 +
|
|
480
|
+
":" +
|
|
481
|
+
reMinute +
|
|
482
|
+
":" +
|
|
483
|
+
reSecond),
|
|
484
|
+
name: "wddx",
|
|
485
|
+
callback(match, year, month, day, hour, minute, second) {
|
|
486
|
+
return this.ymd(+year, month - 1, +day) && this.time(+hour, +minute, +second, 0);
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
exif: {
|
|
490
|
+
regex: RegExp("^" +
|
|
491
|
+
reYear4 +
|
|
492
|
+
":" +
|
|
493
|
+
reMonthlz +
|
|
494
|
+
":" +
|
|
495
|
+
reDaylz +
|
|
496
|
+
" " +
|
|
497
|
+
reHour24lz +
|
|
498
|
+
":" +
|
|
499
|
+
reMinutelz +
|
|
500
|
+
":" +
|
|
501
|
+
reSecondlz, "i"),
|
|
502
|
+
name: "exif",
|
|
503
|
+
callback(match, year, month, day, hour, minute, second) {
|
|
504
|
+
return this.ymd(+year, month - 1, +day) && this.time(+hour, +minute, +second, 0);
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
xmlRpc: {
|
|
508
|
+
regex: RegExp("^" + reYear4 + reMonthlz + reDaylz + "T" + reHour24 + ":" + reMinutelz + ":" + reSecondlz),
|
|
509
|
+
name: "xmlrpc",
|
|
510
|
+
callback(match, year, month, day, hour, minute, second) {
|
|
511
|
+
return this.ymd(+year, month - 1, +day) && this.time(+hour, +minute, +second, 0);
|
|
512
|
+
},
|
|
513
|
+
},
|
|
514
|
+
xmlRpcNoColon: {
|
|
515
|
+
regex: RegExp("^" + reYear4 + reMonthlz + reDaylz + "[Tt]" + reHour24 + reMinutelz + reSecondlz),
|
|
516
|
+
name: "xmlrpcnocolon",
|
|
517
|
+
callback(match, year, month, day, hour, minute, second) {
|
|
518
|
+
return this.ymd(+year, month - 1, +day) && this.time(+hour, +minute, +second, 0);
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
clf: {
|
|
522
|
+
regex: RegExp("^" +
|
|
523
|
+
reDay +
|
|
524
|
+
"/(" +
|
|
525
|
+
reMonthAbbr +
|
|
526
|
+
")/" +
|
|
527
|
+
reYear4 +
|
|
528
|
+
":" +
|
|
529
|
+
reHour24lz +
|
|
530
|
+
":" +
|
|
531
|
+
reMinutelz +
|
|
532
|
+
":" +
|
|
533
|
+
reSecondlz +
|
|
534
|
+
reSpace +
|
|
535
|
+
reTzCorrection, "i"),
|
|
536
|
+
name: "clf",
|
|
537
|
+
callback(match, day, month, year, hour, minute, second, tzCorrection) {
|
|
538
|
+
return (this.ymd(+year, lookupMonth(month), +day) &&
|
|
539
|
+
this.time(+hour, +minute, +second, 0) &&
|
|
540
|
+
this.zone(processTzCorrection(tzCorrection)));
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
iso8601long: {
|
|
544
|
+
regex: RegExp("^t?" + reHour24 + "[:.]" + reMinute + "[:.]" + reSecond + reFrac, "i"),
|
|
545
|
+
name: "iso8601long",
|
|
546
|
+
callback(match, hour, minute, second, frac) {
|
|
547
|
+
return this.time(+hour, +minute, +second, +frac.substr(0, 3));
|
|
548
|
+
},
|
|
549
|
+
},
|
|
550
|
+
dateTextual: {
|
|
551
|
+
regex: RegExp("^" + reMonthText + "[ .\\t-]*" + reDay + "[,.stndrh\\t ]+" + reYear, "i"),
|
|
552
|
+
name: "datetextual",
|
|
553
|
+
callback(match, month, day, year) {
|
|
554
|
+
return this.ymd(processYear(year), lookupMonth(month), +day);
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
pointedDate4: {
|
|
558
|
+
regex: RegExp("^" + reDay + "[.\\t-]" + reMonth + "[.-]" + reYear4),
|
|
559
|
+
name: "pointeddate4",
|
|
560
|
+
callback(match, day, month, year) {
|
|
561
|
+
return this.ymd(+year, month - 1, +day);
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
pointedDate2: {
|
|
565
|
+
regex: RegExp("^" + reDay + "[.\\t]" + reMonth + "\\." + reYear2),
|
|
566
|
+
name: "pointeddate2",
|
|
567
|
+
callback(match, day, month, year) {
|
|
568
|
+
return this.ymd(processYear(year), month - 1, +day);
|
|
569
|
+
},
|
|
570
|
+
},
|
|
571
|
+
timeLong24: {
|
|
572
|
+
regex: RegExp("^t?" + reHour24 + "[:.]" + reMinute + "[:.]" + reSecond),
|
|
573
|
+
name: "timelong24",
|
|
574
|
+
callback(match, hour, minute, second) {
|
|
575
|
+
return this.time(+hour, +minute, +second, 0);
|
|
576
|
+
},
|
|
577
|
+
},
|
|
578
|
+
dateNoColon: {
|
|
579
|
+
regex: RegExp("^" + reYear4 + reMonthlz + reDaylz),
|
|
580
|
+
name: "datenocolon",
|
|
581
|
+
callback(match, year, month, day) {
|
|
582
|
+
return this.ymd(+year, month - 1, +day);
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
pgydotd: {
|
|
586
|
+
regex: RegExp("^" + reYear4 + "\\.?" + reDayOfYear),
|
|
587
|
+
name: "pgydotd",
|
|
588
|
+
callback(match, year, day) {
|
|
589
|
+
return this.ymd(+year, 0, +day);
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
timeShort24: {
|
|
593
|
+
regex: RegExp("^t?" + reHour24 + "[:.]" + reMinute, "i"),
|
|
594
|
+
name: "timeshort24",
|
|
595
|
+
callback(match, hour, minute) {
|
|
596
|
+
return this.time(+hour, +minute, 0, 0);
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
iso8601noColon: {
|
|
600
|
+
regex: RegExp("^t?" + reHour24lz + reMinutelz + reSecondlz, "i"),
|
|
601
|
+
name: "iso8601nocolon",
|
|
602
|
+
callback(match, hour, minute, second) {
|
|
603
|
+
return this.time(+hour, +minute, +second, 0);
|
|
604
|
+
},
|
|
605
|
+
},
|
|
606
|
+
iso8601dateSlash: {
|
|
607
|
+
// eventhough the trailing slash is optional in PHP
|
|
608
|
+
// here it's mandatory and inputs without the slash
|
|
609
|
+
// are handled by dateslash
|
|
610
|
+
regex: RegExp("^" + reYear4 + "/" + reMonthlz + "/" + reDaylz + "/"),
|
|
611
|
+
name: "iso8601dateslash",
|
|
612
|
+
callback(match, year, month, day) {
|
|
613
|
+
return this.ymd(+year, month - 1, +day);
|
|
614
|
+
},
|
|
615
|
+
},
|
|
616
|
+
dateSlash: {
|
|
617
|
+
regex: RegExp("^" + reYear4 + "/" + reMonth + "/" + reDay),
|
|
618
|
+
name: "dateslash",
|
|
619
|
+
callback(match, year, month, day) {
|
|
620
|
+
return this.ymd(+year, month - 1, +day);
|
|
621
|
+
},
|
|
622
|
+
},
|
|
623
|
+
american: {
|
|
624
|
+
regex: RegExp("^" + reMonth + "/" + reDay + "/" + reYear),
|
|
625
|
+
name: "american",
|
|
626
|
+
callback(match, month, day, year) {
|
|
627
|
+
return this.ymd(processYear(year), month - 1, +day);
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
americanShort: {
|
|
631
|
+
regex: RegExp("^" + reMonth + "/" + reDay),
|
|
632
|
+
name: "americanshort",
|
|
633
|
+
callback(match, month, day) {
|
|
634
|
+
return this.ymd(this.y, month - 1, +day);
|
|
635
|
+
},
|
|
636
|
+
},
|
|
637
|
+
gnuDateShortOrIso8601date2: {
|
|
638
|
+
// iso8601date2 is complete subset of gnudateshort
|
|
639
|
+
regex: RegExp("^" + reYear + "-" + reMonth + "-" + reDay),
|
|
640
|
+
name: "gnudateshort | iso8601date2",
|
|
641
|
+
callback(match, year, month, day) {
|
|
642
|
+
return this.ymd(processYear(year), month - 1, +day);
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
iso8601date4: {
|
|
646
|
+
regex: RegExp("^" + reYear4withSign + "-" + reMonthlz + "-" + reDaylz),
|
|
647
|
+
name: "iso8601date4",
|
|
648
|
+
callback(match, year, month, day) {
|
|
649
|
+
return this.ymd(+year, month - 1, +day);
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
gnuNoColon: {
|
|
653
|
+
regex: RegExp("^t?" + reHour24lz + reMinutelz, "i"),
|
|
654
|
+
name: "gnunocolon",
|
|
655
|
+
callback(match, hour, minute) {
|
|
656
|
+
// this rule is a special case
|
|
657
|
+
// if time was already set once by any preceding rule, it sets the captured value as year
|
|
658
|
+
switch (this.times) {
|
|
659
|
+
case 0:
|
|
660
|
+
return this.time(+hour, +minute, 0, this.f);
|
|
661
|
+
case 1:
|
|
662
|
+
this.y = hour * 100 + +minute;
|
|
663
|
+
this.times++;
|
|
664
|
+
return true;
|
|
665
|
+
default:
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
},
|
|
670
|
+
gnuDateShorter: {
|
|
671
|
+
regex: RegExp("^" + reYear4 + "-" + reMonth),
|
|
672
|
+
name: "gnudateshorter",
|
|
673
|
+
callback(match, year, month) {
|
|
674
|
+
return this.ymd(+year, month - 1, 1);
|
|
675
|
+
},
|
|
676
|
+
},
|
|
677
|
+
pgTextReverse: {
|
|
678
|
+
// note: allowed years are from 32-9999
|
|
679
|
+
// years below 32 should be treated as days in datefull
|
|
680
|
+
regex: RegExp("^" + "(\\d{3,4}|[4-9]\\d|3[2-9])-(" + reMonthAbbr + ")-" + reDaylz, "i"),
|
|
681
|
+
name: "pgtextreverse",
|
|
682
|
+
callback(match, year, month, day) {
|
|
683
|
+
return this.ymd(processYear(year), lookupMonth(month), +day);
|
|
684
|
+
},
|
|
685
|
+
},
|
|
686
|
+
dateFull: {
|
|
687
|
+
regex: RegExp("^" + reDay + "[ \\t.-]*" + reMonthText + "[ \\t.-]*" + reYear, "i"),
|
|
688
|
+
name: "datefull",
|
|
689
|
+
callback(match, day, month, year) {
|
|
690
|
+
return this.ymd(processYear(year), lookupMonth(month), +day);
|
|
691
|
+
},
|
|
692
|
+
},
|
|
693
|
+
dateNoDay: {
|
|
694
|
+
regex: RegExp("^" + reMonthText + "[ .\\t-]*" + reYear4, "i"),
|
|
695
|
+
name: "datenoday",
|
|
696
|
+
callback(match, month, year) {
|
|
697
|
+
return this.ymd(+year, lookupMonth(month), 1);
|
|
698
|
+
},
|
|
699
|
+
},
|
|
700
|
+
dateNoDayRev: {
|
|
701
|
+
regex: RegExp("^" + reYear4 + "[ .\\t-]*" + reMonthText, "i"),
|
|
702
|
+
name: "datenodayrev",
|
|
703
|
+
callback(match, year, month) {
|
|
704
|
+
return this.ymd(+year, lookupMonth(month), 1);
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
pgTextShort: {
|
|
708
|
+
regex: RegExp("^(" + reMonthAbbr + ")-" + reDaylz + "-" + reYear, "i"),
|
|
709
|
+
name: "pgtextshort",
|
|
710
|
+
callback(match, month, day, year) {
|
|
711
|
+
return this.ymd(processYear(year), lookupMonth(month), +day);
|
|
712
|
+
},
|
|
713
|
+
},
|
|
714
|
+
dateNoYear: {
|
|
715
|
+
regex: RegExp("^" + reDateNoYear, "i"),
|
|
716
|
+
name: "datenoyear",
|
|
717
|
+
callback(match, month, day) {
|
|
718
|
+
return this.ymd(this.y, lookupMonth(month), +day);
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
dateNoYearRev: {
|
|
722
|
+
regex: RegExp("^" + reDay + "[ .\\t-]*" + reMonthText, "i"),
|
|
723
|
+
name: "datenoyearrev",
|
|
724
|
+
callback(match, day, month) {
|
|
725
|
+
return this.ymd(this.y, lookupMonth(month), +day);
|
|
726
|
+
},
|
|
727
|
+
},
|
|
728
|
+
isoWeekDay: {
|
|
729
|
+
regex: RegExp("^" + reYear4 + "-?W" + reWeekOfYear + "(?:-?([0-7]))?"),
|
|
730
|
+
name: "isoweekday | isoweek",
|
|
731
|
+
callback(match, year, week, day) {
|
|
732
|
+
day = day ? +day : 1;
|
|
733
|
+
if (!this.ymd(+year, 0, 1)) {
|
|
734
|
+
return false;
|
|
735
|
+
}
|
|
736
|
+
// get day of week for Jan 1st
|
|
737
|
+
let dayOfWeek = new Date(this.y, this.m, this.d).getDay();
|
|
738
|
+
// and use the day to figure out the offset for day 1 of week 1
|
|
739
|
+
dayOfWeek = 0 - (dayOfWeek > 4 ? dayOfWeek - 7 : dayOfWeek);
|
|
740
|
+
this.rd += dayOfWeek + (week - 1) * 7 + day;
|
|
741
|
+
},
|
|
742
|
+
},
|
|
743
|
+
relativeText: {
|
|
744
|
+
regex: RegExp("^(" + reReltextnumber + "|" + reReltexttext + ")" + reSpace + "(" + reReltextunit + ")", "i"),
|
|
745
|
+
name: "relativetext",
|
|
746
|
+
callback(match, relValue, relUnit) {
|
|
747
|
+
// todo: implement handling of 'this time-unit'
|
|
748
|
+
// eslint-disable-next-line no-unused-vars
|
|
749
|
+
const { amount, behavior } = lookupRelative(relValue);
|
|
750
|
+
switch (relUnit.toLowerCase()) {
|
|
751
|
+
case "sec":
|
|
752
|
+
case "secs":
|
|
753
|
+
case "second":
|
|
754
|
+
case "seconds":
|
|
755
|
+
this.rs += amount;
|
|
756
|
+
break;
|
|
757
|
+
case "min":
|
|
758
|
+
case "mins":
|
|
759
|
+
case "minute":
|
|
760
|
+
case "minutes":
|
|
761
|
+
this.ri += amount;
|
|
762
|
+
break;
|
|
763
|
+
case "hour":
|
|
764
|
+
case "hours":
|
|
765
|
+
this.rh += amount;
|
|
766
|
+
break;
|
|
767
|
+
case "day":
|
|
768
|
+
case "days":
|
|
769
|
+
this.rd += amount;
|
|
770
|
+
break;
|
|
771
|
+
case "fortnight":
|
|
772
|
+
case "fortnights":
|
|
773
|
+
case "forthnight":
|
|
774
|
+
case "forthnights":
|
|
775
|
+
this.rd += amount * 14;
|
|
776
|
+
break;
|
|
777
|
+
case "week":
|
|
778
|
+
case "weeks":
|
|
779
|
+
this.rd += amount * 7;
|
|
780
|
+
break;
|
|
781
|
+
case "month":
|
|
782
|
+
case "months":
|
|
783
|
+
this.rm += amount;
|
|
784
|
+
break;
|
|
785
|
+
case "year":
|
|
786
|
+
case "years":
|
|
787
|
+
this.ry += amount;
|
|
788
|
+
break;
|
|
789
|
+
case "mon":
|
|
790
|
+
case "monday":
|
|
791
|
+
case "tue":
|
|
792
|
+
case "tuesday":
|
|
793
|
+
case "wed":
|
|
794
|
+
case "wednesday":
|
|
795
|
+
case "thu":
|
|
796
|
+
case "thursday":
|
|
797
|
+
case "fri":
|
|
798
|
+
case "friday":
|
|
799
|
+
case "sat":
|
|
800
|
+
case "saturday":
|
|
801
|
+
case "sun":
|
|
802
|
+
case "sunday":
|
|
803
|
+
this.resetTime();
|
|
804
|
+
this.weekday = lookupWeekday(relUnit, 7);
|
|
805
|
+
this.weekdayBehavior = 1;
|
|
806
|
+
this.rd += (amount > 0 ? amount - 1 : amount) * 7;
|
|
807
|
+
break;
|
|
808
|
+
case "weekday":
|
|
809
|
+
case "weekdays":
|
|
810
|
+
// todo
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
},
|
|
814
|
+
},
|
|
815
|
+
relative: {
|
|
816
|
+
regex: RegExp("^([+-]*)[ \\t]*(\\d+)" + reSpaceOpt + "(" + reReltextunit + "|week)", "i"),
|
|
817
|
+
name: "relative",
|
|
818
|
+
callback(match, signs, relValue, relUnit) {
|
|
819
|
+
const minuses = signs.replace(/[^-]/g, "").length;
|
|
820
|
+
const amount = +relValue * Math.pow(-1, minuses);
|
|
821
|
+
switch (relUnit.toLowerCase()) {
|
|
822
|
+
case "sec":
|
|
823
|
+
case "secs":
|
|
824
|
+
case "second":
|
|
825
|
+
case "seconds":
|
|
826
|
+
this.rs += amount;
|
|
827
|
+
break;
|
|
828
|
+
case "min":
|
|
829
|
+
case "mins":
|
|
830
|
+
case "minute":
|
|
831
|
+
case "minutes":
|
|
832
|
+
this.ri += amount;
|
|
833
|
+
break;
|
|
834
|
+
case "hour":
|
|
835
|
+
case "hours":
|
|
836
|
+
this.rh += amount;
|
|
837
|
+
break;
|
|
838
|
+
case "day":
|
|
839
|
+
case "days":
|
|
840
|
+
this.rd += amount;
|
|
841
|
+
break;
|
|
842
|
+
case "fortnight":
|
|
843
|
+
case "fortnights":
|
|
844
|
+
case "forthnight":
|
|
845
|
+
case "forthnights":
|
|
846
|
+
this.rd += amount * 14;
|
|
847
|
+
break;
|
|
848
|
+
case "week":
|
|
849
|
+
case "weeks":
|
|
850
|
+
this.rd += amount * 7;
|
|
851
|
+
break;
|
|
852
|
+
case "month":
|
|
853
|
+
case "months":
|
|
854
|
+
this.rm += amount;
|
|
855
|
+
break;
|
|
856
|
+
case "year":
|
|
857
|
+
case "years":
|
|
858
|
+
this.ry += amount;
|
|
859
|
+
break;
|
|
860
|
+
case "mon":
|
|
861
|
+
case "monday":
|
|
862
|
+
case "tue":
|
|
863
|
+
case "tuesday":
|
|
864
|
+
case "wed":
|
|
865
|
+
case "wednesday":
|
|
866
|
+
case "thu":
|
|
867
|
+
case "thursday":
|
|
868
|
+
case "fri":
|
|
869
|
+
case "friday":
|
|
870
|
+
case "sat":
|
|
871
|
+
case "saturday":
|
|
872
|
+
case "sun":
|
|
873
|
+
case "sunday":
|
|
874
|
+
this.resetTime();
|
|
875
|
+
this.weekday = lookupWeekday(relUnit, 7);
|
|
876
|
+
this.weekdayBehavior = 1;
|
|
877
|
+
this.rd += (amount > 0 ? amount - 1 : amount) * 7;
|
|
878
|
+
break;
|
|
879
|
+
case "weekday":
|
|
880
|
+
case "weekdays":
|
|
881
|
+
// todo
|
|
882
|
+
break;
|
|
883
|
+
}
|
|
884
|
+
},
|
|
885
|
+
},
|
|
886
|
+
dayText: {
|
|
887
|
+
regex: RegExp("^(" + reDaytext + ")", "i"),
|
|
888
|
+
name: "daytext",
|
|
889
|
+
callback(match, dayText) {
|
|
890
|
+
this.resetTime();
|
|
891
|
+
this.weekday = lookupWeekday(dayText, 0);
|
|
892
|
+
if (this.weekdayBehavior !== 2) {
|
|
893
|
+
this.weekdayBehavior = 1;
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
},
|
|
897
|
+
relativeTextWeek: {
|
|
898
|
+
regex: RegExp("^(" + reReltexttext + ")" + reSpace + "week", "i"),
|
|
899
|
+
name: "relativetextweek",
|
|
900
|
+
callback(match, relText) {
|
|
901
|
+
this.weekdayBehavior = 2;
|
|
902
|
+
switch (relText.toLowerCase()) {
|
|
903
|
+
case "this":
|
|
904
|
+
this.rd += 0;
|
|
905
|
+
break;
|
|
906
|
+
case "next":
|
|
907
|
+
this.rd += 7;
|
|
908
|
+
break;
|
|
909
|
+
case "last":
|
|
910
|
+
case "previous":
|
|
911
|
+
this.rd -= 7;
|
|
912
|
+
break;
|
|
913
|
+
}
|
|
914
|
+
if (isNaN(this.weekday)) {
|
|
915
|
+
this.weekday = 1;
|
|
916
|
+
}
|
|
917
|
+
},
|
|
918
|
+
},
|
|
919
|
+
monthFullOrMonthAbbr: {
|
|
920
|
+
regex: RegExp("^(" + reMonthFull + "|" + reMonthAbbr + ")", "i"),
|
|
921
|
+
name: "monthfull | monthabbr",
|
|
922
|
+
callback(match, month) {
|
|
923
|
+
return this.ymd(this.y, lookupMonth(month), this.d);
|
|
924
|
+
},
|
|
925
|
+
},
|
|
926
|
+
tzCorrection: {
|
|
927
|
+
regex: RegExp("^" + reTzCorrection, "i"),
|
|
928
|
+
name: "tzcorrection",
|
|
929
|
+
callback(tzCorrection) {
|
|
930
|
+
return this.zone(processTzCorrection(tzCorrection));
|
|
931
|
+
},
|
|
932
|
+
},
|
|
933
|
+
tzAbbr: {
|
|
934
|
+
regex: RegExp("^" + reTzAbbr),
|
|
935
|
+
name: "tzabbr",
|
|
936
|
+
callback(match, abbr) {
|
|
937
|
+
const offset = tzAbbrOffsets[abbr.toLowerCase()];
|
|
938
|
+
if (isNaN(offset)) {
|
|
939
|
+
return false;
|
|
940
|
+
}
|
|
941
|
+
return this.zone(offset);
|
|
942
|
+
},
|
|
943
|
+
},
|
|
944
|
+
ago: {
|
|
945
|
+
regex: /^ago/i,
|
|
946
|
+
name: "ago",
|
|
947
|
+
callback() {
|
|
948
|
+
this.ry = -this.ry;
|
|
949
|
+
this.rm = -this.rm;
|
|
950
|
+
this.rd = -this.rd;
|
|
951
|
+
this.rh = -this.rh;
|
|
952
|
+
this.ri = -this.ri;
|
|
953
|
+
this.rs = -this.rs;
|
|
954
|
+
this.rf = -this.rf;
|
|
955
|
+
},
|
|
956
|
+
},
|
|
957
|
+
year4: {
|
|
958
|
+
regex: RegExp("^" + reYear4),
|
|
959
|
+
name: "year4",
|
|
960
|
+
callback(match, year) {
|
|
961
|
+
this.y = +year;
|
|
962
|
+
return true;
|
|
963
|
+
},
|
|
964
|
+
},
|
|
965
|
+
whitespace: {
|
|
966
|
+
regex: /^[ .,\t]+/,
|
|
967
|
+
name: "whitespace",
|
|
968
|
+
// do nothing
|
|
969
|
+
},
|
|
970
|
+
dateShortWithTimeLong: {
|
|
971
|
+
regex: RegExp("^" + reDateNoYear + "t?" + reHour24 + "[:.]" + reMinute + "[:.]" + reSecond, "i"),
|
|
972
|
+
name: "dateshortwithtimelong",
|
|
973
|
+
callback(match, month, day, hour, minute, second) {
|
|
974
|
+
return this.ymd(this.y, lookupMonth(month), +day) && this.time(+hour, +minute, +second, 0);
|
|
975
|
+
},
|
|
976
|
+
},
|
|
977
|
+
dateShortWithTimeLong12: {
|
|
978
|
+
regex: RegExp("^" +
|
|
979
|
+
reDateNoYear +
|
|
980
|
+
reHour12 +
|
|
981
|
+
"[:.]" +
|
|
982
|
+
reMinute +
|
|
983
|
+
"[:.]" +
|
|
984
|
+
reSecondlz +
|
|
985
|
+
reSpaceOpt +
|
|
986
|
+
reMeridian, "i"),
|
|
987
|
+
name: "dateshortwithtimelong12",
|
|
988
|
+
callback(match, month, day, hour, minute, second, meridian) {
|
|
989
|
+
return (this.ymd(this.y, lookupMonth(month), +day) &&
|
|
990
|
+
this.time(processMeridian(+hour, meridian), +minute, +second, 0));
|
|
991
|
+
},
|
|
992
|
+
},
|
|
993
|
+
dateShortWithTimeShort: {
|
|
994
|
+
regex: RegExp("^" + reDateNoYear + "t?" + reHour24 + "[:.]" + reMinute, "i"),
|
|
995
|
+
name: "dateshortwithtimeshort",
|
|
996
|
+
callback(match, month, day, hour, minute) {
|
|
997
|
+
return this.ymd(this.y, lookupMonth(month), +day) && this.time(+hour, +minute, 0, 0);
|
|
998
|
+
},
|
|
999
|
+
},
|
|
1000
|
+
dateShortWithTimeShort12: {
|
|
1001
|
+
regex: RegExp("^" + reDateNoYear + reHour12 + "[:.]" + reMinutelz + reSpaceOpt + reMeridian, "i"),
|
|
1002
|
+
name: "dateshortwithtimeshort12",
|
|
1003
|
+
callback(match, month, day, hour, minute, meridian) {
|
|
1004
|
+
return (this.ymd(this.y, lookupMonth(month), +day) &&
|
|
1005
|
+
this.time(processMeridian(+hour, meridian), +minute, 0, 0));
|
|
1006
|
+
},
|
|
1007
|
+
},
|
|
1008
|
+
};
|
|
1009
|
+
const resultProto = {
|
|
1010
|
+
// date
|
|
1011
|
+
y: NaN,
|
|
1012
|
+
m: NaN,
|
|
1013
|
+
d: NaN,
|
|
1014
|
+
// time
|
|
1015
|
+
h: NaN,
|
|
1016
|
+
i: NaN,
|
|
1017
|
+
s: NaN,
|
|
1018
|
+
f: NaN,
|
|
1019
|
+
// relative shifts
|
|
1020
|
+
ry: 0,
|
|
1021
|
+
rm: 0,
|
|
1022
|
+
rd: 0,
|
|
1023
|
+
rh: 0,
|
|
1024
|
+
ri: 0,
|
|
1025
|
+
rs: 0,
|
|
1026
|
+
rf: 0,
|
|
1027
|
+
// weekday related shifts
|
|
1028
|
+
weekday: NaN,
|
|
1029
|
+
weekdayBehavior: 0,
|
|
1030
|
+
// first or last day of month
|
|
1031
|
+
// 0 none, 1 first, -1 last
|
|
1032
|
+
firstOrLastDayOfMonth: 0,
|
|
1033
|
+
// timezone correction in minutes
|
|
1034
|
+
z: NaN,
|
|
1035
|
+
// counters
|
|
1036
|
+
dates: 0,
|
|
1037
|
+
times: 0,
|
|
1038
|
+
zones: 0,
|
|
1039
|
+
// helper functions
|
|
1040
|
+
ymd(y, m, d) {
|
|
1041
|
+
if (this.dates > 0) {
|
|
1042
|
+
return false;
|
|
1043
|
+
}
|
|
1044
|
+
this.dates++;
|
|
1045
|
+
this.y = y;
|
|
1046
|
+
this.m = m;
|
|
1047
|
+
this.d = d;
|
|
1048
|
+
return true;
|
|
1049
|
+
},
|
|
1050
|
+
time(h, i, s, f) {
|
|
1051
|
+
if (this.times > 0) {
|
|
1052
|
+
return false;
|
|
1053
|
+
}
|
|
1054
|
+
this.times++;
|
|
1055
|
+
this.h = h;
|
|
1056
|
+
this.i = i;
|
|
1057
|
+
this.s = s;
|
|
1058
|
+
this.f = f;
|
|
1059
|
+
return true;
|
|
1060
|
+
},
|
|
1061
|
+
resetTime() {
|
|
1062
|
+
this.h = 0;
|
|
1063
|
+
this.i = 0;
|
|
1064
|
+
this.s = 0;
|
|
1065
|
+
this.f = 0;
|
|
1066
|
+
this.times = 0;
|
|
1067
|
+
return true;
|
|
1068
|
+
},
|
|
1069
|
+
zone(minutes) {
|
|
1070
|
+
if (this.zones <= 1) {
|
|
1071
|
+
this.zones++;
|
|
1072
|
+
this.z = minutes;
|
|
1073
|
+
return true;
|
|
1074
|
+
}
|
|
1075
|
+
return false;
|
|
1076
|
+
},
|
|
1077
|
+
toDate(relativeTo) {
|
|
1078
|
+
if (this.dates && !this.times) {
|
|
1079
|
+
this.h = this.i = this.s = this.f = 0;
|
|
1080
|
+
}
|
|
1081
|
+
// fill holes
|
|
1082
|
+
if (isNaN(this.y)) {
|
|
1083
|
+
this.y = relativeTo.getFullYear();
|
|
1084
|
+
}
|
|
1085
|
+
if (isNaN(this.m)) {
|
|
1086
|
+
this.m = relativeTo.getMonth();
|
|
1087
|
+
}
|
|
1088
|
+
if (isNaN(this.d)) {
|
|
1089
|
+
this.d = relativeTo.getDate();
|
|
1090
|
+
}
|
|
1091
|
+
if (isNaN(this.h)) {
|
|
1092
|
+
this.h = relativeTo.getHours();
|
|
1093
|
+
}
|
|
1094
|
+
if (isNaN(this.i)) {
|
|
1095
|
+
this.i = relativeTo.getMinutes();
|
|
1096
|
+
}
|
|
1097
|
+
if (isNaN(this.s)) {
|
|
1098
|
+
this.s = relativeTo.getSeconds();
|
|
1099
|
+
}
|
|
1100
|
+
if (isNaN(this.f)) {
|
|
1101
|
+
this.f = relativeTo.getMilliseconds();
|
|
1102
|
+
}
|
|
1103
|
+
// adjust special early
|
|
1104
|
+
switch (this.firstOrLastDayOfMonth) {
|
|
1105
|
+
case 1:
|
|
1106
|
+
this.d = 1;
|
|
1107
|
+
break;
|
|
1108
|
+
case -1:
|
|
1109
|
+
this.d = 0;
|
|
1110
|
+
this.m += 1;
|
|
1111
|
+
break;
|
|
1112
|
+
}
|
|
1113
|
+
if (!isNaN(this.weekday)) {
|
|
1114
|
+
const date = new Date(relativeTo.getTime());
|
|
1115
|
+
date.setFullYear(this.y, this.m, this.d);
|
|
1116
|
+
date.setHours(this.h, this.i, this.s, this.f);
|
|
1117
|
+
const dow = date.getDay();
|
|
1118
|
+
if (this.weekdayBehavior === 2) {
|
|
1119
|
+
// To make "this week" work, where the current day of week is a "sunday"
|
|
1120
|
+
if (dow === 0 && this.weekday !== 0) {
|
|
1121
|
+
this.weekday = -6;
|
|
1122
|
+
}
|
|
1123
|
+
// To make "sunday this week" work, where the current day of week is not a "sunday"
|
|
1124
|
+
if (this.weekday === 0 && dow !== 0) {
|
|
1125
|
+
this.weekday = 7;
|
|
1126
|
+
}
|
|
1127
|
+
this.d -= dow;
|
|
1128
|
+
this.d += this.weekday;
|
|
1129
|
+
}
|
|
1130
|
+
else {
|
|
1131
|
+
let diff = this.weekday - dow;
|
|
1132
|
+
// some PHP magic
|
|
1133
|
+
if ((this.rd < 0 && diff < 0) || (this.rd >= 0 && diff <= -this.weekdayBehavior)) {
|
|
1134
|
+
diff += 7;
|
|
1135
|
+
}
|
|
1136
|
+
if (this.weekday >= 0) {
|
|
1137
|
+
this.d += diff;
|
|
1138
|
+
}
|
|
1139
|
+
else {
|
|
1140
|
+
this.d -= 7 - (Math.abs(this.weekday) - dow);
|
|
1141
|
+
}
|
|
1142
|
+
this.weekday = NaN;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
// adjust relative
|
|
1146
|
+
this.y += this.ry;
|
|
1147
|
+
this.m += this.rm;
|
|
1148
|
+
this.d += this.rd;
|
|
1149
|
+
this.h += this.rh;
|
|
1150
|
+
this.i += this.ri;
|
|
1151
|
+
this.s += this.rs;
|
|
1152
|
+
this.f += this.rf;
|
|
1153
|
+
this.ry = this.rm = this.rd = 0;
|
|
1154
|
+
this.rh = this.ri = this.rs = this.rf = 0;
|
|
1155
|
+
const result = new Date(relativeTo.getTime());
|
|
1156
|
+
// since Date constructor treats years <= 99 as 1900+
|
|
1157
|
+
// it can't be used, thus this weird way
|
|
1158
|
+
result.setFullYear(this.y, this.m, this.d);
|
|
1159
|
+
result.setHours(this.h, this.i, this.s, this.f);
|
|
1160
|
+
// note: this is done twice in PHP
|
|
1161
|
+
// early when processing special relatives
|
|
1162
|
+
// and late
|
|
1163
|
+
// todo: check if the logic can be reduced
|
|
1164
|
+
// to just one time action
|
|
1165
|
+
switch (this.firstOrLastDayOfMonth) {
|
|
1166
|
+
case 1:
|
|
1167
|
+
result.setDate(1);
|
|
1168
|
+
break;
|
|
1169
|
+
case -1:
|
|
1170
|
+
result.setMonth(result.getMonth() + 1, 0);
|
|
1171
|
+
break;
|
|
1172
|
+
}
|
|
1173
|
+
// adjust timezone
|
|
1174
|
+
if (!isNaN(this.z) && result.getTimezoneOffset() !== this.z) {
|
|
1175
|
+
result.setUTCFullYear(result.getFullYear(), result.getMonth(), result.getDate());
|
|
1176
|
+
result.setUTCHours(result.getHours(), result.getMinutes(), result.getSeconds() - this.z, result.getMilliseconds());
|
|
1177
|
+
}
|
|
1178
|
+
return result;
|
|
1179
|
+
},
|
|
1180
|
+
};
|
|
1181
|
+
module.exports = function strtotime(str, now) {
|
|
1182
|
+
// discuss at: https://locutus.io/php/strtotime/
|
|
1183
|
+
// original by: Caio Ariede (https://caioariede.com)
|
|
1184
|
+
// improved by: Kevin van Zonneveld (https://kvz.io)
|
|
1185
|
+
// improved by: Caio Ariede (https://caioariede.com)
|
|
1186
|
+
// improved by: A. Matías Quezada (https://amatiasq.com)
|
|
1187
|
+
// improved by: preuter
|
|
1188
|
+
// improved by: Brett Zamir (https://brett-zamir.me)
|
|
1189
|
+
// improved by: Mirko Faber
|
|
1190
|
+
// input by: David
|
|
1191
|
+
// bugfixed by: Wagner B. Soares
|
|
1192
|
+
// bugfixed by: Artur Tchernychev
|
|
1193
|
+
// bugfixed by: Stephan Bösch-Plepelits (https://github.com/plepe)
|
|
1194
|
+
// reimplemented by: Rafał Kukawski
|
|
1195
|
+
// note 1: Examples all have a fixed timestamp to prevent
|
|
1196
|
+
// note 1: tests to fail because of variable time(zones)
|
|
1197
|
+
// example 1: strtotime('+1 day', 1129633200)
|
|
1198
|
+
// returns 1: 1129719600
|
|
1199
|
+
// example 2: strtotime('+1 week 2 days 4 hours 2 seconds', 1129633200)
|
|
1200
|
+
// returns 2: 1130425202
|
|
1201
|
+
// example 3: strtotime('last month', 1129633200)
|
|
1202
|
+
// returns 3: 1127041200
|
|
1203
|
+
// example 4: strtotime('2009-05-04 08:30:00+00')
|
|
1204
|
+
// returns 4: 1241425800
|
|
1205
|
+
// example 5: strtotime('2009-05-04 08:30:00+02:00')
|
|
1206
|
+
// returns 5: 1241418600
|
|
1207
|
+
// example 6: strtotime('2009-05-04 08:30:00 YWT')
|
|
1208
|
+
// returns 6: 1241454600
|
|
1209
|
+
// example 7: strtotime('10-JUL-17')
|
|
1210
|
+
// returns 7: 1499644800
|
|
1211
|
+
if (now == null) {
|
|
1212
|
+
now = Math.floor(Date.now() / 1000);
|
|
1213
|
+
}
|
|
1214
|
+
// the rule order is important
|
|
1215
|
+
// if multiple rules match, the longest match wins
|
|
1216
|
+
// if multiple rules match the same string, the first match wins
|
|
1217
|
+
const rules = [
|
|
1218
|
+
formats.yesterday,
|
|
1219
|
+
formats.now,
|
|
1220
|
+
formats.noon,
|
|
1221
|
+
formats.midnightOrToday,
|
|
1222
|
+
formats.tomorrow,
|
|
1223
|
+
formats.timestamp,
|
|
1224
|
+
formats.firstOrLastDay,
|
|
1225
|
+
formats.backOrFrontOf,
|
|
1226
|
+
// formats.weekdayOf, // not yet implemented
|
|
1227
|
+
formats.timeTiny12,
|
|
1228
|
+
formats.timeShort12,
|
|
1229
|
+
formats.timeLong12,
|
|
1230
|
+
formats.mssqltime,
|
|
1231
|
+
formats.oracledate,
|
|
1232
|
+
formats.timeShort24,
|
|
1233
|
+
formats.timeLong24,
|
|
1234
|
+
formats.iso8601long,
|
|
1235
|
+
formats.gnuNoColon,
|
|
1236
|
+
formats.iso8601noColon,
|
|
1237
|
+
formats.americanShort,
|
|
1238
|
+
formats.american,
|
|
1239
|
+
formats.iso8601date4,
|
|
1240
|
+
formats.iso8601dateSlash,
|
|
1241
|
+
formats.dateSlash,
|
|
1242
|
+
formats.gnuDateShortOrIso8601date2,
|
|
1243
|
+
formats.gnuDateShorter,
|
|
1244
|
+
formats.dateFull,
|
|
1245
|
+
formats.pointedDate4,
|
|
1246
|
+
formats.pointedDate2,
|
|
1247
|
+
formats.dateNoDay,
|
|
1248
|
+
formats.dateNoDayRev,
|
|
1249
|
+
formats.dateTextual,
|
|
1250
|
+
formats.dateNoYear,
|
|
1251
|
+
formats.dateNoYearRev,
|
|
1252
|
+
formats.dateNoColon,
|
|
1253
|
+
formats.xmlRpc,
|
|
1254
|
+
formats.xmlRpcNoColon,
|
|
1255
|
+
formats.soap,
|
|
1256
|
+
formats.wddx,
|
|
1257
|
+
formats.exif,
|
|
1258
|
+
formats.pgydotd,
|
|
1259
|
+
formats.isoWeekDay,
|
|
1260
|
+
formats.pgTextShort,
|
|
1261
|
+
formats.pgTextReverse,
|
|
1262
|
+
formats.clf,
|
|
1263
|
+
formats.year4,
|
|
1264
|
+
formats.ago,
|
|
1265
|
+
formats.dayText,
|
|
1266
|
+
formats.relativeTextWeek,
|
|
1267
|
+
formats.relativeText,
|
|
1268
|
+
formats.monthFullOrMonthAbbr,
|
|
1269
|
+
formats.tzCorrection,
|
|
1270
|
+
formats.tzAbbr,
|
|
1271
|
+
formats.dateShortWithTimeShort12,
|
|
1272
|
+
formats.dateShortWithTimeLong12,
|
|
1273
|
+
formats.dateShortWithTimeShort,
|
|
1274
|
+
formats.dateShortWithTimeLong,
|
|
1275
|
+
formats.relative,
|
|
1276
|
+
formats.whitespace,
|
|
1277
|
+
];
|
|
1278
|
+
const result = Object.create(resultProto);
|
|
1279
|
+
while (str.length) {
|
|
1280
|
+
let longestMatch = null;
|
|
1281
|
+
let finalRule = null;
|
|
1282
|
+
for (let i = 0, l = rules.length; i < l; i++) {
|
|
1283
|
+
const format = rules[i];
|
|
1284
|
+
const match = str.match(format.regex);
|
|
1285
|
+
if (match) {
|
|
1286
|
+
if (!longestMatch || match[0].length > longestMatch[0].length) {
|
|
1287
|
+
longestMatch = match;
|
|
1288
|
+
finalRule = format;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
if (!finalRule ||
|
|
1293
|
+
(finalRule.callback && finalRule.callback.apply(result, longestMatch) === false)) {
|
|
1294
|
+
return false;
|
|
1295
|
+
}
|
|
1296
|
+
str = str.substr(longestMatch[0].length);
|
|
1297
|
+
finalRule = null;
|
|
1298
|
+
longestMatch = null;
|
|
1299
|
+
}
|
|
1300
|
+
return Math.floor(result.toDate(new Date(now * 1000)) / 1000);
|
|
1301
|
+
};
|