forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xdate.d.ts
375 lines (303 loc) · 10.2 KB
/
xdate.d.ts
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// Type definitions for XDate 0.8
// Project: http://arshaw.com/xdate/
// Definitions by: yamada28go <https://github.com/yamada28go/>
// Definitions: https://github.com/daptiv/DefinitelyTyped
interface formatters_info
{
i?: string;
u?: string;
xxx? : string;
vvv?: (xdate : XDate , useutc : boolean ) => string;
}
interface locale_detail
{
monthNames? : string [];
monthNamesShort?: string [];
dayNames?: string[];
dayNamesShort?: string [];
amDesignator?: string;
pmDesignator?: string;
}
declare class XDate {
//------------
//Constructors
//------------
public constructor();
public constructor( utcmode : boolean );
/**
* constructor
*/
public constructor(xdate : XDate , utcmode? : boolean ) ;
/**
* constructor
* @param {Date} [nativeDate] - JavaScript native date
*/
public constructor(nativeDate : Date , utcmode? : boolean ) ;
/**
* constructor
* @param {number} [milliseconds] - milliseconds
*/
public constructor(milliseconds: number , utcmode? : boolean ) ;
/**
* constructor
* @param {number} [year] - year
* @param {number} [month] - month
* @param {number} [date] - date
* @param {number} [hours] - hours
* @param {number} [minutes] - minutes
* @param {number} [seconds] - seconds
* @param {number} [milliseconds] - milliseconds
*/
public constructor( year : number , month : number , date : number ,
hours? : number , minutes? : number , seconds? : number , milliseconds? : number , utcmode? : boolean );
/**
* constructor
* @param {string} [dateString] - formatted date string
*/
public constructor( dateString : string , utcmode? : boolean );
//------------
//Getters
//------------
/**
* Returns the 4-digit year (ex: 2012)
* @return {number} 4-digit year (ex: 2012)
*/
public getFullYear() : number ;
/*
*Returns the month of the year. (0-11)
*Value is zero-index, meaning Jan=0, Feb=1, Mar=2, etc.
*/
public getMonth() : number;
/*
*Returns the ISO week number of the year. (1-53)
*/
public getWeek(): number;
/*
*Returns the date of the month. (1-31)
*/
public getDate() : number;
/*
*Returns the day-of-week as a number. (0-6)
*Sun=0, Mon=1, Tue=2, etc.
*/
public getDay() : number;
/*
*Returns the hour of the day. (0-23)
*/
public getHours() : number;
/*
*Returns the minute of the hour. (0-59)
*/
public getMinutes() : number;
/*
*Returns the second of the minute. (0-59)
*/
public getSeconds() : number;
/*
*Returns the millisecond of the second. (0-999)
*/
public getMilliseconds() : number;
/*
*Returns the number of milliseconds since the epoch.
*/
public getTime() : number;
/*
*Returns the number of milliseconds since the epoch. Identical to getTime.
*/
public valueOf() : number;
//------------
//Setters
//------------
/*
*year is a 4-digit year
*/
public setFullYear(year : number , preventOverflow? : boolean) : XDate;
/*
month is zero-indexed, meaning Jan=0, Feb=1, Mar=2, etc.
*/
public setMonth(month : number , preventOverflow? : boolean ) : XDate;
/*
*Moves the xdate to the Monday of the given week with time 00:00:00.
*The week is represented by a given ISO week number and an optional year. If year is omitted, the xdate's year with be used.
*/
public setWeek(week : number , year? : number) : XDate;
/*
*Sets the date of the month. (1-31)
*/
public setDate(date : number ) : XDate;
/*
*Sets the hour of the day. (0-23)
*/
public setHours(hours: number ) :XDate;
/*
*Sets the minute of the hour. (0-59)
*/
public setMinutes(minutes : number) : XDate;
/*
*Sets the second of the minute. (0-59)
*/
public setSeconds(seconds : number) : XDate;
/*
*Sets the millisecond of the second. (0-999)
*/
public setMilliseconds(milliseconds : number) : XDate;
/*
*Sets the number of milliseconds since the epoch.
*/
public setTime(milliseconds : number ) : XDate;
//------------
//Adding
//------------
public addYears(years : number, preventOverflow? : boolean) : XDate;
public addMonths(months : number , preventOverflow? : boolean) : XDate;
public addWeeks(weeks : number) : XDate;
public addDays(days : number) : XDate;
public addHours(hours : number) : XDate;
public addMinutes(minutes : number) : XDate;
public addSeconds(seconds : number) : XDate;
public addMilliseconds(milliseconds : number) :XDate;
//------------
//Diffing
//------------
public diffYears(otherDate : string) : number ;
public diffYears(otherDate : XDate) : number ;
public diffMonths(otherDate : string) : number ;
public diffMonths(otherDate : XDate) : number ;
public diffWeeks(otherDate : string) : number ;
public diffWeeks(otherDate : XDate) : number ;
public diffDays(otherDate : string) : number ;
public diffDays(otherDate : XDate) : number ;
public diffHours(otherDate : string) : number ;
public diffHours(otherDate : XDate) : number ;
public diffMinutes(otherDate : string) : number ;
public diffMinutes(otherDate : XDate) : number ;
public diffSeconds(otherDate : string) : number ;
public diffSeconds(otherDate : XDate) : number ;
public diffMilliseconds(otherDate : string) : number ;
public diffMilliseconds(otherDate : XDate) : number ;
//------------
//Formatting
//------------
/*
*If formatString is not specified, a browser-produced IETF string will be returned.
* settings can be a name of an available locale or an object that overrides the default locale's settings.
*/
public toString(formatString? : string , settings? : Object) : string;
/*
*Same as toString but gets its values from the UTC version of the date.
*As a result, "Z" will be displayed as the timezone.
*/
public toUTCString(formatString? : string , settings? : Object) : string;
public toGMTString(formatString? : string , settings? : Object) : string;
/*
*Returns an ISO8601 string that has been normalized to UTC. Will have a "Z" timezone indicator.
*See the native Date's specs for toISOString.
*/
public toISOString() : string;
/*
*Same as native Date's toDateString
*/
public toDateString() : string;
/*
*Same as native Date's toTimeString
*/
public toTimeString() : string;
/*
*Same as native Date's toLocaleString
*/
public toLocaleString() : string;
/*
*Same as native Date's toLocaleDateString
*/
public toLocaleDateString() : string;
/*
*Same as native Date's toLocaleTimeString
*/
public toLocaleTimeString() : string;
//------------
//Formatting
//------------
public getUTCFullYear() : number ;
public getUTCMonth() : number ;
public getUTCWeek() : number ;
public getUTCDate() : number ;
public getUTCDay() : number ;
public getUTCHours() : number ;
public getUTCMinutes() : number ;
public getUTCSeconds() : number ;
public getUTCMilliseconds() : number ;
public setUTCFullYear(year : number) : XDate;
public setUTCMonth(month : number) : XDate;
public setUTCWeek(week : number , year? : number ) : XDate;
public setUTCDate(date : number ) : XDate;
public setUTCHours(hours : number ) : XDate;
public setUTCMinutes(minutes : number ) : XDate;
public setUTCSeconds(seconds : number ) : XDate;
public setUTCMilliseconds(milliseconds : number) : XDate;
//------------
//UTC Mode
//------------
/*
*Returns true if the date is in UTC-mode and false otherwise
*/
public getUTCMode() : boolean;
/*
*utcMode must be either true or false. If the optional doCoercion parameters is set to true,
*the underlying millisecond time of the date will be coerced in such a way that methods like
*getDate and getHours will have the same values before and after the conversion.
*/
public setUTCMode(utcMode : boolean , doCoercion? : boolean ) : XDate;
/*
*Returns the number of minutes from UTC, just like the native Date's getTimezoneOffset.
*However, if the XDate is in UTC-mode, 0 will be returned.
*/
public getTimezoneOffset() : number;
//------------
//Utilities
//------------
/*
*returns a copy of the XDate
*/
public clone() : XDate;
/*
*sets the hours, minutes, seconds, and milliseconds to zero
*/
public clearTime() : XDate ;
/*
*return true if the XDate is a valid date, false otherwise
*/
public valid() : boolean ;
/*
*Returns a conversion to a native Date
*/
public toDate() : Date;
//------------
//Static function
//------------
/*
*Returns the number of days in the given month
*/
public static getDaysInMonth(year : number , month : number) : number;
/*
*Parses a date-string and returns milliseconds since the epoch. You'll probably want to use new XDate(dateString) instead.
*/
public static parse(dateString : string ) : number;
/*
*Returns the current date, as milliseconds since the epoch. You'll probably want to use new XDate() instead.
*/
public static now() : number ;
/*
*Returns the current date with time cleared, as an XDate object
*/
public static today() : XDate ;
/*
*Returns a milliseconds time since the epoch for the given UTC date
*/
public static UTC(year : number , month : number , date : number , hours : number,
minutes : number , seconds : number , milliseconds : number ) : XDate;
public static locales : { [key: string]: locale_detail; };
public static defaultLocale : string;
public static formatters : formatters_info;
public static getDaysInMonth(year : number, month : number) : number;
public static UTC(year : number, month : number, day : number , hours? : number , minutes? : number , seconds?:number,ms?:number): number;
}