-
Notifications
You must be signed in to change notification settings - Fork 3
/
date-parser.js
117 lines (113 loc) · 3.55 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.8.0
(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, result, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
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 (_error) {
error = _error;
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);