forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-calendar.d.ts
executable file
·402 lines (345 loc) · 11.2 KB
/
node-calendar.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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
// Type definitions for node-calendar v0.1.4
// Project: https://www.npmjs.com/package/node-calendar
// Definitions by: Luzian Zagadinow <https://github.com/luzianz>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface IWeekRow<T> extends Array<T> {
[dayIndex: number]: T;
}
interface IMonthGrid<T> extends Array<IWeekRow<T>> {
[weekRowIndex: number]: IWeekRow<T>;
}
interface IMonthRow<T> extends Array<IMonthGrid<T>> {
[monthColumnIndex: number]: IMonthGrid<T>;
}
interface IYearGrid<T> extends Array<IMonthRow<T>> {
[monthRowIndex: number]: IMonthRow<T>;
}
/**
* This module allows you to output calendars like the Unix cal program, and provides
* additional useful functions related to the calendar. By default, these calendars
* have Monday as the first day of the week, and Sunday as the last (the European
* convention). Use setfirstweekday() to set the first day of the week to Sunday
* (6) or to any other weekday. Parameters that specify dates are given as integers.
*/
declare module 'node-calendar' {
/** 0 */
export var MONDAY: number;
/** 1 */
export var TUESDAY: number;
/** 2 */
export var WEDNESDAY: number;
/** 3 */
export var THURSDAY: number;
/** 4 */
export var FRIDAY: number;
/** 5 */
export var SATURDAY: number;
/** 6 */
export var SUNDAY: number;
/** 1 */
export var JANUARY: number;
/** 2 */
export var FEBRUARY: number;
/** 3 */
export var MARCH: number;
/** 4 */
export var APRIL: number;
/** 5 */
export var MAY: number;
/** 6 */
export var JUNE: number;
/** 7 */
export var JULY: number;
/** 8 */
export var AUGUST: number;
/** 9 */
export var SEPTEMBER: number;
/** 10 */
export var OCTOBER: number;
/** 11 */
export var NOVEMBER: number;
/** 12 */
export var DECEMBER: number;
/**
* [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]
*/
export var day_name: string[];
/**
* [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
*/
export var day_abbr: string[];
/**
* [ '', 'January', 'February', 'March',
* 'April', 'May', 'June', 'July', 'August',
* 'September', 'October', 'November', 'December' ]
*/
export var month_name: string[];
/**
* [ '', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
* 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
*/
export var month_abbr: string[];
/**
* Base calendar class. This class doesn't do any formatting. It simply provides
* data to subclasses.
*/
export class Calendar {
/**
* @param {number} firstweekday
* Numerical day of the week the calendar weeks should start.
* (0=MON, 1=TUE, ...) Default: 0
*/
constructor(firstweekday?: number);
/**
* Numerical day of the week the calendar weeks should start.
* (0=MON, 1=TUE, ...)
*
* @method getfirstweekday
*/
getfirstweekday(): number;
/**
* Numerical day of the week the calendar weeks should start.
* (0=MON, 1=TUE, ...)
*
* @param {number} firstweekday
* Numerical day of the week the calendar weeks should start.
* (0=MON, 1=TUE, ...) Default: 0
*/
setfirstweekday(firstweekday: number): void;
/**
* One week of weekday numbers starting with the configured first one.
*/
iterweekdays(): number[];
/**
* Dates for one month. The array will contain Date values and will always
* iterate through complete weeks, so it will yield dates outside the
* specified month.
*
* @param {number} year
* Year for which the calendar should be generated.
*
* @param {number} month
* Month for which the calendar should be generated.
*/
itermonthdates(year: number, month: number): Date[];
/**
* Like itermonthdates(), but will yield day numbers. For days outside
* the specified month the day number is 0.
*
* @param {number} year
* Year for which the calendar should be generated.
*
* @param {number} month
* Month for which the calendar should be generated.
*/
itermonthdays(year: number, month: number): number[];
/**
* Like itermonthdates(), but will yield [day number, weekday number]
* arrays. For days outside the specified month the day number is 0.
*
* @param {number} year
* Year for which the calendar should be generated.
*
* @param {number} month
* Month for which the calendar should be generated.
*/
itermonthdays2(year: number, month: number): [number, number][];
/**
* A matrix (array of array) representing a month's calendar.
* Each row represents a week; week entries are Date values.
*
* @param {number} year
* Year for which the calendar should be generated.
*
* @param {number} month
* Month for which the calendar should be generated.
*/
monthdatescalendar(year: number, month: number): IMonthGrid<Date>;
/**
* A matrix representing a month's calendar. Each row represents a week;
* days outside this month are zero.
*
* @param {number} year
* Year for which the calendar should be generated.
*
* @param {number} month
* Month for which the calendar should be generated.
*/
monthdayscalendar(year: number, month: number): IMonthGrid<number>;
/**
* Return a matrix representing a month's calendar. Each row represents
* a week; week entries are [day number, weekday number] arrays. Day numbers
* outside this month are zero.
*
* @param {number} year
* Year for which the calendar should be generated.
*
* @param {number} month
* Month for which the calendar should be generated.
*/
monthdays2calendar(year: number, month: number): IMonthGrid<[number, number]>;
/**
* The specified year ready for formatting. The return value is an array
* of month rows. Each month row contains up to width months. Each month
* contains between 4 and 6 weeks and each week contains 1-7 days. Days
* are Date objects.
*
* @param {number} year
* Year for which the calendar should be generated.
*
* @param {number} width
* The number of months to include in each row. Default: 3
*/
yeardatescalendar(year: number, width?: number): IYearGrid<Date>;
/**
* the specified year ready for formatting (similar to yeardatescalendar()).
* Entries in the week arrays are day numbers. Day numbers outside this
* month are zero.
*
* @param {number} year
* Year for which the calendar should be generated
*
* @param {number} width
* The number of months to include in each row. Default: 3
*/
yeardayscalendar(year: number, width?: number): IYearGrid<number>;
/**
* The specified year ready for formatting (similar to yeardatescalendar()).
* Entries in the week arrays are [day number, weekday number] arrays.
* Day numbers outside this month are zero.
*
* @param {number} year
* Year for which the calendar should be generated
*
* @param {number} width
* The number of months to include in each row. Default: 3
*/
yeardays2calendar(year: number, width?: number): IYearGrid<[number, number]>;
}
/**
* @param {number} year
* Year to test.
*
* @return {boolean}
* true for leap years, false for non-leap years.
*/
export function isleap(year: number): boolean;
/**
* @param {number} y1
* Beginning year in the range to test.
*
* @param {number} y2
* Ending year in the range to test.
*
* @return {number}
* Number of leap years in range (y1...y2). Assumes y1 <= y2.
*/
export function leapdays(y1: number, y2: number): number;
/**
* @param {number} year
* Year for which the range should be calculated.
*
* @param {number} month
* Month for which the range should be calculated.
*
* @throws {IllegalMonthError} if the provided month is invalid.
*
* @return {[number, number]}
* starting weekday (0-6 ~ Mon-Sun) and number of days (28-31) for year, month.
*/
export function monthrange(year: number, month: number): [number, number];
/**
* Sets the locale for use in extracting month and weekday names.
*
* @param {string} locale
* Locale to set on the calendar object. Default: en_US
*
* @throws {IllegalLocaleError} if the provided locale is invalid.
*/
export function setlocale(locale?: string): void;
/**
* Unrelated but handy function to calculate Unix timestamp from GMT.
*
* @param timegmt {[number, number, number, number, number, number]}
* An array containing the elements from a time structure dataset.
* Format: [tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec]
*
* @throws {IllegalMonthError} if the provided month element is invalid.
*
* @throws {IllegalDayError} if the provided day element is invalid.
*
* @throws {IllegalTimeError} if any of the the provided time elements are invalid.
*
* @return {number}
* Unix timestamp from GMT.
*/
export function timegm(timegmt: [number, number, number, number, number, number]): number;
/**
* @param {number} year
* Year for which the weekday should be calculated.
*
* @param {number} month
* Month for which the weekday should be calculated.
*
* @param {number} day
* Day for which the weekday should be calculated.
*
* @throws {IllegalMonthError} if the provided month element is invalid.
*
* @throws {IllegalDayError} if the provided day element is invalid.
*
* @return {number}
* weekday (0-6 ~ Mon-Sun) for year (1970-...), month (1-12), day (1-31).
*/
export function weekday(year: number, month: number, day: number): number;
/** Error indicating a nonexistent or unsupported locale specified. */
export class IllegalLocaleError implements Error {
public name: string;
public message: string;
/**
* @param {string} message
* Optional custom error message.
*/
constructor(message?: string)
}
/** Error indicating a day index specified outside of the valid range. */
export class IllegalDayError implements Error {
public name: string;
public message: string;
/**
* @param {string} message
* Optional custom error message.
*/
constructor(message?: string)
}
/** Error indicating a month index specified outside of the expected range (1-12 ~ Jan-Dec). */
export class IllegalMonthError implements Error {
public name: string;
public message: string;
/**
* @param {string} message
* Optional custom error message.
*/
constructor(message?: string)
}
/** Error indicating a time element is outside of the valid range. */
export class IllegalTimeError implements Error {
public name: string;
public message: string;
/**
* @param {string} message
* Optional custom error message.
*/
constructor(message?: string)
}
/** Error indicating a weekday index specified outside of the expected range (0-6 ~ Mon-Sun). */
export class IllegalWeekdayError implements Error {
public name: string;
public message: string;
/**
* @param {string} message
* Optional custom error message.
*/
constructor(message?: string)
}
}