date-and-time 2.2.1 → 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.
- package/PLUGINS.md +22 -22
- package/README.md +81 -80
- package/date-and-time.d.ts +304 -0
- package/date-and-time.js +73 -72
- package/esm/date-and-time.es.js +73 -72
- package/esm/date-and-time.mjs +73 -72
- package/esm/plugin/timezone.es.js +1 -1
- package/esm/plugin/timezone.mjs +1 -1
- package/locale/ar.d.ts +1 -0
- package/locale/az.d.ts +1 -0
- package/locale/bn.d.ts +1 -0
- package/locale/cs.d.ts +1 -0
- package/locale/de.d.ts +1 -0
- package/locale/dk.d.ts +1 -0
- package/locale/el.d.ts +1 -0
- package/locale/en.d.ts +1 -0
- package/locale/es.d.ts +1 -0
- package/locale/fa.d.ts +1 -0
- package/locale/fr.d.ts +1 -0
- package/locale/hi.d.ts +1 -0
- package/locale/hu.d.ts +1 -0
- package/locale/id.d.ts +1 -0
- package/locale/it.d.ts +1 -0
- package/locale/ja.d.ts +1 -0
- package/locale/jv.d.ts +1 -0
- package/locale/ko.d.ts +1 -0
- package/locale/my.d.ts +1 -0
- package/locale/nl.d.ts +1 -0
- package/locale/pa-in.d.ts +1 -0
- package/locale/pl.d.ts +1 -0
- package/locale/pt.d.ts +1 -0
- package/locale/ro.d.ts +1 -0
- package/locale/ru.d.ts +1 -0
- package/locale/rw.d.ts +1 -0
- package/locale/sr.d.ts +1 -0
- package/locale/sv.d.ts +1 -0
- package/locale/th.d.ts +1 -0
- package/locale/tr.d.ts +1 -0
- package/locale/uk.d.ts +1 -0
- package/locale/uz.d.ts +1 -0
- package/locale/vi.d.ts +1 -0
- package/locale/zh-cn.d.ts +1 -0
- package/locale/zh-tw.d.ts +1 -0
- package/package.json +6 -3
- package/plugin/day-of-week.d.ts +1 -0
- package/plugin/meridiem.d.ts +1 -0
- package/plugin/microsecond.d.ts +1 -0
- package/plugin/ordinal.d.ts +1 -0
- package/plugin/timespan.d.ts +24 -0
- package/plugin/timezone.d.ts +79 -0
- package/plugin/timezone.js +1 -1
- 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
|
@@ -146,9 +146,9 @@
|
|
|
146
146
|
date;
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
|
-
* Compiling
|
|
150
|
-
* @param {string} formatString -
|
|
151
|
-
* @returns {Array.<string>}
|
|
149
|
+
* Compiling format strings
|
|
150
|
+
* @param {string} formatString - A format string
|
|
151
|
+
* @returns {Array.<string>} A compiled object
|
|
152
152
|
*/
|
|
153
153
|
proto.compile = function (formatString) {
|
|
154
154
|
var re = /\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g, keys, pattern = [formatString];
|
|
@@ -160,11 +160,11 @@
|
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
/**
|
|
163
|
-
* Formatting
|
|
164
|
-
* @param {Date} dateObj -
|
|
165
|
-
* @param {string|Array.<string>} arg -
|
|
166
|
-
* @param {boolean} [utc] -
|
|
167
|
-
* @returns {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
|
|
168
168
|
*/
|
|
169
169
|
proto.format = function (dateObj, arg, utc) {
|
|
170
170
|
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
@@ -181,10 +181,11 @@
|
|
|
181
181
|
};
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
|
-
* Pre-parsing
|
|
185
|
-
* @param {string} dateString -
|
|
186
|
-
* @param {string|Array.<string>} arg -
|
|
187
|
-
* @
|
|
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
|
|
188
189
|
*/
|
|
189
190
|
proto.preparse = function (dateString, arg) {
|
|
190
191
|
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
@@ -220,11 +221,11 @@
|
|
|
220
221
|
};
|
|
221
222
|
|
|
222
223
|
/**
|
|
223
|
-
* Parsing
|
|
224
|
-
* @param {string} dateString -
|
|
225
|
-
* @param {string|Array.<string>} arg -
|
|
226
|
-
* @param {boolean} [utc] -
|
|
227
|
-
* @returns {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
|
|
228
229
|
*/
|
|
229
230
|
proto.parse = function (dateString, arg, utc) {
|
|
230
231
|
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
@@ -241,10 +242,10 @@
|
|
|
241
242
|
};
|
|
242
243
|
|
|
243
244
|
/**
|
|
244
|
-
*
|
|
245
|
-
* @param {Object|string} arg1 -
|
|
246
|
-
* @param {string|Array.<string>} [arg2] -
|
|
247
|
-
* @returns {boolean}
|
|
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
|
|
248
249
|
*/
|
|
249
250
|
proto.isValid = function (arg1, arg2) {
|
|
250
251
|
var ctx = this || date, dt = typeof arg1 === 'string' ? ctx.preparse(arg1, arg2) : arg1,
|
|
@@ -259,12 +260,12 @@
|
|
|
259
260
|
};
|
|
260
261
|
|
|
261
262
|
/**
|
|
262
|
-
*
|
|
263
|
-
* @param {string} dateString -
|
|
264
|
-
* @param {string|Array.<string>} arg1 -
|
|
265
|
-
* @param {string|Array.<string>} arg2 -
|
|
266
|
-
* @param {boolean} [utc] -
|
|
267
|
-
* @returns {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
|
|
268
269
|
*/
|
|
269
270
|
proto.transform = function (dateString, arg1, arg2, utc) {
|
|
270
271
|
const ctx = this || date;
|
|
@@ -273,9 +274,9 @@
|
|
|
273
274
|
|
|
274
275
|
/**
|
|
275
276
|
* Adding years
|
|
276
|
-
* @param {Date} dateObj -
|
|
277
|
-
* @param {number} years -
|
|
278
|
-
* @returns {Date}
|
|
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
|
|
279
280
|
*/
|
|
280
281
|
proto.addYears = function (dateObj, years) {
|
|
281
282
|
return (this || date).addMonths(dateObj, years * 12);
|
|
@@ -283,9 +284,9 @@
|
|
|
283
284
|
|
|
284
285
|
/**
|
|
285
286
|
* Adding months
|
|
286
|
-
* @param {Date} dateObj -
|
|
287
|
-
* @param {number} months -
|
|
288
|
-
* @returns {Date}
|
|
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
|
|
289
290
|
*/
|
|
290
291
|
proto.addMonths = function (dateObj, months) {
|
|
291
292
|
var d = new Date(dateObj.getTime());
|
|
@@ -296,9 +297,9 @@
|
|
|
296
297
|
|
|
297
298
|
/**
|
|
298
299
|
* Adding days
|
|
299
|
-
* @param {Date} dateObj -
|
|
300
|
-
* @param {number} days -
|
|
301
|
-
* @returns {Date}
|
|
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
|
|
302
303
|
*/
|
|
303
304
|
proto.addDays = function (dateObj, days) {
|
|
304
305
|
var d = new Date(dateObj.getTime());
|
|
@@ -309,9 +310,9 @@
|
|
|
309
310
|
|
|
310
311
|
/**
|
|
311
312
|
* Adding hours
|
|
312
|
-
* @param {Date} dateObj -
|
|
313
|
-
* @param {number} hours -
|
|
314
|
-
* @returns {Date}
|
|
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
|
|
315
316
|
*/
|
|
316
317
|
proto.addHours = function (dateObj, hours) {
|
|
317
318
|
return (this || date).addMinutes(dateObj, hours * 60);
|
|
@@ -319,9 +320,9 @@
|
|
|
319
320
|
|
|
320
321
|
/**
|
|
321
322
|
* Adding minutes
|
|
322
|
-
* @param {Date} dateObj -
|
|
323
|
-
* @param {number} minutes -
|
|
324
|
-
* @returns {Date}
|
|
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
|
|
325
326
|
*/
|
|
326
327
|
proto.addMinutes = function (dateObj, minutes) {
|
|
327
328
|
return (this || date).addSeconds(dateObj, minutes * 60);
|
|
@@ -329,9 +330,9 @@
|
|
|
329
330
|
|
|
330
331
|
/**
|
|
331
332
|
* Adding seconds
|
|
332
|
-
* @param {Date} dateObj -
|
|
333
|
-
* @param {number} seconds -
|
|
334
|
-
* @returns {Date}
|
|
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
|
|
335
336
|
*/
|
|
336
337
|
proto.addSeconds = function (dateObj, seconds) {
|
|
337
338
|
return (this || date).addMilliseconds(dateObj, seconds * 1000);
|
|
@@ -339,19 +340,19 @@
|
|
|
339
340
|
|
|
340
341
|
/**
|
|
341
342
|
* Adding milliseconds
|
|
342
|
-
* @param {Date} dateObj -
|
|
343
|
-
* @param {number} milliseconds -
|
|
344
|
-
* @returns {Date}
|
|
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
|
|
345
346
|
*/
|
|
346
347
|
proto.addMilliseconds = function (dateObj, milliseconds) {
|
|
347
348
|
return new Date(dateObj.getTime() + milliseconds);
|
|
348
349
|
};
|
|
349
350
|
|
|
350
351
|
/**
|
|
351
|
-
* Subtracting two dates
|
|
352
|
-
* @param {Date} date1 -
|
|
353
|
-
* @param {Date} date2 -
|
|
354
|
-
* @returns {Object}
|
|
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
|
|
355
356
|
*/
|
|
356
357
|
proto.subtract = function (date1, date2) {
|
|
357
358
|
var delta = date1.getTime() - date2.getTime();
|
|
@@ -376,9 +377,9 @@
|
|
|
376
377
|
};
|
|
377
378
|
|
|
378
379
|
/**
|
|
379
|
-
* Whether year is leap year
|
|
380
|
-
* @param {number} y - year
|
|
381
|
-
* @returns {boolean}
|
|
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
|
|
382
383
|
*/
|
|
383
384
|
proto.isLeapYear = function (y) {
|
|
384
385
|
return (!(y % 4) && !!(y % 100)) || !(y % 400);
|
|
@@ -386,19 +387,19 @@
|
|
|
386
387
|
|
|
387
388
|
/**
|
|
388
389
|
* Comparison of two dates
|
|
389
|
-
* @param {Date} date1 -
|
|
390
|
-
* @param {Date} date2 -
|
|
391
|
-
* @returns {boolean}
|
|
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)
|
|
392
393
|
*/
|
|
393
394
|
proto.isSameDay = function (date1, date2) {
|
|
394
395
|
return date1.toDateString() === date2.toDateString();
|
|
395
396
|
};
|
|
396
397
|
|
|
397
398
|
/**
|
|
398
|
-
*
|
|
399
|
-
* @param {string} code - language code
|
|
400
|
-
* @param {Function} locale - locale installer
|
|
401
|
-
* @returns {
|
|
399
|
+
* Definition of new locale
|
|
400
|
+
* @param {string} code - A language code
|
|
401
|
+
* @param {Function} locale - A locale installer
|
|
402
|
+
* @returns {void}
|
|
402
403
|
*/
|
|
403
404
|
proto.locale = function (code, locale) {
|
|
404
405
|
if (!locales[code]) {
|
|
@@ -407,9 +408,9 @@
|
|
|
407
408
|
};
|
|
408
409
|
|
|
409
410
|
/**
|
|
410
|
-
*
|
|
411
|
-
* @param {string} name - plugin name
|
|
412
|
-
* @param {Function} plugin - plugin installer
|
|
411
|
+
* Definition of new plugin
|
|
412
|
+
* @param {string} name - A plugin name
|
|
413
|
+
* @param {Function} plugin - A plugin installer
|
|
413
414
|
* @returns {void}
|
|
414
415
|
*/
|
|
415
416
|
proto.plugin = function (name, plugin) {
|
|
@@ -422,9 +423,9 @@
|
|
|
422
423
|
date = extend(proto);
|
|
423
424
|
|
|
424
425
|
/**
|
|
425
|
-
* Changing
|
|
426
|
-
* @param {Function|string} [locale] - locale
|
|
427
|
-
* @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
|
|
428
429
|
*/
|
|
429
430
|
date.locale = function (locale) {
|
|
430
431
|
var install = typeof locale === 'function' ? locale : date.locale[locale];
|
|
@@ -450,8 +451,8 @@
|
|
|
450
451
|
};
|
|
451
452
|
|
|
452
453
|
/**
|
|
453
|
-
*
|
|
454
|
-
* @param {Object} extension - extension object
|
|
454
|
+
* Functional extension
|
|
455
|
+
* @param {Object} extension - An extension object
|
|
455
456
|
* @returns {void}
|
|
456
457
|
*/
|
|
457
458
|
date.extend = function (extension) {
|
|
@@ -469,8 +470,8 @@
|
|
|
469
470
|
};
|
|
470
471
|
|
|
471
472
|
/**
|
|
472
|
-
* Importing
|
|
473
|
-
* @param {Function|string} plugin - plugin
|
|
473
|
+
* Importing plugins
|
|
474
|
+
* @param {Function|string} plugin - A plugin installer or plugin name
|
|
474
475
|
* @returns {void}
|
|
475
476
|
*/
|
|
476
477
|
date.plugin = function (plugin) {
|