date-and-time 2.1.2 → 2.3.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.
Files changed (54) hide show
  1. package/PLUGINS.md +42 -26
  2. package/README.md +88 -95
  3. package/date-and-time.d.ts +304 -0
  4. package/date-and-time.js +85 -74
  5. package/date-and-time.min.js +11 -10
  6. package/esm/date-and-time.es.js +85 -74
  7. package/esm/date-and-time.es.min.js +10 -10
  8. package/esm/date-and-time.mjs +85 -74
  9. package/esm/plugin/timezone.es.js +8 -6
  10. package/esm/plugin/timezone.mjs +8 -6
  11. package/locale/ar.d.ts +1 -0
  12. package/locale/az.d.ts +1 -0
  13. package/locale/bn.d.ts +1 -0
  14. package/locale/cs.d.ts +1 -0
  15. package/locale/de.d.ts +1 -0
  16. package/locale/dk.d.ts +1 -0
  17. package/locale/el.d.ts +1 -0
  18. package/locale/en.d.ts +1 -0
  19. package/locale/es.d.ts +1 -0
  20. package/locale/fa.d.ts +1 -0
  21. package/locale/fr.d.ts +1 -0
  22. package/locale/hi.d.ts +1 -0
  23. package/locale/hu.d.ts +1 -0
  24. package/locale/id.d.ts +1 -0
  25. package/locale/it.d.ts +1 -0
  26. package/locale/ja.d.ts +1 -0
  27. package/locale/jv.d.ts +1 -0
  28. package/locale/ko.d.ts +1 -0
  29. package/locale/my.d.ts +1 -0
  30. package/locale/nl.d.ts +1 -0
  31. package/locale/pa-in.d.ts +1 -0
  32. package/locale/pl.d.ts +1 -0
  33. package/locale/pt.d.ts +1 -0
  34. package/locale/ro.d.ts +1 -0
  35. package/locale/ru.d.ts +1 -0
  36. package/locale/rw.d.ts +1 -0
  37. package/locale/sr.d.ts +1 -0
  38. package/locale/sv.d.ts +1 -0
  39. package/locale/th.d.ts +1 -0
  40. package/locale/tr.d.ts +1 -0
  41. package/locale/uk.d.ts +1 -0
  42. package/locale/uz.d.ts +1 -0
  43. package/locale/vi.d.ts +1 -0
  44. package/locale/zh-cn.d.ts +1 -0
  45. package/locale/zh-tw.d.ts +1 -0
  46. package/package.json +7 -4
  47. package/plugin/day-of-week.d.ts +1 -0
  48. package/plugin/meridiem.d.ts +1 -0
  49. package/plugin/microsecond.d.ts +1 -0
  50. package/plugin/ordinal.d.ts +1 -0
  51. package/plugin/timespan.d.ts +24 -0
  52. package/plugin/timezone.d.ts +79 -0
  53. package/plugin/timezone.js +8 -6
  54. package/plugin/two-digit-year.d.ts +1 -0
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Formatting date and time objects (Date -> String)
3
+ * @param dateObj - A Date object
4
+ * @param formatString - A format string
5
+ * @param [utc] - Output as UTC
6
+ * @returns A formatted string
7
+ */
8
+ export function format(dateObj: Date, formatString: string, utc?: boolean): string;
9
+
10
+ /**
11
+ * Formatting date and time objects (Date -> String)
12
+ * @param dateObj - A Date object
13
+ * @param compiledObj - A compiled object of format string
14
+ * @param [utc] - Output as UTC
15
+ * @returns A formatted string
16
+ */
17
+ export function format(dateObj: Date, compiledObj: string[], utc?: boolean): string;
18
+
19
+ /**
20
+ * Parsing date and time strings (String -> Date)
21
+ * @param dateString - A date and time string
22
+ * @param formatString - A format string
23
+ * @param [utc] - Input as UTC
24
+ * @returns A Date object
25
+ */
26
+ export function parse(dateString: string, formatString: string, utc?: boolean): Date;
27
+
28
+ /**
29
+ * Parsing date and time strings (String -> Date)
30
+ * @param dateString - A date and time string
31
+ * @param compiledObj - A compiled object of format string
32
+ * @param [utc] - Input as UTC
33
+ * @returns A Date object
34
+ */
35
+ export function parse(dateString: string, compiledObj: string[], utc?: boolean): Date;
36
+
37
+ /**
38
+ * Compiling format strings
39
+ * @param formatString - A format string
40
+ * @returns A compiled object
41
+ */
42
+ export function compile(formatString: string): string[];
43
+
44
+ /** Preparse result object */
45
+ export type PreparseResult = {
46
+ /** Year */
47
+ Y: number;
48
+ /** Month */
49
+ M: number;
50
+ /** Day */
51
+ D: number;
52
+ /** 24-hour */
53
+ H: number;
54
+ /** Meridiem */
55
+ A: number;
56
+ /** 12-hour */
57
+ h: number;
58
+ /** Minute */
59
+ m: number;
60
+ /** Second */
61
+ s: number;
62
+ /** Millisecond */
63
+ S: number;
64
+ /** Timezone offset */
65
+ Z: number;
66
+ /** Pointer offset */
67
+ _index: number;
68
+ /** Length of the date string */
69
+ _length: number;
70
+ /** Token matching count */
71
+ _match: number;
72
+ };
73
+
74
+ /**
75
+ * Pre-parsing date and time strings
76
+ * @param dateString - A date and time string
77
+ * @param formatString - A format string
78
+ * @returns A pre-parsed result object
79
+ */
80
+ export function preparse(dateString: string, formatString: string): PreparseResult;
81
+
82
+ /**
83
+ * Pre-parsing date and time strings
84
+ * @param dateString - A date and time string
85
+ * @param compiledObj - A compiled object of format string
86
+ * @returns A pre-parsed result object
87
+ */
88
+ export function preparse(dateString: string, compiledObj: string[]): PreparseResult;
89
+
90
+ /**
91
+ * Date and time string validation
92
+ * @param dateString - A date and time string
93
+ * @param formatString - A format string
94
+ * @returns Whether the date and time string is a valid date and time
95
+ */
96
+ export function isValid(dateString: string, formatString: string): boolean;
97
+
98
+ /**
99
+ * Date and time string validation
100
+ * @param dateString - A date and time string
101
+ * @param compiledObj - A compiled object of format string
102
+ * @returns Whether the date and time string is a valid date and time
103
+ */
104
+ export function isValid(dateString: string, compiledObj: string[]): boolean;
105
+
106
+ /**
107
+ * Date and time string validation
108
+ * @param preparseResult - A pre-parsed result object
109
+ * @returns Whether the date and time string is a valid date and time
110
+ */
111
+ export function isValid(preparseResult: PreparseResult): boolean;
112
+
113
+ /**
114
+ * Format transformation of date and time strings (String -> String)
115
+ * @param dateString - A date and time string
116
+ * @param formatString1 - A format string before transformation
117
+ * @param formatString2 - A format string after transformation
118
+ * @param [utc] - Output as UTC
119
+ * @returns A formatted string
120
+ */
121
+ export function transform(dateString: string, formatString1: string, formatString2: string, utc?: boolean): string;
122
+
123
+ /**
124
+ * Format transformation of date and time strings (String -> String)
125
+ * @param dateString - A date and time string
126
+ * @param formatString - A format string before transformation
127
+ * @param compiledObj - A compiled object of format string after transformation
128
+ * @param [utc] - Output as UTC
129
+ * @returns A formatted string
130
+ */
131
+ export function transform(dateString: string, formatString: string, compiledObj: string[], utc?: boolean): string;
132
+
133
+ /**
134
+ * Format transformation of date and time strings (String -> String)
135
+ * @param dateString - A date and time string
136
+ * @param compiledObj - A compiled object of format string before transformation
137
+ * @param formatString - A format string after transformation
138
+ * @param [utc] - Output as UTC
139
+ * @returns A formatted string
140
+ */
141
+ export function transform(dateString: string, compiledObj: string[], formatString: string, utc?: boolean): string;
142
+
143
+ /**
144
+ * Format transformation of date and time strings (String -> String)
145
+ * @param dateString - A date and time string
146
+ * @param compiledObj1 - A compiled object of format string before transformation
147
+ * @param compiledObj2 - A compiled object of format string after transformation
148
+ * @param [utc] - Output as UTC
149
+ * @returns A formatted string
150
+ */
151
+ export function transform(dateString: string, compiledObj1: string[], compiledObj2: string[], utc?: boolean): string;
152
+
153
+ /**
154
+ * Adding years
155
+ * @param dateObj - A Date object
156
+ * @param years - Number of years to add
157
+ * @returns The Date object after adding the value
158
+ */
159
+ export function addYears(dateObj: Date, years: number): Date;
160
+
161
+ /**
162
+ * Adding months
163
+ * @param dateObj - A Date object
164
+ * @param months - Number of months to add
165
+ * @returns The Date object after adding the value
166
+ */
167
+ export function addMonths(dateObj: Date, months: number): Date;
168
+
169
+ /**
170
+ * Adding days
171
+ * @param dateObj - A Date object
172
+ * @param days - Number of days to add
173
+ * @returns The Date object after adding the value
174
+ */
175
+ export function addDays(dateObj: Date, days: number): Date;
176
+
177
+ /**
178
+ * Adding hours
179
+ * @param dateObj - A Date object
180
+ * @param hours - Number of hours to add
181
+ * @returns The Date object after adding the value
182
+ */
183
+ export function addHours(dateObj: Date, hours: number): Date;
184
+
185
+ /**
186
+ * Adding minutes
187
+ * @param dateObj - A Date object
188
+ * @param minutes - Number of minutes to add
189
+ * @returns The Date object after adding the value
190
+ */
191
+ export function addMinutes(dateObj: Date, minutes: number): Date;
192
+
193
+ /**
194
+ * Adding seconds
195
+ * @param dateObj - A Date object
196
+ * @param seconds - Number of seconds to add
197
+ * @returns The Date object after adding the value
198
+ */
199
+ export function addSeconds(dateObj: Date, seconds: number): Date;
200
+
201
+ /**
202
+ * Adding milliseconds
203
+ * @param dateObj - A Date object
204
+ * @param milliseconds - Number of milliseconds to add
205
+ * @returns The Date object after adding the value
206
+ */
207
+ export function addMilliseconds(dateObj: Date, milliseconds: number): Date;
208
+
209
+ /** Subtraction result object */
210
+ export type SubtractResult = {
211
+ /** Returns the result value in milliseconds. */
212
+ toMilliseconds: () => number;
213
+ /** Returns the result value in seconds. */
214
+ toSeconds: () => number;
215
+ /** Returns the result value in minutes. This value might be a real number. */
216
+ toMinutes: () => number;
217
+ /** Returns the result value in hours. This value might be a real number. */
218
+ toHours: () => number;
219
+ /** Returns the result value in days. This value might be a real number. */
220
+ toDays: () => number;
221
+ };
222
+
223
+ /**
224
+ * Subtracting two dates (date1 - date2)
225
+ * @param date1 - A Date object
226
+ * @param date2 - A Date object
227
+ * @returns The result object of subtracting date2 from date1
228
+ */
229
+ export function subtract(date1: Date, date2: Date): SubtractResult;
230
+
231
+ /**
232
+ * Whether a year is a leap year
233
+ * @param y - A year to check
234
+ * @returns Whether the year is a leap year
235
+ */
236
+ export function isLeapYear(y: number): boolean;
237
+
238
+ /**
239
+ * Comparison of two dates
240
+ * @param date1 - A Date object
241
+ * @param date2 - A Date object
242
+ * @returns Whether the two dates are the same day (time is ignored)
243
+ */
244
+ export function isSameDay(date1: Date, date2: Date): boolean;
245
+
246
+ /** Locale installer */
247
+ export type Locale = (proto: unknown) => string;
248
+
249
+ /**
250
+ * Changing locales
251
+ * @param [locale] - A locale installer
252
+ * @returns The current language code
253
+ */
254
+ export function locale(locale?: Locale): string;
255
+
256
+ /**
257
+ * Changing locales
258
+ * @param [locale] - A language code
259
+ * @returns The current language code
260
+ */
261
+ export function locale(locale?: string): string;
262
+
263
+ export type Resources = {
264
+ [key: string]: string[] | string[][]
265
+ };
266
+
267
+ export type Formatter = {
268
+ };
269
+
270
+ export type Parser = {
271
+ };
272
+
273
+ export type Extender = {
274
+ [key: string]: (...args: any) => any
275
+ };
276
+
277
+ /** Extension object */
278
+ export type Extension = {
279
+ res?: Resources,
280
+ formatter?: Formatter,
281
+ parser?: Parser,
282
+ extender?: Extender
283
+ };
284
+
285
+ /**
286
+ * Functional extension
287
+ * @param extension - An extension object
288
+ */
289
+ export function extend(extension: Extension): void;
290
+
291
+ /** Plugin installer */
292
+ export type Plugin = (proto: unknown, localized_proto?: unknown) => string;
293
+
294
+ /**
295
+ * Importing plugins
296
+ * @param plugin - A plugin installer
297
+ */
298
+ export function plugin(plugin: Plugin): void;
299
+
300
+ /**
301
+ * Importing plugins
302
+ * @param plugin - A plugin name
303
+ */
304
+ export function plugin(plugin: string): void;
package/date-and-time.js CHANGED
@@ -48,6 +48,11 @@
48
48
  var offset = d.getTimezoneOffset() / 0.6 | 0;
