date-and-time 1.0.0 → 2.1.0
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/EXTEND.md +28 -10
- package/LOCALE.md +1 -0
- package/PLUGINS.md +185 -63
- package/README.md +91 -76
- package/date-and-time.js +140 -102
- package/date-and-time.min.js +12 -12
- package/esm/date-and-time.es.js +138 -100
- package/esm/date-and-time.es.min.js +13 -12
- package/esm/date-and-time.mjs +138 -100
- package/esm/locale/ar.es.js +1 -1
- package/esm/locale/ar.mjs +1 -1
- package/esm/locale/az.es.js +1 -1
- package/esm/locale/az.mjs +1 -1
- package/esm/locale/bn.es.js +1 -1
- package/esm/locale/bn.mjs +1 -1
- package/esm/locale/cs.es.js +1 -1
- package/esm/locale/cs.mjs +1 -1
- package/esm/locale/de.es.js +1 -1
- package/esm/locale/de.mjs +1 -1
- package/esm/locale/dk.es.js +1 -1
- package/esm/locale/dk.mjs +1 -1
- package/esm/locale/el.es.js +7 -5
- package/esm/locale/el.mjs +7 -5
- package/esm/locale/en.es.js +3 -2
- package/esm/locale/en.mjs +3 -2
- package/esm/locale/es.es.js +1 -1
- package/esm/locale/es.mjs +1 -1
- package/esm/locale/fa.es.js +1 -1
- package/esm/locale/fa.mjs +1 -1
- package/esm/locale/fr.es.js +1 -1
- package/esm/locale/fr.mjs +1 -1
- package/esm/locale/hi.es.js +1 -1
- package/esm/locale/hi.mjs +1 -1
- package/esm/locale/hu.es.js +1 -1
- package/esm/locale/hu.mjs +1 -1
- package/esm/locale/id.es.js +1 -1
- package/esm/locale/id.mjs +1 -1
- package/esm/locale/it.es.js +1 -1
- package/esm/locale/it.mjs +1 -1
- package/esm/locale/ja.es.js +1 -1
- package/esm/locale/ja.mjs +1 -1
- package/esm/locale/jv.es.js +1 -1
- package/esm/locale/jv.mjs +1 -1
- package/esm/locale/ko.es.js +1 -1
- package/esm/locale/ko.mjs +1 -1
- package/esm/locale/my.es.js +1 -1
- package/esm/locale/my.mjs +1 -1
- package/esm/locale/nl.es.js +7 -5
- package/esm/locale/nl.mjs +7 -5
- package/esm/locale/pa-in.es.js +1 -1
- package/esm/locale/pa-in.mjs +1 -1
- package/esm/locale/pl.es.js +7 -5
- package/esm/locale/pl.mjs +7 -5
- package/esm/locale/pt.es.js +1 -1
- package/esm/locale/pt.mjs +1 -1
- package/esm/locale/ro.es.js +1 -1
- package/esm/locale/ro.mjs +1 -1
- package/esm/locale/ru.es.js +1 -1
- package/esm/locale/ru.mjs +1 -1
- package/esm/locale/rw.es.js +1 -1
- package/esm/locale/rw.mjs +1 -1
- package/esm/locale/sr.es.js +1 -1
- package/esm/locale/sr.mjs +1 -1
- package/esm/locale/sv.es.js +22 -0
- package/esm/locale/sv.mjs +22 -0
- package/esm/locale/th.es.js +1 -1
- package/esm/locale/th.mjs +1 -1
- package/esm/locale/tr.es.js +1 -1
- package/esm/locale/tr.mjs +1 -1
- package/esm/locale/uk.es.js +10 -8
- package/esm/locale/uk.mjs +10 -8
- package/esm/locale/uz.es.js +1 -1
- package/esm/locale/uz.mjs +1 -1
- package/esm/locale/vi.es.js +1 -1
- package/esm/locale/vi.mjs +1 -1
- package/esm/locale/zh-cn.es.js +1 -1
- package/esm/locale/zh-cn.mjs +1 -1
- package/esm/locale/zh-tw.es.js +1 -1
- package/esm/locale/zh-tw.mjs +1 -1
- package/esm/plugin/day-of-week.es.js +1 -1
- package/esm/plugin/day-of-week.mjs +1 -1
- package/esm/plugin/meridiem.es.js +20 -11
- package/esm/plugin/meridiem.mjs +20 -11
- package/esm/plugin/microsecond.es.js +1 -1
- package/esm/plugin/microsecond.mjs +1 -1
- package/esm/plugin/ordinal.es.js +1 -1
- package/esm/plugin/ordinal.mjs +1 -1
- package/esm/plugin/timespan.es.js +1 -1
- package/esm/plugin/timespan.mjs +1 -1
- package/esm/plugin/timezone.es.js +73 -0
- package/esm/plugin/timezone.mjs +73 -0
- package/esm/plugin/two-digit-year.es.js +1 -6
- package/esm/plugin/two-digit-year.mjs +1 -6
- package/locale/ar.js +2 -2
- package/locale/az.js +2 -2
- package/locale/bn.js +2 -2
- package/locale/cs.js +2 -2
- package/locale/de.js +2 -2
- package/locale/dk.js +2 -2
- package/locale/el.js +8 -6
- package/locale/en.js +4 -3
- package/locale/es.js +2 -2
- package/locale/fa.js +2 -2
- package/locale/fr.js +2 -2
- package/locale/hi.js +2 -2
- package/locale/hu.js +2 -2
- package/locale/id.js +2 -2
- package/locale/it.js +2 -2
- package/locale/ja.js +2 -2
- package/locale/jv.js +2 -2
- package/locale/ko.js +2 -2
- package/locale/my.js +2 -2
- package/locale/nl.js +8 -6
- package/locale/pa-in.js +3 -3
- package/locale/pl.js +8 -6
- package/locale/pt.js +2 -2
- package/locale/ro.js +2 -2
- package/locale/ru.js +2 -2
- package/locale/rw.js +2 -2
- package/locale/sr.js +2 -2
- package/locale/sv.js +30 -0
- package/locale/th.js +2 -2
- package/locale/tr.js +2 -2
- package/locale/uk.js +11 -9
- package/locale/uz.js +2 -2
- package/locale/vi.js +2 -2
- package/locale/zh-cn.js +3 -3
- package/locale/zh-tw.js +3 -3
- package/package.json +4 -4
- package/plugin/day-of-week.js +3 -3
- package/plugin/meridiem.js +21 -12
- package/plugin/microsecond.js +2 -2
- package/plugin/ordinal.js +2 -2
- package/plugin/timespan.js +2 -2
- package/plugin/timezone.js +81 -0
- package/plugin/two-digit-year.js +3 -8
package/esm/date-and-time.mjs
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* @preserve date-and-time (c) KNOWLEDGECODE | MIT
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
locales = {},
|
|
5
|
+
var locales = {},
|
|
7
6
|
plugins = {},
|
|
8
7
|
lang = 'en',
|
|
9
8
|
_res = {
|
|
@@ -40,10 +39,11 @@ var date = {},
|
|
|
40
39
|
ddd: function (d/*, formatString*/) { return this.res.ddd[d.getDay()]; },
|
|
41
40
|
dd: function (d/*, formatString*/) { return this.res.dd[d.getDay()]; },
|
|
42
41
|
Z: function (d/*, formatString*/) {
|
|
43
|
-
var offset = d.
|
|
44
|
-
return (offset > 0 ? '-' : '+') + ('000' + Math.abs(offset - offset % 100 * 0.4)).slice(-4);
|
|
42
|
+
var offset = d.getTimezoneOffset() / 0.6 | 0;
|
|
43
|
+
return (offset > 0 ? '-' : '+') + ('000' + Math.abs(offset - (offset % 100 * 0.4 | 0))).slice(-4);
|
|
45
44
|
},
|
|
46
|
-
post: function (str) { return str; }
|
|
45
|
+
post: function (str) { return str; },
|
|
46
|
+
res: _res
|
|
47
47
|
},
|
|
48
48
|
_parser = {
|
|
49
49
|
YYYY: function (str/*, formatString */) { return this.exec(/^\d{4}/, str); },
|
|
@@ -104,39 +104,38 @@ var date = {},
|
|
|
104
104
|
}
|
|
105
105
|
return { value: index, length: length };
|
|
106
106
|
},
|
|
107
|
-
pre: function (str) { return str; }
|
|
107
|
+
pre: function (str) { return str; },
|
|
108
|
+
res: _res
|
|
108
109
|
},
|
|
109
|
-
|
|
110
|
-
var
|
|
111
|
-
var Locale = function (r) {
|
|
112
|
-
if (r) { this.res = r; }
|
|
113
|
-
};
|
|
110
|
+
extend = function (base, props, override, res) {
|
|
111
|
+
var obj = {}, key;
|
|
114
112
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
113
|
+
for (key in base) {
|
|
114
|
+
obj[key] = base[key];
|
|
115
|
+
}
|
|
116
|
+
for (key in props || {}) {
|
|
117
|
+
if (!(!!override ^ !!obj[key])) {
|
|
118
|
+
obj[key] = props[key];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (res) {
|
|
122
|
+
obj.res = res;
|
|
123
|
+
}
|
|
124
|
+
return obj;
|
|
125
|
+
},
|
|
126
|
+
proto = {
|
|
127
|
+
_formatter: _formatter,
|
|
128
|
+
_parser: _parser
|
|
129
|
+
},
|
|
130
|
+
localized_proto,
|
|
131
|
+
date;
|
|
133
132
|
|
|
134
133
|
/**
|
|
135
134
|
* Compiling a format string
|
|
136
135
|
* @param {string} formatString - a format string
|
|
137
136
|
* @returns {Array.<string>} a compiled object
|
|
138
137
|
*/
|
|
139
|
-
|
|
138
|
+
proto.compile = function (formatString) {
|
|
140
139
|
var re = /\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g, keys, pattern = [formatString];
|
|
141
140
|
|
|
142
141
|
while ((keys = re.exec(formatString))) {
|
|
@@ -152,12 +151,13 @@ date.compile = function (formatString) {
|
|
|
152
151
|
* @param {boolean} [utc] - output as UTC
|
|
153
152
|
* @returns {string} a formatted string
|
|
154
153
|
*/
|
|
155
|
-
|
|
156
|
-
var pattern = typeof arg === 'string' ?
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
proto.format = function (dateObj, arg, utc) {
|
|
155
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
156
|
+
offset = dateObj.getTimezoneOffset(),
|
|
157
|
+
d = ctx.addMinutes(dateObj, utc ? offset : 0),
|
|
158
|
+
formatter = ctx._formatter, str = '';
|
|
159
159
|
|
|
160
|
-
d.
|
|
160
|
+
d.getTimezoneOffset = function () { return utc ? 0 : offset; };
|
|
161
161
|
for (var i = 1, len = pattern.length, token; i < len; i++) {
|
|
162
162
|
token = pattern[i];
|
|
163
163
|
str += formatter[token] ? formatter.post(formatter[token](d, pattern[0])) : token.replace(/\[(.*)]/, '$1');
|
|
@@ -171,10 +171,10 @@ date.format = function (dateObj, arg, utc) {
|
|
|
171
171
|
* @param {string|Array.<string>} arg - a format string or its compiled object
|
|
172
172
|
* @returns {Object} a date structure
|
|
173
173
|
*/
|
|
174
|
-
|
|
175
|
-
var pattern = typeof arg === 'string' ?
|
|
174
|
+
proto.preparse = function (dateString, arg) {
|
|
175
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
176
176
|
dt = { Y: 1970, M: 1, D: 1, H: 0, A: 0, h: 0, m: 0, s: 0, S: 0, Z: 0, _index: 0, _length: 0, _match: 0 },
|
|
177
|
-
comment = /\[(.*)]/, parser =
|
|
177
|
+
comment = /\[(.*)]/, parser = ctx._parser, offset = 0;
|
|
178
178
|
|
|
179
179
|
dateString = parser.pre(dateString);
|
|
180
180
|
for (var i = 1, len = pattern.length, token, result; i < len; i++) {
|
|
@@ -185,7 +185,7 @@ date.preparse = function (dateString, arg) {
|
|
|
185
185
|
break;
|
|
186
186
|
}
|
|
187
187
|
offset += result.length;
|
|
188
|
-
dt[token.charAt(0)] = result.value;
|
|
188
|
+
dt[result.token || token.charAt(0)] = result.value;
|
|
189
189
|
dt._match++;
|
|
190
190
|
} else if (token === dateString.charAt(offset) || token === ' ') {
|
|
191
191
|
offset++;
|
|
@@ -204,24 +204,6 @@ date.preparse = function (dateString, arg) {
|
|
|
204
204
|
return dt;
|
|
205
205
|
};
|
|
206
206
|
|
|
207
|
-
/**
|
|
208
|
-
* Validation
|
|
209
|
-
* @param {Object|string} arg1 - a date structure or a date string
|
|
210
|
-
* @param {string|Array.<string>} [arg2] - a format string or its compiled object
|
|
211
|
-
* @returns {boolean} whether the date string is a valid date
|
|
212
|
-
*/
|
|
213
|
-
date.isValid = function (arg1, arg2) {
|
|
214
|
-
var dt = typeof arg1 === 'string' ? date.preparse(arg1, arg2) : arg1,
|
|
215
|
-
last = [31, 28 + date.isLeapYear(dt.Y) | 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][dt.M - 1];
|
|
216
|
-
|
|
217
|
-
return !(
|
|
218
|
-
dt._index < 1 || dt._length < 1 || dt._index - dt._length || dt._match < 1 ||
|
|
219
|
-
dt.Y < 1 || dt.Y > 9999 || dt.M < 1 || dt.M > 12 || dt.D < 1 || dt.D > last ||
|
|
220
|
-
dt.H < 0 || dt.H > 23 || dt.m < 0 || dt.m > 59 || dt.s < 0 || dt.s > 59 || dt.S < 0 || dt.S > 999 ||
|
|
221
|
-
dt.Z < -720 || dt.Z > 840
|
|
222
|
-
);
|
|
223
|
-
};
|
|
224
|
-
|
|
225
207
|
/**
|
|
226
208
|
* Parsing a Date and Time string
|
|
227
209
|
* @param {string} dateString - a date string
|
|
@@ -229,10 +211,10 @@ date.isValid = function (arg1, arg2) {
|
|
|
229
211
|
* @param {boolean} [utc] - input as UTC
|
|
230
212
|
* @returns {Date} a constructed date
|
|
231
213
|
*/
|
|
232
|
-
|
|
233
|
-
var dt =
|
|
214
|
+
proto.parse = function (dateString, arg, utc) {
|
|
215
|
+
var ctx = this || date, dt = ctx.preparse(dateString, arg);
|
|
234
216
|
|
|
235
|
-
if (
|
|
217
|
+
if (ctx.isValid(dt)) {
|
|
236
218
|
dt.M -= dt.Y < 100 ? 22801 : 1; // 22801 = 1900 * 12 + 1
|
|
237
219
|
if (utc || dt.Z) {
|
|
238
220
|
return new Date(Date.UTC(dt.Y, dt.M, dt.D, dt.H, dt.m + dt.Z, dt.s, dt.S));
|
|
@@ -242,6 +224,24 @@ date.parse = function (dateString, arg, utc) {
|
|
|
242
224
|
return new Date(NaN);
|
|
243
225
|
};
|
|
244
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Validation
|
|
229
|
+
* @param {Object|string} arg1 - a date structure or a date string
|
|
230
|
+
* @param {string|Array.<string>} [arg2] - a format string or its compiled object
|
|
231
|
+
* @returns {boolean} whether the date string is a valid date
|
|
232
|
+
*/
|
|
233
|
+
proto.isValid = function (arg1, arg2) {
|
|
234
|
+
var ctx = this || date, dt = typeof arg1 === 'string' ? ctx.preparse(arg1, arg2) : arg1,
|
|
235
|
+
last = [31, 28 + ctx.isLeapYear(dt.Y) | 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][dt.M - 1];
|
|
236
|
+
|
|
237
|
+
return !(
|
|
238
|
+
dt._index < 1 || dt._length < 1 || dt._index - dt._length || dt._match < 1 ||
|
|
239
|
+
dt.Y < 1 || dt.Y > 9999 || dt.M < 1 || dt.M > 12 || dt.D < 1 || dt.D > last ||
|
|
240
|
+
dt.H < 0 || dt.H > 23 || dt.m < 0 || dt.m > 59 || dt.s < 0 || dt.s > 59 || dt.S < 0 || dt.S > 999 ||
|
|
241
|
+
dt.Z < -720 || dt.Z > 840
|
|
242
|
+
);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
245
|
/**
|
|
246
246
|
* Transforming a Date and Time string
|
|
247
247
|
* @param {string} dateString - a date string
|
|
@@ -250,8 +250,9 @@ date.parse = function (dateString, arg, utc) {
|
|
|
250
250
|
* @param {boolean} [utc] - output as UTC
|
|
251
251
|
* @returns {string} a formatted string
|
|
252
252
|
*/
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
proto.transform = function (dateString, arg1, arg2, utc) {
|
|
254
|
+
const ctx = this || date;
|
|
255
|
+
return ctx.format(ctx.parse(dateString, arg1), arg2, utc);
|
|
255
256
|
};
|
|
256
257
|
|
|
257
258
|
/**
|
|
@@ -260,8 +261,8 @@ date.transform = function (dateString, arg1, arg2, utc) {
|
|
|
260
261
|
* @param {number} years - number of years to add
|
|
261
262
|
* @returns {Date} a date after adding the value
|
|
262
263
|
*/
|
|
263
|
-
|
|
264
|
-
return date.addMonths(dateObj, years * 12);
|
|
264
|
+
proto.addYears = function (dateObj, years) {
|
|
265
|
+
return (this || date).addMonths(dateObj, years * 12);
|
|
265
266
|
};
|
|
266
267
|
|
|
267
268
|
/**
|
|
@@ -270,7 +271,7 @@ date.addYears = function (dateObj, years) {
|
|
|
270
271
|
* @param {number} months - number of months to add
|
|
271
272
|
* @returns {Date} a date after adding the value
|
|
272
273
|
*/
|
|
273
|
-
|
|
274
|
+
proto.addMonths = function (dateObj, months) {
|
|
274
275
|
var d = new Date(dateObj.getTime());
|
|
275
276
|
|
|
276
277
|
d.setMonth(d.getMonth() + months);
|
|
@@ -283,7 +284,7 @@ date.addMonths = function (dateObj, months) {
|
|
|
283
284
|
* @param {number} days - number of days to add
|
|
284
285
|
* @returns {Date} a date after adding the value
|
|
285
286
|
*/
|
|
286
|
-
|
|
287
|
+
proto.addDays = function (dateObj, days) {
|
|
287
288
|
var d = new Date(dateObj.getTime());
|
|
288
289
|
|
|
289
290
|
d.setDate(d.getDate() + days);
|
|
@@ -296,8 +297,8 @@ date.addDays = function (dateObj, days) {
|
|
|
296
297
|
* @param {number} hours - number of hours to add
|
|
297
298
|
* @returns {Date} a date after adding the value
|
|
298
299
|
*/
|
|
299
|
-
|
|
300
|
-
return date.addMinutes(dateObj, hours * 60);
|
|
300
|
+
proto.addHours = function (dateObj, hours) {
|
|
301
|
+
return (this || date).addMinutes(dateObj, hours * 60);
|
|
301
302
|
};
|
|
302
303
|
|
|
303
304
|
/**
|
|
@@ -306,8 +307,8 @@ date.addHours = function (dateObj, hours) {
|
|
|
306
307
|
* @param {number} minutes - number of minutes to add
|
|
307
308
|
* @returns {Date} a date after adding the value
|
|
308
309
|
*/
|
|
309
|
-
|
|
310
|
-
return date.addSeconds(dateObj, minutes * 60);
|
|
310
|
+
proto.addMinutes = function (dateObj, minutes) {
|
|
311
|
+
return (this || date).addSeconds(dateObj, minutes * 60);
|
|
311
312
|
};
|
|
312
313
|
|
|
313
314
|
/**
|
|
@@ -316,8 +317,8 @@ date.addMinutes = function (dateObj, minutes) {
|
|
|
316
317
|
* @param {number} seconds - number of seconds to add
|
|
317
318
|
* @returns {Date} a date after adding the value
|
|
318
319
|
*/
|
|
319
|
-
|
|
320
|
-
return date.addMilliseconds(dateObj, seconds * 1000);
|
|
320
|
+
proto.addSeconds = function (dateObj, seconds) {
|
|
321
|
+
return (this || date).addMilliseconds(dateObj, seconds * 1000);
|
|
321
322
|
};
|
|
322
323
|
|
|
323
324
|
/**
|
|
@@ -326,7 +327,7 @@ date.addSeconds = function (dateObj, seconds) {
|
|
|
326
327
|
* @param {number} milliseconds - number of milliseconds to add
|
|
327
328
|
* @returns {Date} a date after adding the value
|
|
328
329
|
*/
|
|
329
|
-
|
|
330
|
+
proto.addMilliseconds = function (dateObj, milliseconds) {
|
|
330
331
|
return new Date(dateObj.getTime() + milliseconds);
|
|
331
332
|
};
|
|
332
333
|
|
|
@@ -336,7 +337,7 @@ date.addMilliseconds = function (dateObj, milliseconds) {
|
|
|
336
337
|
* @param {Date} date2 - a Date object
|
|
337
338
|
* @returns {Object} a result object subtracting date2 from date1
|
|
338
339
|
*/
|
|
339
|
-
|
|
340
|
+
proto.subtract = function (date1, date2) {
|
|
340
341
|
var delta = date1.getTime() - date2.getTime();
|
|
341
342
|
|
|
342
343
|
return {
|
|
@@ -363,7 +364,7 @@ date.subtract = function (date1, date2) {
|
|
|
363
364
|
* @param {number} y - year
|
|
364
365
|
* @returns {boolean} whether year is leap year
|
|
365
366
|
*/
|
|
366
|
-
|
|
367
|
+
proto.isLeapYear = function (y) {
|
|
367
368
|
return (!(y % 4) && !!(y % 100)) || !(y % 400);
|
|
368
369
|
};
|
|
369
370
|
|
|
@@ -373,22 +374,62 @@ date.isLeapYear = function (y) {
|
|
|
373
374
|
* @param {Date} date2 - a Date object
|
|
374
375
|
* @returns {boolean} whether the two dates are the same day (time is ignored)
|
|
375
376
|
*/
|
|
376
|
-
|
|
377
|
+
proto.isSameDay = function (date1, date2) {
|
|
377
378
|
return date1.toDateString() === date2.toDateString();
|
|
378
379
|
};
|
|
379
380
|
|
|
380
381
|
/**
|
|
381
|
-
*
|
|
382
|
-
* @param {
|
|
383
|
-
* @param {
|
|
382
|
+
* Defining new locale
|
|
383
|
+
* @param {string} code - language code
|
|
384
|
+
* @param {Function} locale - locale installer
|
|
385
|
+
* @returns {string} current language code
|
|
386
|
+
*/
|
|
387
|
+
proto.locale = function (code, locale) {
|
|
388
|
+
if (!locales[code]) {
|
|
389
|
+
locales[code] = locale;
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Defining new plugin
|
|
395
|
+
* @param {string} name - plugin name
|
|
396
|
+
* @param {Function} plugin - plugin installer
|
|
397
|
+
* @returns {void}
|
|
398
|
+
*/
|
|
399
|
+
proto.plugin = function (name, plugin) {
|
|
400
|
+
if (!plugins[name]) {
|
|
401
|
+
plugins[name] = plugin;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
localized_proto = extend(proto);
|
|
406
|
+
date = extend(proto);
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Changing locale
|
|
410
|
+
* @param {Function|string} [locale] - locale object | language code
|
|
384
411
|
* @returns {string} current language code
|
|
385
412
|
*/
|
|
386
|
-
date.locale = function (
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
413
|
+
date.locale = function (locale) {
|
|
414
|
+
var install = typeof locale === 'function' ? locale : date.locale[locale];
|
|
415
|
+
|
|
416
|
+
if (!install) {
|
|
417
|
+
return lang;
|
|
418
|
+
}
|
|
419
|
+
lang = install(proto);
|
|
420
|
+
|
|
421
|
+
var extension = locales[lang] || {};
|
|
422
|
+
var res = extend(_res, extension.res, true);
|
|
423
|
+
var formatter = extend(_formatter, extension.formatter, true, res);
|
|
424
|
+
var parser = extend(_parser, extension.parser, true, res);
|
|
425
|
+
|
|
426
|
+
date._formatter = localized_proto._formatter = formatter;
|
|
427
|
+
date._parser = localized_proto._parser = parser;
|
|
428
|
+
|
|
429
|
+
for (var plugin in plugins) {
|
|
430
|
+
date.extend(plugins[plugin]);
|
|
391
431
|
}
|
|
432
|
+
|
|
392
433
|
return lang;
|
|
393
434
|
};
|
|
394
435
|
|
|
@@ -398,35 +439,32 @@ date.locale = function (code, locale) {
|
|
|
398
439
|
* @returns {void}
|
|
399
440
|
*/
|
|
400
441
|
date.extend = function (extension) {
|
|
442
|
+
var res = extend(date._parser.res, extension.res);
|
|
401
443
|
var extender = extension.extender || {};
|
|
402
444
|
|
|
445
|
+
date._formatter = extend(date._formatter, extension.formatter, false, res);
|
|
446
|
+
date._parser = extend(date._parser, extension.parser, false, res);
|
|
447
|
+
|
|
403
448
|
for (var key in extender) {
|
|
404
449
|
if (!date[key]) {
|
|
405
450
|
date[key] = extender[key];
|
|
406
451
|
}
|
|
407
452
|
}
|
|
408
|
-
if (extension.formatter || extension.parser || extension.res) {
|
|
409
|
-
customize(lang, locales[lang], extension);
|
|
410
|
-
}
|
|
411
453
|
};
|
|
412
454
|
|
|
413
455
|
/**
|
|
414
|
-
* Importing
|
|
415
|
-
* @param {Function|string}
|
|
416
|
-
* @param {Object} [plugin] - plugin object
|
|
456
|
+
* Importing plugin
|
|
457
|
+
* @param {Function|string} plugin - plugin object | plugin name
|
|
417
458
|
* @returns {void}
|
|
418
459
|
*/
|
|
419
|
-
date.plugin = function (
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
} else {
|
|
425
|
-
(typeof name === 'function' ? name : date.plugin[name] || function () {})(date);
|
|
460
|
+
date.plugin = function (plugin) {
|
|
461
|
+
var install = typeof plugin === 'function' ? plugin : date.plugin[plugin];
|
|
462
|
+
|
|
463
|
+
if (install) {
|
|
464
|
+
date.extend(plugins[install(proto, localized_proto)] || {});
|
|
426
465
|
}
|
|
427
466
|
};
|
|
428
467
|
|
|
429
|
-
|
|
430
|
-
date.locale(lang, {});
|
|
468
|
+
var date$1 = date;
|
|
431
469
|
|
|
432
|
-
export default
|
|
470
|
+
export { date$1 as default };
|
package/esm/locale/ar.es.js
CHANGED
package/esm/locale/ar.mjs
CHANGED
package/esm/locale/az.es.js
CHANGED
package/esm/locale/az.mjs
CHANGED
package/esm/locale/bn.es.js
CHANGED
package/esm/locale/bn.mjs
CHANGED
package/esm/locale/cs.es.js
CHANGED
package/esm/locale/cs.mjs
CHANGED
package/esm/locale/de.es.js
CHANGED
package/esm/locale/de.mjs
CHANGED
package/esm/locale/dk.es.js
CHANGED
package/esm/locale/dk.mjs
CHANGED
package/esm/locale/el.es.js
CHANGED
|
@@ -9,8 +9,10 @@ var el = function (date) {
|
|
|
9
9
|
|
|
10
10
|
date.locale(code, {
|
|
11
11
|
res: {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
MMMM: [
|
|
13
|
+
['Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 'Απρίλιος', 'Μάιος', 'Ιούνιος', 'Ιούλιος', 'Αύγουστος', 'Σεπτέμβριος', 'Οκτώβριος', 'Νοέμβριος', 'Δεκέμβριος'],
|
|
14
|
+
['Ιανουαρίου', 'Φεβρουαρίου', 'Μαρτίου', 'Απριλίου', 'Μαΐου', 'Ιουνίου', 'Ιουλίου', 'Αυγούστου', 'Σεπτεμβρίου', 'Οκτωβρίου', 'Νοεμβρίου', 'Δεκεμβρίου']
|
|
15
|
+
],
|
|
14
16
|
MMM: ['Ιαν', 'Φεβ', 'Μαρ', 'Απρ', 'Μαϊ', 'Ιουν', 'Ιουλ', 'Αυγ', 'Σεπ', 'Οκτ', 'Νοε', 'Δεκ'],
|
|
15
17
|
dddd: ['Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο'],
|
|
16
18
|
ddd: ['Κυρ', 'Δευ', 'Τρι', 'Τετ', 'Πεμ', 'Παρ', 'Σαβ'],
|
|
@@ -19,7 +21,7 @@ var el = function (date) {
|
|
|
19
21
|
},
|
|
20
22
|
formatter: {
|
|
21
23
|
MMMM: function (d, formatString) {
|
|
22
|
-
return this.res[
|
|
24
|
+
return this.res.MMMM[/D.*MMMM/.test(formatString) | 0][d.getMonth()];
|
|
23
25
|
},
|
|
24
26
|
hh: function (d) {
|
|
25
27
|
return ('0' + d.getHours() % 12).slice(-2);
|
|
@@ -30,7 +32,7 @@ var el = function (date) {
|
|
|
30
32
|
},
|
|
31
33
|
parser: {
|
|
32
34
|
MMMM: function (str, formatString) {
|
|
33
|
-
var result = this.find(this.res[
|
|
35
|
+
var result = this.find(this.res.MMMM[/D.*MMMM/.test(formatString) | 0], str);
|
|
34
36
|
result.value++;
|
|
35
37
|
return result;
|
|
36
38
|
}
|
|
@@ -39,4 +41,4 @@ var el = function (date) {
|
|
|
39
41
|
return code;
|
|
40
42
|
};
|
|
41
43
|
|
|
42
|
-
export default
|
|
44
|
+
export { el as default };
|
package/esm/locale/el.mjs
CHANGED
|
@@ -9,8 +9,10 @@ var el = function (date) {
|
|
|
9
9
|
|
|
10
10
|
date.locale(code, {
|
|
11
11
|
res: {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
MMMM: [
|
|
13
|
+
['Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 'Απρίλιος', 'Μάιος', 'Ιούνιος', 'Ιούλιος', 'Αύγουστος', 'Σεπτέμβριος', 'Οκτώβριος', 'Νοέμβριος', 'Δεκέμβριος'],
|
|
14
|
+
['Ιανουαρίου', 'Φεβρουαρίου', 'Μαρτίου', 'Απριλίου', 'Μαΐου', 'Ιουνίου', 'Ιουλίου', 'Αυγούστου', 'Σεπτεμβρίου', 'Οκτωβρίου', 'Νοεμβρίου', 'Δεκεμβρίου']
|
|
15
|
+
],
|
|
14
16
|
MMM: ['Ιαν', 'Φεβ', 'Μαρ', 'Απρ', 'Μαϊ', 'Ιουν', 'Ιουλ', 'Αυγ', 'Σεπ', 'Οκτ', 'Νοε', 'Δεκ'],
|
|
15
17
|
dddd: ['Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο'],
|
|
16
18
|
ddd: ['Κυρ', 'Δευ', 'Τρι', 'Τετ', 'Πεμ', 'Παρ', 'Σαβ'],
|
|
@@ -19,7 +21,7 @@ var el = function (date) {
|
|
|
19
21
|
},
|
|
20
22
|
formatter: {
|
|
21
23
|
MMMM: function (d, formatString) {
|
|
22
|
-
return this.res[
|
|
24
|
+
return this.res.MMMM[/D.*MMMM/.test(formatString) | 0][d.getMonth()];
|
|
23
25
|
},
|
|
24
26
|
hh: function (d) {
|
|
25
27
|
return ('0' + d.getHours() % 12).slice(-2);
|
|
@@ -30,7 +32,7 @@ var el = function (date) {
|
|
|
30
32
|
},
|
|
31
33
|
parser: {
|
|
32
34
|
MMMM: function (str, formatString) {
|
|
33
|
-
var result = this.find(this.res[
|
|
35
|
+
var result = this.find(this.res.MMMM[/D.*MMMM/.test(formatString) | 0], str);
|
|
34
36
|
result.value++;
|
|
35
37
|
return result;
|
|
36
38
|
}
|
|
@@ -39,4 +41,4 @@ var el = function (date) {
|
|
|
39
41
|
return code;
|
|
40
42
|
};
|
|
41
43
|
|
|
42
|
-
export default
|
|
44
|
+
export { el as default };
|
package/esm/locale/en.es.js
CHANGED
package/esm/locale/en.mjs
CHANGED
package/esm/locale/es.es.js
CHANGED
package/esm/locale/es.mjs
CHANGED
package/esm/locale/fa.es.js
CHANGED
package/esm/locale/fa.mjs
CHANGED
package/esm/locale/fr.es.js
CHANGED
package/esm/locale/fr.mjs
CHANGED
package/esm/locale/hi.es.js
CHANGED
package/esm/locale/hi.mjs
CHANGED