This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphantomjs_dateparse_polyfill.js
66 lines (59 loc) · 2.4 KB
/
phantomjs_dateparse_polyfill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(function () {
var map = {
Jan: "01",
Feb: "02",
Mar: "03",
Apr: "04",
May: "05",
Jun: "06",
Jul: "07",
Aug: "08",
Sep: "09",
Oct: "10",
Nov: "11",
Dec: "12"
};
var rx = /(\d{4}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{1,2}) /i;
function fixStringDate (sDate) {
//If sDate contains NNNN abc [N]N covert it to NNNN-NN-NN and add "T"
//to turn it into an ISO8601 date string which PhantomJS can parse.
var pDate = rx.exec(sDate);
if (pDate) {
sDate = sDate.replace(
rx,
pDate[1] + "-" + map[pDate[2]] + "-" + (pDate[3].length == 1 ? "0" : "") + pDate[3] + "T"
);
}
return sDate;
}
Date = (function (JSDate) {
function dateCtorDecorator() {
var newDate;
if (arguments.length === 1 && typeof arguments[0] === "string") {
newDate = new JSDate(fixStringDate(arguments[0]))
} else {
//Can't get apply to work against JSDate's constructor.
//It always returns the current date and time. :-(
if (arguments.length == 1)
newDate = new JSDate(arguments[0]);
else if (arguments.length == 2)
newDate = new JSDate(arguments[0], arguments[1]);
else if (arguments.length == 3)
newDate = new JSDate(arguments[0], arguments[1], arguments[2]);
else if (arguments.length == 4)
newDate = new JSDate(arguments[0], arguments[1], arguments[2], arguments[3]);
else if (arguments.length == 5)
newDate = new JSDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
else if (arguments.length == 6)
newDate = new JSDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
else if (arguments.length == 7)
newDate = new JSDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]);
}
return newDate;
}
dateCtorDecorator.parse = function (sDate) {
return JSDate.parse(fixStringDate(sDate));
}
return dateCtorDecorator;
})(Date)
})();