49
49
  return (offset > 0 ? '-' : '+') + ('000' + Math.abs(offset - (offset % 100 * 0.4 | 0))).slice(-4);
50
50
  },
51
+ ZZ: function (d/*, formatString*/) {
52
+ var offset = d.getTimezoneOffset();
53
+ var mod = Math.abs(offset);
54
+ return (offset > 0 ? '-' : '+') + ('0' + (mod / 60 | 0)).slice(-2) + ':' + ('0' + mod % 60).slice(-2);
55
+ },
51
56
  post: function (str) { return str; },
52
57
  res: _res
53
58
  },
@@ -93,6 +98,10 @@
93
98
  result.value = (result.value / 100 | 0) * -60 - result.value % 100;
94
99
  return result;
95
100
  },
101
+ ZZ: function (str/*, formatString */) {
102
+ var arr = /^([\+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
103
+ return { value: 0 - ((arr[1] + arr[2] | 0) * 60 + (arr[1] + arr[3] | 0)), length: arr[0].length };
104
+ },
96
105
  h12: function (h, a) { return (h === 12 ? 0 : h) + a * 12; },
97
106
  exec: function (re, str) {
98
107
  var result = (re.exec(str) || [''])[0];
@@ -137,9 +146,9 @@
137
146
  date;
138
147
 
139
148
  /**
140
- * Compiling a format string
141
- * @param {string} formatString - a format string
142
- * @returns {Array.<string>} a compiled object
149
+ * Compiling format strings
150
+ * @param {string} formatString - A format string
151
+ * @returns {Array.<string>} A compiled object
143
152
  */
144
153
  proto.compile = function (formatString) {
145
154
  var re = /\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g, keys, pattern = [formatString];
@@ -151,11 +160,11 @@
151
160
  };
152
161
 
153
162
  /**
154
- * Formatting a Date and Time
155
- * @param {Date} dateObj - a Date object
156
- * @param {string|Array.<string>} arg - a format string or its compiled object
157
- * @param {boolean} [utc] - output as UTC
158
- * @returns {string} a formatted string
163
+ * Formatting date and time objects (Date -> String)
164
+ * @param {Date} dateObj - A Date object
165
+ * @param {string|Array.<string>} arg - A format string or its compiled object
166
+ * @param {boolean} [utc] - Output as UTC
167
+ * @returns {string} A formatted string
159
168
  */
160
169
  proto.format = function (dateObj, arg, utc) {
161
170
  var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
@@ -172,10 +181,11 @@
172
181
  };
173
182
 
174
183
  /**
175
- * Pre-parsing a Date and Time string
176
- * @param {string} dateString - a date string
177
- * @param {string|Array.<string>} arg - a format string or its compiled object
178
- * @returns {Object} a date structure
184
+ * Pre-parsing date and time strings
185
+ * @param {string} dateString - A date and time string
186
+ * @param {string|Array.<string>} arg - A format string or its compiled object
187
+ * @param {boolean} [utc] - Input as UTC
188
+ * @returns {Object} A pre-parsed result object
179
189
  */
180
190
  proto.preparse = function (dateString, arg) {
181
191
  var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
@@ -211,18 +221,19 @@
211
221
  };
212
222
 
213
223
  /**
214
- * Parsing a Date and Time string
215
- * @param {string} dateString - a date string
216
- * @param {string|Array.<string>} arg - a format string or its compiled object
217
- * @param {boolean} [utc] - input as UTC
218
- * @returns {Date} a constructed date
224
+ * Parsing of date and time string (String -> Date)
225
+ * @param {string} dateString - A date-time string
226
+ * @param {string|Array.<string>} arg - A format string or its compiled object
227
+ * @param {boolean} [utc] - Input as UTC
228
+ * @returns {Date} A Date object
219
229
  */
220
230
  proto.parse = function (dateString, arg, utc) {
221
- var ctx = this || date, dt = ctx.preparse(dateString, arg);
231
+ var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
232
+ dt = ctx.preparse(dateString, pattern);
222
233
 
223
234
  if (ctx.isValid(dt)) {
224
235
  dt.M -= dt.Y < 100 ? 22801 : 1; // 22801 = 1900 * 12 + 1
225
- if (utc || dt.Z) {
236
+ if (utc || ~ctx._parser.find(pattern, 'ZZ').value) {
226
237
  return new Date(Date.UTC(dt.Y, dt.M, dt.D, dt.H, dt.m + dt.Z, dt.s, dt.S));
227
238
  }
228
239
  return new Date(dt.Y, dt.M, dt.D, dt.H, dt.m, dt.s, dt.S);
@@ -231,10 +242,10 @@
231
242
  };
232
243
 
233
244
  /**
234
- * Validation
235
- * @param {Object|string} arg1 - a date structure or a date string
236
- * @param {string|Array.<string>} [arg2] - a format string or its compiled object
237
- * @returns {boolean} whether the date string is a valid date
245
+ * Date and time string validation
246
+ * @param {Object|string} arg1 - A pre-parsed result object or a date and time string
247
+ * @param {string|Array.<string>} [arg2] - A format string or its compiled object
248
+ * @returns {boolean} Whether the date and time string is a valid date and time
238
249
  */
239
250
  proto.isValid = function (arg1, arg2) {
240
251
  var ctx = this || date, dt = typeof arg1 === 'string' ? ctx.preparse(arg1, arg2) : arg1,
@@ -249,12 +260,12 @@
249
260
  };
250
261
 
251
262
  /**
252
- * Transforming a Date and Time string
253
- * @param {string} dateString - a date string
254
- * @param {string|Array.<string>} arg1 - a format string or its compiled object
255
- * @param {string|Array.<string>} arg2 - a transformed format string or its compiled object
256
- * @param {boolean} [utc] - output as UTC
257
- * @returns {string} a formatted string
263
+ * Format transformation of date and time string (String -> String)
264
+ * @param {string} dateString - A date and time string
265
+ * @param {string|Array.<string>} arg1 - A format string or its compiled object before transformation
266
+ * @param {string|Array.<string>} arg2 - A format string or its compiled object after transformation
267
+ * @param {boolean} [utc] - Output as UTC
268
+ * @returns {string} A formatted string
258
269
  */
259
270
  proto.transform = function (dateString, arg1, arg2, utc) {
260
271
  const ctx = this || date;
@@ -263,9 +274,9 @@
263
274
 
264
275
  /**
265
276
  * Adding years
266
- * @param {Date} dateObj - a date object
267
- * @param {number} years - number of years to add
268
- * @returns {Date} a date after adding the value
277
+ * @param {Date} dateObj - A Date object
278
+ * @param {number} years - Number of years to add
279
+ * @returns {Date} The Date object after adding the value
269
280
  */
270
281
  proto.addYears = function (dateObj, years) {
271
282
  return (this || date).addMonths(dateObj, years * 12);
@@ -273,9 +284,9 @@
273
284
 
274
285
  /**
275
286
  * Adding months
276
- * @param {Date} dateObj - a date object
277
- * @param {number} months - number of months to add
278
- * @returns {Date} a date after adding the value
287
+ * @param {Date} dateObj - A Date object
288
+ * @param {number} months - Number of months to add
289
+ * @returns {Date} The Date object after adding the value
279
290
  */
280
291
  proto.addMonths = function (dateObj, months) {
281
292
  var d = new Date(dateObj.getTime());
@@ -286,9 +297,9 @@
286
297
 
287
298
  /**
288
299
  * Adding days
289
- * @param {Date} dateObj - a date object
290
- * @param {number} days - number of days to add
291
- * @returns {Date} a date after adding the value
300
+ * @param {Date} dateObj - A Date object
301
+ * @param {number} days - Number of days to add
302
+ * @returns {Date} The Date object after adding the value
292
303
  */
293
304
  proto.addDays = function (dateObj, days) {
294
305
  var d = new Date(dateObj.getTime());
@@ -299,9 +310,9 @@
299
310
 
300
311
  /**
301
312
  * Adding hours
302
- * @param {Date} dateObj - a date object
303
- * @param {number} hours - number of hours to add
304
- * @returns {Date} a date after adding the value
313
+ * @param {Date} dateObj - A Date object
314
+ * @param {number} hours - Number of hours to add
315
+ * @returns {Date} The Date object after adding the value
305
316
  */
306
317
  proto.addHours = function (dateObj, hours) {
307
318
  return (this || date).addMinutes(dateObj, hours * 60);
@@ -309,9 +320,9 @@
309
320
 
310
321
  /**
311
322
  * Adding minutes
312
- * @param {Date} dateObj - a date object
313
- * @param {number} minutes - number of minutes to add
314
- * @returns {Date} a date after adding the value
323
+ * @param {Date} dateObj - A Date object
324
+ * @param {number} minutes - Number of minutes to add
325
+ * @returns {Date} The Date object after adding the value
315
326
  */
316
327
  proto.addMinutes = function (dateObj, minutes) {
317
328
  return (this || date).addSeconds(dateObj, minutes * 60);
@@ -319,9 +330,9 @@
319
330
 
320
331
  /**
321
332
  * Adding seconds
322
- * @param {Date} dateObj - a date object
323
- * @param {number} seconds - number of seconds to add
324
- * @returns {Date} a date after adding the value
333
+ * @param {Date} dateObj - A Date object
334
+ * @param {number} seconds - Number of seconds to add
335
+ * @returns {Date} The Date object after adding the value
325
336
  */
326
337
  proto.addSeconds = function (dateObj, seconds) {
327
338
  return (this || date).addMilliseconds(dateObj, seconds * 1000);
@@ -329,19 +340,19 @@
329
340
 
330
341
  /**
331
342
  * Adding milliseconds
332
- * @param {Date} dateObj - a date object
333
- * @param {number} milliseconds - number of milliseconds to add
334
- * @returns {Date} a date after adding the value
343
+ * @param {Date} dateObj - A Date object
344
+ * @param {number} milliseconds - Number of milliseconds to add
345
+ * @returns {Date} The Date object after adding the value
335
346
  */
336
347
  proto.addMilliseconds = function (dateObj, milliseconds) {
337
348
  return new Date(dateObj.getTime() + milliseconds);
338
349
  };
339
350
 
340
351
  /**
341
- * Subtracting two dates
342
- * @param {Date} date1 - a Date object
343
- * @param {Date} date2 - a Date object
344
- * @returns {Object} a result object subtracting date2 from date1
352
+ * Subtracting two dates (date1 - date2)
353
+ * @param {Date} date1 - A Date object
354
+ * @param {Date} date2 - A Date object
355
+ * @returns {Object} The result object of subtracting date2 from date1
345
356
  */
346
357
  proto.subtract = function (date1, date2) {
347
358
  var delta = date1.getTime() - date2.getTime();
@@ -366,9 +377,9 @@
366
377
  };
367
378
 
368
379
  /**
369
- * Whether year is leap year
370
- * @param {number} y - year
371
- * @returns {boolean} whether year is leap year
380
+ * Whether a year is a leap year
381
+ * @param {number} y - A year to check
382
+ * @returns {boolean} Whether the year is a leap year
372
383
  */
373
384
  proto.isLeapYear = function (y) {
374
385
  return (!(y % 4) && !!(y % 100)) || !(y % 400);
@@ -376,19 +387,19 @@
376
387
 
377
388
  /**
378
389
  * Comparison of two dates
379
- * @param {Date} date1 - a Date object
380
- * @param {Date} date2 - a Date object
381
- * @returns {boolean} whether the two dates are the same day (time is ignored)
390
+ * @param {Date} date1 - A Date object
391
+ * @param {Date} date2 - A Date object
392
+ * @returns {boolean} Whether the two dates are the same day (time is ignored)
382
393
  */
383
394
  proto.isSameDay = function (date1, date2) {
384
395
  return date1.toDateString() === date2.toDateString();
385
396
  };
386
397
 
387
398
  /**
388
- * Defining new locale
389
- * @param {string} code - language code
390
- * @param {Function} locale - locale installer
391
- * @returns {string} current language code
399
+ * Definition of new locale
400
+ * @param {string} code - A language code
401
+ * @param {Function} locale - A locale installer
402
+ * @returns {void}
392
403
  */
393
404
  proto.locale = function (code, locale) {
394
405
  if (!locales[code]) {
@@ -397,9 +408,9 @@
397
408
  };
398
409
 
399
410
  /**
400
- * Defining new plugin
401
- * @param {string} name - plugin name
402
- * @param {Function} plugin - plugin installer
411
+ * Definition of new plugin
412
+ * @param {string} name - A plugin name
413
+ * @param {Function} plugin - A plugin installer
403
414
  * @returns {void}
404
415
  */
405
416
  proto.plugin = function (name, plugin) {
@@ -412,9 +423,9 @@
412
423
  date = extend(proto);
413
424
 
414
425
  /**
415
- * Changing locale
416
- * @param {Function|string} [locale] - locale object | language code
417
- * @returns {string} current language code
426
+ * Changing locales
427
+ * @param {Function|string} [locale] - A locale installer or language code
428
+ * @returns {string} The current language code
418
429
  */
419
430
  date.locale = function (locale) {
420
431
  var install = typeof locale === 'function' ? locale : date.locale[locale];
@@ -440,8 +451,8 @@
440
451
  };
441
452
 
442
453
  /**
443
- * Feature extension
444
- * @param {Object} extension - extension object
454
+ * Functional extension
455
+ * @param {Object} extension - An extension object
445
456
  * @returns {void}
446
457
  */
447
458
  date.extend = function (extension) {
@@ -459,8 +470,8 @@
459
470
  };
460
471
 
461
472
  /**
462
- * Importing plugin
463
- * @param {Function|string} plugin - plugin object | plugin name
473
+ * Importing plugins
474
+ * @param {Function|string} plugin - A plugin installer or plugin name
464
475
  * @returns {void}
465
476
  */
466
477
  date.plugin = function (plugin) {
@@ -4,13 +4,14 @@
4
4
  'use strict';(function(p,m){"object"===typeof exports&&"undefined"!==typeof module?module.exports=m():"function"===typeof define&&define.amd?define(m):(p="undefined"!==typeof globalThis?globalThis:p||self,p.date=m())})(this,function(){var p={},m={},r="en",t={MMMM:"January February March April May June July August September October November December".split(" "),MMM:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),dddd:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),
5
5
  ddd:"Sun Mon Tue Wed Thu Fri Sat".split(" "),dd:"Su Mo Tu We Th Fr Sa".split(" "),A:["AM","PM"]},w={YYYY:function(a){return("000"+a.getFullYear()).slice(-4)},YY:function(a){return("0"+a.getFullYear()).slice(-2)},Y:function(a){return""+a.getFullYear()},MMMM:function(a){return this.res.MMMM[a.getMonth()]},MMM:function(a){return this.res.MMM[a.getMonth()]},MM:function(a){return("0"+(a.getMonth()+1)).slice(-2)},M:function(a){return""+(a.getMonth()+1)},DD:function(a){return("0"+a.getDate()).slice(-2)},
6
6
  D:function(a){return""+a.getDate()},HH:function(a){return("0"+a.getHours()).slice(-2)},H:function(a){return""+a.getHours()},A:function(a){return this.res.A[11<a.getHours()|0]},hh:function(a){return("0"+(a.getHours()%12||12)).slice(-2)},h:function(a){return""+(a.getHours()%12||12)},mm:function(a){return("0"+a.getMinutes()).slice(-2)},m:function(a){return""+a.getMinutes()},ss:function(a){return("0"+a.getSeconds()).slice(-2)},s:function(a){return""+a.getSeconds()},SSS:function(a){return("00"+a.getMilliseconds()).slice(-3)},
7
- SS:function(a){return("0"+(a.getMilliseconds()/10|0)).slice(-2)},S:function(a){return""+(a.getMilliseconds()/100|0)},dddd:function(a){return this.res.dddd[a.getDay()]},ddd:function(a){return this.res.ddd[a.getDay()]},dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.getTimezoneOffset()/.6|0;return(0<a?"-":"+")+("000"+Math.abs(a-(a%100*.4|0))).slice(-4)},post:function(a){return a},res:t},x={YYYY:function(a){return this.exec(/^\d{4}/,a)},Y:function(a){return this.exec(/^\d{1,4}/,a)},
8
- MMMM:function(a){a=this.find(this.res.MMMM,a);a.value++;return a},MMM:function(a){a=this.find(this.res.MMM,a);a.value++;return a},MM:function(a){return this.exec(/^\d\d/,a)},M:function(a){return this.exec(/^\d\d?/,a)},DD:function(a){return this.exec(/^\d\d/,a)},D:function(a){return this.exec(/^\d\d?/,a)},HH:function(a){return this.exec(/^\d\d/,a)},H:function(a){return this.exec(/^\d\d?/,a)},A:function(a){return this.find(this.res.A,a)},hh:function(a){return this.exec(/^\d\d/,a)},h:function(a){return this.exec(/^\d\d?/,
9
- a)},mm:function(a){return this.exec(/^\d\d/,a)},m:function(a){return this.exec(/^\d\d?/,a)},ss:function(a){return this.exec(/^\d\d/,a)},s:function(a){return this.exec(/^\d\d?/,a)},SSS:function(a){return this.exec(/^\d{1,3}/,a)},SS:function(a){a=this.exec(/^\d\d?/,a);a.value*=10;return a},S:function(a){a=this.exec(/^\d/,a);a.value*=100;return a},Z:function(a){a=this.exec(/^[\+-]\d{2}[0-5]\d/,a);a.value=-60*(a.value/100|0)-a.value%100;return a},h12:function(a,b){return(12===a?0:a)+12*b},exec:function(a,
10
- b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var c=-1,d=0,h=0,g=a.length,l;h<g;h++)l=a[h],!b.indexOf(l)&&l.length>d&&(c=h,d=l.length);return{value:c,length:d}},pre:function(a){return a},res:t},n=function(a,b,c,d){var h={},g;for(g in a)h[g]=a[g];for(g in b||{})!!c^!!h[g]||(h[g]=b[g]);d&&(h.res=d);return h},f={_formatter:w,_parser:x};f.compile=function(a){for(var b=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,c,d=[a];c=b.exec(a);)d[d.length]=c[0];return d};
11
- f.format=function(a,b,c){var d=this||e;b="string"===typeof b?d.compile(b):b;var h=a.getTimezoneOffset();a=d.addMinutes(a,c?h:0);d=d._formatter;var g="";a.getTimezoneOffset=function(){return c?0:h};for(var l=1,u=b.length,k;l<u;l++)k=b[l],g+=d[k]?d.post(d[k](a,b[0])):k.replace(/\[(.*)]/,"$1");return g};f.preparse=function(a,b){var c=this||e;b="string"===typeof b?c.compile(b):b;var d={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},h=/\[(.*)]/;c=c._parser;var g=0;a=c.pre(a);for(var l=
12
- 1,u=b.length,k,q;l<u;l++)if(k=b[l],c[k]){q=c[k](a.slice(g),b[0]);if(!q.length)break;g+=q.length;d[q.token||k.charAt(0)]=q.value;d._match++}else if(k===a.charAt(g)||" "===k)g++;else if(h.test(k)&&!a.slice(g).indexOf(h.exec(k)[1]))g+=k.length-2;else{"..."===k&&(g=a.length);break}d.H=d.H||c.h12(d.h,d.A);d._index=g;d._length=a.length;return d};f.parse=function(a,b,c){var d=this||e;a=d.preparse(a,b);return d.isValid(a)?(a.M-=100>a.Y?22801:1,c||a.Z?new Date(Date.UTC(a.Y,a.M,a.D,a.H,a.m+a.Z,a.s,a.S)):new Date(a.Y,
13
- a.M,a.D,a.H,a.m,a.s,a.S)):new Date(NaN)};f.isValid=function(a,b){var c=this||e;a="string"===typeof a?c.preparse(a,b):a;c=[31,28+c.isLeapYear(a.Y)|0,31,30,31,30,31,31,30,31,30,31][a.M-1];return!(1>a._index||1>a._length||a._index-a._length||1>a._match||1>a.Y||9999<a.Y||1>a.M||12<a.M||1>a.D||a.D>c||0>a.H||23<a.H||0>a.m||59<a.m||0>a.s||59<a.s||0>a.S||999<a.S||-840>a.Z||720<a.Z)};f.transform=function(a,b,c,d){let h=this||e;return h.format(h.parse(a,b),c,d)};f.addYears=function(a,b){return(this||e).addMonths(a,
14
- 12*b)};f.addMonths=function(a,b){a=new Date(a.getTime());a.setMonth(a.getMonth()+b);return a};f.addDays=function(a,b){a=new Date(a.getTime());a.setDate(a.getDate()+b);return a};f.addHours=function(a,b){return(this||e).addMinutes(a,60*b)};f.addMinutes=function(a,b){return(this||e).addSeconds(a,60*b)};f.addSeconds=function(a,b){return(this||e).addMilliseconds(a,1E3*b)};f.addMilliseconds=function(a,b){return new Date(a.getTime()+b)};f.subtract=function(a,b){var c=a.getTime()-b.getTime();return{toMilliseconds:function(){return c},
15
- toSeconds:function(){return c/1E3},toMinutes:function(){return c/6E4},toHours:function(){return c/36E5},toDays:function(){return c/864E5}}};f.isLeapYear=function(a){return!(a%4)&&!!(a%100)||!(a%400)};f.isSameDay=function(a,b){return a.toDateString()===b.toDateString()};f.locale=function(a,b){p[a]||(p[a]=b)};f.plugin=function(a,b){m[a]||(m[a]=b)};var v=n(f);var e=n(f);e.locale=function(a){a="function"===typeof a?a:e.locale[a];if(!a)return r;r=a(f);var b=p[r]||{},c=n(t,b.res,!0);a=n(w,b.formatter,!0,
16
- c);b=n(x,b.parser,!0,c);e._formatter=v._formatter=a;e._parser=v._parser=b;for(var d in m)e.extend(m[d]);return r};e.extend=function(a){var b=n(e._parser.res,a.res),c=a.extender||{};e._formatter=n(e._formatter,a.formatter,!1,b);e._parser=n(e._parser,a.parser,!1,b);for(var d in c)e[d]||(e[d]=c[d])};e.plugin=function(a){(a="function"===typeof a?a:e.plugin[a])&&e.extend(m[a(f,v)]||{})};return e})
7
+ SS:function(a){return("0"+(a.getMilliseconds()/10|0)).slice(-2)},S:function(a){return""+(a.getMilliseconds()/100|0)},dddd:function(a){return this.res.dddd[a.getDay()]},ddd:function(a){return this.res.ddd[a.getDay()]},dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.getTimezoneOffset()/.6|0;return(0<a?"-":"+")+("000"+Math.abs(a-(a%100*.4|0))).slice(-4)},ZZ:function(a){a=a.getTimezoneOffset();var b=Math.abs(a);return(0<a?"-":"+")+("0"+(b/60|0)).slice(-2)+":"+("0"+b%60).slice(-2)},post:function(a){return a},
8
+ res:t},x={YYYY:function(a){return this.exec(/^\d{4}/,a)},Y:function(a){return this.exec(/^\d{1,4}/,a)},MMMM:function(a){a=this.find(this.res.MMMM,a);a.value++;return a},MMM:function(a){a=this.find(this.res.MMM,a);a.value++;return a},MM:function(a){return this.exec(/^\d\d/,a)},M:function(a){return this.exec(/^\d\d?/,a)},DD:function(a){return this.exec(/^\d\d/,a)},D:function(a){return this.exec(/^\d\d?/,a)},HH:function(a){return this.exec(/^\d\d/,a)},H:function(a){return this.exec(/^\d\d?/,a)},A:function(a){return this.find(this.res.A,
9
+ a)},hh:function(a){return this.exec(/^\d\d/,a)},h:function(a){return this.exec(/^\d\d?/,a)},mm:function(a){return this.exec(/^\d\d/,a)},m:function(a){return this.exec(/^\d\d?/,a)},ss:function(a){return this.exec(/^\d\d/,a)},s:function(a){return this.exec(/^\d\d?/,a)},SSS:function(a){return this.exec(/^\d{1,3}/,a)},SS:function(a){a=this.exec(/^\d\d?/,a);a.value*=10;return a},S:function(a){a=this.exec(/^\d/,a);a.value*=100;return a},Z:function(a){a=this.exec(/^[\+-]\d{2}[0-5]\d/,a);a.value=-60*(a.value/
10
+ 100|0)-a.value%100;return a},ZZ:function(a){a=/^([\+-])(\d{2}):([0-5]\d)/.exec(a)||["","","",""];return{value:-(60*(a[1]+a[2]|0)+(a[1]+a[3]|0)),length:a[0].length}},h12:function(a,b){return(12===a?0:a)+12*b},exec:function(a,b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var d=-1,c=0,h=0,g=a.length,l;h<g;h++)l=a[h],!b.indexOf(l)&&l.length>c&&(d=h,c=l.length);return{value:d,length:c}},pre:function(a){return a},res:t},n=function(a,b,d,c){var h={},g;for(g in a)h[g]=
11
+ a[g];for(g in b||{})!!d^!!h[g]||(h[g]=b[g]);c&&(h.res=c);return h},f={_formatter:w,_parser:x};f.compile=function(a){for(var b=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,d,c=[a];d=b.exec(a);)c[c.length]=d[0];return c};f.format=function(a,b,d){var c=this||e;b="string"===typeof b?c.compile(b):b;var h=a.getTimezoneOffset();a=c.addMinutes(a,d?h:0);c=c._formatter;var g="";a.getTimezoneOffset=function(){return d?0:h};for(var l=1,u=b.length,k;l<u;l++)k=b[l],g+=c[k]?c.post(c[k](a,b[0])):k.replace(/\[(.*)]/,
12
+ "$1");return g};f.preparse=function(a,b){var d=this||e;b="string"===typeof b?d.compile(b):b;var c={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},h=/\[(.*)]/;d=d._parser;var g=0;a=d.pre(a);for(var l=1,u=b.length,k,q;l<u;l++)if(k=b[l],d[k]){q=d[k](a.slice(g),b[0]);if(!q.length)break;g+=q.length;c[q.token||k.charAt(0)]=q.value;c._match++}else if(k===a.charAt(g)||" "===k)g++;else if(h.test(k)&&!a.slice(g).indexOf(h.exec(k)[1]))g+=k.length-2;else{"..."===k&&(g=a.length);break}c.H=
13
+ c.H||d.h12(c.h,c.A);c._index=g;c._length=a.length;return c};f.parse=function(a,b,d){var c=this||e;b="string"===typeof b?c.compile(b):b;a=c.preparse(a,b);return c.isValid(a)?(a.M-=100>a.Y?22801:1,d||~c._parser.find(b,"ZZ").value?new Date(Date.UTC(a.Y,a.M,a.D,a.H,a.m+a.Z,a.s,a.S)):new Date(a.Y,a.M,a.D,a.H,a.m,a.s,a.S)):new Date(NaN)};f.isValid=function(a,b){var d=this||e;a="string"===typeof a?d.preparse(a,b):a;d=[31,28+d.isLeapYear(a.Y)|0,31,30,31,30,31,31,30,31,30,31][a.M-1];return!(1>a._index||1>
14
+ a._length||a._index-a._length||1>a._match||1>a.Y||9999<a.Y||1>a.M||12<a.M||1>a.D||a.D>d||0>a.H||23<a.H||0>a.m||59<a.m||0>a.s||59<a.s||0>a.S||999<a.S||-840>a.Z||720<a.Z)};f.transform=function(a,b,d,c){let h=this||e;return h.format(h.parse(a,b),d,c)};f.addYears=function(a,b){return(this||e).addMonths(a,12*b)};f.addMonths=function(a,b){a=new Date(a.getTime());a.setMonth(a.getMonth()+b);return a};f.addDays=function(a,b){a=new Date(a.getTime());a.setDate(a.getDate()+b);return a};f.addHours=function(a,
15
+ b){return(this||e).addMinutes(a,60*b)};f.addMinutes=function(a,b){return(this||e).addSeconds(a,60*b)};f.addSeconds=function(a,b){return(this||e).addMilliseconds(a,1E3*b)};f.addMilliseconds=function(a,b){return new Date(a.getTime()+b)};f.subtract=function(a,b){var d=a.getTime()-b.getTime();return{toMilliseconds:function(){return d},toSeconds:function(){return d/1E3},toMinutes:function(){return d/6E4},toHours:function(){return d/36E5},toDays:function(){return d/864E5}}};f.isLeapYear=function(a){return!(a%
16
+ 4)&&!!(a%100)||!(a%400)};f.isSameDay=function(a,b){return a.toDateString()===b.toDateString()};f.locale=function(a,b){p[a]||(p[a]=b)};f.plugin=function(a,b){m[a]||(m[a]=b)};var v=n(f);var e=n(f);e.locale=function(a){a="function"===typeof a?a:e.locale[a];if(!a)return r;r=a(f);var b=p[r]||{},d=n(t,b.res,!0);a=n(w,b.formatter,!0,d);b=n(x,b.parser,!0,d);e._formatter=v._formatter=a;e._parser=v._parser=b;for(var c in m)e.extend(m[c]);return r};e.extend=function(a){var b=n(e._parser.res,a.res),d=a.extender||
17
+ {};e._formatter=n(e._formatter,a.formatter,!1,b);e._parser=n(e._parser,a.parser,!1,b);for(var c in d)e[c]||(e[c]=d[c])};e.plugin=function(a){(a="function"===typeof a?a:e.plugin[a])&&e.extend(m[a(f,v)]||{})};return e})