forked from zetavg/date-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate-parser.js
117 lines (113 loc) · 3.5 KB
/
date-parser.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Generated by CoffeeScript 1.12.6
(function() {
var DateParser;
DateParser = {
LOCALES: {
'zh-TW': require("./lib/zh-TW")
},
DEFAULT_LOCALE: 'zh-TW',
DEFAULT_TIMEZONE: 'Asia/Taipei',
locale: function(locale) {
var ref;
if (this.LOCALES[locale]) {
this.DEFAULT_LOCALE = locale;
return (ref = this.LOCALES[locale].testStrings) != null ? ref.forEach((function(_this) {
return function(s) {
return _this.parse(s);
};
})(this)) : void 0;
} else {
return console.error("No such locale: " + locale);
}
},
timezone: function(timezone) {
return this.DEFAULT_TIMEZONE = timezone;
},
parse: function(text, timezone, locale) {
var error, expression, expressions, i, len, ref, ref1, ref2, ref3, ref4, ref5, result;
if (!text) {
text = '';
}
if (!locale) {
locale = this.DEFAULT_LOCALE;
}
if (!timezone) {
timezone = this.DEFAULT_TIMEZONE;
}
expressions = (ref = this.LOCALES[locale]) != null ? ref.expressions : void 0;
if ((ref1 = this.LOCALES[locale]) != null ? (ref2 = ref1.words) != null ? ref2.interjections : void 0 : void 0) {
text = text.replace(RegExp((ref3 = this.LOCALES[locale]) != null ? (ref4 = ref3.words) != null ? ref4.interjections : void 0 : void 0, 'g'), '');
}
if (!expressions) {
console.error("No such locale: " + locale);
return null;
}
ref5 = this.LOCALES[locale].expressions;
for (i = 0, len = ref5.length; i < len; i++) {
expression = ref5[i];
try {
result = expression(text, timezone);
if (result) {
return result;
}
} catch (error1) {
error = error1;
console.error('error', error);
}
}
return null;
},
number2integer: function(text, locale) {
var ref;
if (!text) {
text = '';
}
if (!locale) {
locale = this.DEFAULT_LOCALE;
}
return (ref = this.LOCALES[locale]) != null ? typeof ref.number2integer === "function" ? ref.number2integer(text) : void 0 : void 0;
},
time2object: function(text, locale) {
var ref;
if (!text) {
text = '';
}
if (!locale) {
locale = this.DEFAULT_LOCALE;
}
return (ref = this.LOCALES[locale]) != null ? typeof ref.time2object === "function" ? ref.time2object(text) : void 0 : void 0;
},
dayTime2moment: function(text, locale) {
var ref;
if (!text) {
text = '';
}
if (!locale) {
locale = this.DEFAULT_LOCALE;
}
return (ref = this.LOCALES[locale]) != null ? typeof ref.dayTime2moment === "function" ? ref.dayTime2moment(text) : void 0 : void 0;
},
date2object: function(text, locale) {
var ref;
if (!text) {
text = '';
}
if (!locale) {
locale = this.DEFAULT_LOCALE;
}
return (ref = this.LOCALES[locale]) != null ? typeof ref.date2object === "function" ? ref.date2object(text) : void 0 : void 0;
},
dateExpression2moment: function(text, locale) {
var ref;
if (!text) {
text = '';
}
if (!locale) {
locale = this.DEFAULT_LOCALE;
}
return (ref = this.LOCALES[locale]) != null ? typeof ref.dateExpression2moment === "function" ? ref.dateExpression2moment(text) : void 0 : void 0;
}
};
DateParser.locale('zh-TW');
module.exports = DateParser;
}).call(this);