From 499811255bde78f457a50f1595746b90ca17131b Mon Sep 17 00:00:00 2001 From: Luzian Zagadinow Date: Tue, 2 Jun 2015 01:34:08 -0400 Subject: [PATCH 1/9] initial commit --- node-calendar/.gitignore | 4 + node-calendar/node-calendar-tests.ts | 126 +++++++++++++ node-calendar/node-calendar.d.ts | 271 +++++++++++++++++++++++++++ node-calendar/package.json | 14 ++ 4 files changed, 415 insertions(+) create mode 100644 node-calendar/.gitignore create mode 100644 node-calendar/node-calendar-tests.ts create mode 100755 node-calendar/node-calendar.d.ts create mode 100755 node-calendar/package.json diff --git a/node-calendar/.gitignore b/node-calendar/.gitignore new file mode 100644 index 0000000000..76136c9e9a --- /dev/null +++ b/node-calendar/.gitignore @@ -0,0 +1,4 @@ +*.js +tsconfig.json +node_modules +.settings \ No newline at end of file diff --git a/node-calendar/node-calendar-tests.ts b/node-calendar/node-calendar-tests.ts new file mode 100644 index 0000000000..5a4a40a466 --- /dev/null +++ b/node-calendar/node-calendar-tests.ts @@ -0,0 +1,126 @@ +/// +/// + +import node_calendar = require('node-calendar'); + +var cal = new node_calendar.Calendar(node_calendar.SUNDAY); + +assert(cal.getfirstweekday() == node_calendar.SUNDAY); + +cal.setfirstweekday(node_calendar.MONDAY); + +assert(cal.getfirstweekday() == node_calendar.MONDAY); + +assert(node_calendar.MONDAY == 0); +assert(node_calendar.TUESDAY == 1); +assert(node_calendar.WEDNESDAY == 2); +assert(node_calendar.THURSDAY == 3); +assert(node_calendar.FRIDAY == 4); +assert(node_calendar.SATURDAY == 5); +assert(node_calendar.SUNDAY == 6); + +assert(node_calendar.day_name[node_calendar.MONDAY] == 'Monday'); +assert(node_calendar.day_name[node_calendar.TUESDAY] == 'Tuesday'); +assert(node_calendar.day_name[node_calendar.WEDNESDAY] == 'Wednesday'); +assert(node_calendar.day_name[node_calendar.THURSDAY] == 'Thursday'); +assert(node_calendar.day_name[node_calendar.FRIDAY] == 'Friday'); +assert(node_calendar.day_name[node_calendar.SATURDAY] == 'Saturday'); +assert(node_calendar.day_name[node_calendar.SUNDAY] == 'Sunday'); + +assert(node_calendar.day_abbr[node_calendar.MONDAY] == 'Mon'); +assert(node_calendar.day_abbr[node_calendar.TUESDAY] == 'Tue'); +assert(node_calendar.day_abbr[node_calendar.WEDNESDAY] == 'Wed'); +assert(node_calendar.day_abbr[node_calendar.THURSDAY] == 'Thu'); +assert(node_calendar.day_abbr[node_calendar.FRIDAY] == 'Fri'); +assert(node_calendar.day_abbr[node_calendar.SATURDAY] == 'Sat'); +assert(node_calendar.day_abbr[node_calendar.SUNDAY] == 'Sun'); + +assert(node_calendar.JANUARY == 1); +assert(node_calendar.FEBRUARY == 2); +assert(node_calendar.MARCH == 3); +assert(node_calendar.APRIL == 4); +assert(node_calendar.MAY == 5); +assert(node_calendar.JUNE == 6); +assert(node_calendar.JULY == 7); +assert(node_calendar.AUGUST == 8); +assert(node_calendar.SEPTEMBER == 9); +assert(node_calendar.OCTOBER == 10); +assert(node_calendar.NOVEMBER == 11); +assert(node_calendar.DECEMBER == 12); + +assert(node_calendar.month_name[0] == ''); +assert(node_calendar.month_name[node_calendar.JANUARY] == 'January'); +assert(node_calendar.month_name[node_calendar.FEBRUARY] == 'February'); +assert(node_calendar.month_name[node_calendar.MARCH] == 'March'); +assert(node_calendar.month_name[node_calendar.APRIL] == 'April'); +assert(node_calendar.month_name[node_calendar.MAY] == 'May'); +assert(node_calendar.month_name[node_calendar.JUNE] == 'June'); +assert(node_calendar.month_name[node_calendar.JULY] == 'July'); +assert(node_calendar.month_name[node_calendar.AUGUST] == 'August'); +assert(node_calendar.month_name[node_calendar.SEPTEMBER] == 'September'); +assert(node_calendar.month_name[node_calendar.OCTOBER] == 'October'); +assert(node_calendar.month_name[node_calendar.NOVEMBER] == 'November'); +assert(node_calendar.month_name[node_calendar.DECEMBER] == 'December'); + +assert(node_calendar.month_abbr[0] == ''); +assert(node_calendar.month_abbr[node_calendar.JANUARY] == 'Jan'); +assert(node_calendar.month_abbr[node_calendar.FEBRUARY] == 'Feb'); +assert(node_calendar.month_abbr[node_calendar.MARCH] == 'Mar'); +assert(node_calendar.month_abbr[node_calendar.APRIL] == 'Apr'); +assert(node_calendar.month_abbr[node_calendar.MAY] == 'May'); +assert(node_calendar.month_abbr[node_calendar.JUNE] == 'Jun'); +assert(node_calendar.month_abbr[node_calendar.JULY] == 'Jul'); +assert(node_calendar.month_abbr[node_calendar.AUGUST] == 'Aug'); +assert(node_calendar.month_abbr[node_calendar.SEPTEMBER] == 'Sep'); +assert(node_calendar.month_abbr[node_calendar.OCTOBER] == 'Oct'); +assert(node_calendar.month_abbr[node_calendar.NOVEMBER] == 'Nov'); +assert(node_calendar.month_abbr[node_calendar.DECEMBER] == 'Dec'); + +cal.itermonthdates(2015, node_calendar.JANUARY).forEach(assertIsDate); +cal.itermonthdays(2014, node_calendar.FEBRUARY).forEach(assertIsNumber); +cal.itermonthdays2(2013, node_calendar.MARCH).forEach(assertDayOfWeekMonth); +cal.iterweekdays().forEach(assertIsNumber); + +assertMonthGrid(cal.monthdatescalendar(2012, node_calendar.APRIL), assertIsDate); +assertMonthGrid(cal.monthdays2calendar(2011, node_calendar.MAY), assertDayOfWeekMonth); +assertMonthGrid(cal.monthdayscalendar(2010, node_calendar.JUNE), assertIsNumber); + +assertYearGrid(cal.yeardatescalendar(2009, 3), assertIsDate); +assertYearGrid(cal.yeardays2calendar(2008, 2), assertDayOfWeekMonth); +assertYearGrid(cal.yeardayscalendar(2007, 4), assertIsNumber); + +function assertIsDate(d: Date) { + assert(d instanceof Date, 'Should be a date'); +} + +function assertIsNumber(n: number) { + assert(typeof n == 'number', 'Should be a number'); +} + +function assertDayOfWeekMonth(d: IDayOfWeekMonth) { + assert(d instanceof Array, 'Day of weak/month should be an array'); + assert(d.length == 2, 'Day of weak/month array should contain 2 items'); + assert(typeof d[0] == 'number', 'Day of month should be a number'); + assert(typeof d[1] == 'number', 'Day of week should be a number'); +} + +function assertWeekRow(row: IWeekRow, assertItemType: (item: T) => void) { + row.forEach(assertItemType); +} + +function assertMonthGrid(grid: IMonthGrid, assertItemType: (item: T) => void) { + grid.forEach(wr => assertWeekRow(wr, assertItemType)); +} + +function assertMonthRow(row: IMonthRow, assertItemType: (item: T) => void) { + row.forEach(mg => assertMonthGrid(mg, assertItemType)); +} + +function assertYearGrid(grid: IYearGrid, assertItemType: (item: T) => void) { + grid.forEach(mr => assertMonthRow(mr, assertItemType)); +} + +function assert(condition: boolean, msg?: string): void { + if (condition) return; + throw new Error(msg); +} \ No newline at end of file diff --git a/node-calendar/node-calendar.d.ts b/node-calendar/node-calendar.d.ts new file mode 100755 index 0000000000..a1c3f0500a --- /dev/null +++ b/node-calendar/node-calendar.d.ts @@ -0,0 +1,271 @@ +// Type definitions for node-calendar v0.1.4 +// Project: https://www.npmjs.com/package/node-calendar +// Definitions by: Luzian Zagadinow +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface IDayOfWeekMonth extends Array { + /** dayOfMonth */ + 0: number; + + /** dayOfWeek */ + 1: number; +} + +interface IWeekRow extends Array { + [dayIndex: number]: T; +} + +interface IMonthGrid extends Array> { + [weekRowIndex: number]: IWeekRow; +} + +interface IMonthRow extends Array> { + [monthColumnIndex: number]: IMonthGrid; +} + +interface IYearGrid extends Array>{ + [monthRowIndex: number]: IMonthRow; +} + +/** + * 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): IDayOfWeekMonth[]; + + /** + * 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; + + /** + * 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; + + /** + * 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; + + /** + * 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; + + /** + * 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; + + /** + * 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; + } + + // Undocumented + //export function isleap(year: number): boolean; + //export function leapdays(beginYear: number, endYear: number): number; + //export function monthrange(year: number, month: number): number[]; + //export function weekday(year: number, month: number, day: number): number; + //export function timegm(dateParams: number[]): number; + //export function IllegalLocaleError(): Error; + //export function IllegalDayError(): Error; + //export function IllegalMonthError(): Error; + //export function IllegalTimeError(): Error; + //export function IllegalWeekdayError(): Error; +} \ No newline at end of file diff --git a/node-calendar/package.json b/node-calendar/package.json new file mode 100755 index 0000000000..8cc162a957 --- /dev/null +++ b/node-calendar/package.json @@ -0,0 +1,14 @@ +{ + "name": "node-calendar.d.ts", + "version": "0.0.1", + "description": "Type definitions for node-calendar v0.1.4", + "main": "node-calendar-tests", + "scripts": { + "test": "node node-calendar-tests" + }, + "author": "Luzian Zagadinow (https://github.com/luzianz)", + "license": "MIT", + "dependencies": { + "node-calendar": "^0.1.4" + } +} \ No newline at end of file From c8436fbe1eb00d52f7ed123311a64d5bded7ee87 Mon Sep 17 00:00:00 2001 From: Luzian Zagadinow Date: Wed, 3 Jun 2015 10:29:07 -0400 Subject: [PATCH 2/9] removed extraneous files --- node-calendar/.gitignore | 4 ---- node-calendar/package.json | 14 -------------- 2 files changed, 18 deletions(-) delete mode 100644 node-calendar/.gitignore delete mode 100755 node-calendar/package.json diff --git a/node-calendar/.gitignore b/node-calendar/.gitignore deleted file mode 100644 index 76136c9e9a..0000000000 --- a/node-calendar/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.js -tsconfig.json -node_modules -.settings \ No newline at end of file diff --git a/node-calendar/package.json b/node-calendar/package.json deleted file mode 100755 index 8cc162a957..0000000000 --- a/node-calendar/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "node-calendar.d.ts", - "version": "0.0.1", - "description": "Type definitions for node-calendar v0.1.4", - "main": "node-calendar-tests", - "scripts": { - "test": "node node-calendar-tests" - }, - "author": "Luzian Zagadinow (https://github.com/luzianz)", - "license": "MIT", - "dependencies": { - "node-calendar": "^0.1.4" - } -} \ No newline at end of file From 08fee9265fb493ba6a308f009677696ee063a5d0 Mon Sep 17 00:00:00 2001 From: Luzian Zagadinow Date: Thu, 4 Jun 2015 00:18:28 -0400 Subject: [PATCH 3/9] remove IDayOfWeekMonth in favor of a tuple of [number, number] with refactor --- node-calendar/node-calendar-tests.ts | 3 +-- node-calendar/node-calendar.d.ts | 14 +++----------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/node-calendar/node-calendar-tests.ts b/node-calendar/node-calendar-tests.ts index 5a4a40a466..6de5d6cc48 100644 --- a/node-calendar/node-calendar-tests.ts +++ b/node-calendar/node-calendar-tests.ts @@ -1,5 +1,4 @@ /// -/// import node_calendar = require('node-calendar'); @@ -97,7 +96,7 @@ function assertIsNumber(n: number) { assert(typeof n == 'number', 'Should be a number'); } -function assertDayOfWeekMonth(d: IDayOfWeekMonth) { +function assertDayOfWeekMonth(d: [number, number]) { assert(d instanceof Array, 'Day of weak/month should be an array'); assert(d.length == 2, 'Day of weak/month array should contain 2 items'); assert(typeof d[0] == 'number', 'Day of month should be a number'); diff --git a/node-calendar/node-calendar.d.ts b/node-calendar/node-calendar.d.ts index a1c3f0500a..3839d65410 100755 --- a/node-calendar/node-calendar.d.ts +++ b/node-calendar/node-calendar.d.ts @@ -3,14 +3,6 @@ // Definitions by: Luzian Zagadinow // Definitions: https://github.com/borisyankov/DefinitelyTyped -interface IDayOfWeekMonth extends Array { - /** dayOfMonth */ - 0: number; - - /** dayOfWeek */ - 1: number; -} - interface IWeekRow extends Array { [dayIndex: number]: T; } @@ -183,7 +175,7 @@ declare module 'node-calendar' { * @param {number} month * Month for which the calendar should be generated. */ - itermonthdays2(year: number, month: number): IDayOfWeekMonth[]; + itermonthdays2(year: number, month: number): [number, number][]; /** * A matrix (array of array) representing a month's calendar. @@ -217,7 +209,7 @@ declare module 'node-calendar' { * @param {number} month * Month for which the calendar should be generated. */ - monthdays2calendar(year: number, month: number): IMonthGrid; + monthdays2calendar(year: number, month: number): IMonthGrid<[number, number]>; /** * The specified year ready for formatting. The return value is an array @@ -254,7 +246,7 @@ declare module 'node-calendar' { * @param {number} width * The number of months to include in each row. Default: 3 */ - yeardays2calendar(year: number, width?: number): IYearGrid; + yeardays2calendar(year: number, width?: number): IYearGrid<[number, number]>; } // Undocumented From 66feb94be0a3c2f60cd2a64744f271c8fb3748a6 Mon Sep 17 00:00:00 2001 From: Luzian Zagadinow Date: Thu, 4 Jun 2015 01:38:15 -0400 Subject: [PATCH 4/9] add missing definitions for module functions add line breaks in documentation to make readable --- node-calendar/node-calendar.d.ts | 169 ++++++++++++++++++++++++++++--- 1 file changed, 154 insertions(+), 15 deletions(-) diff --git a/node-calendar/node-calendar.d.ts b/node-calendar/node-calendar.d.ts index 3839d65410..ae4b16cad1 100755 --- a/node-calendar/node-calendar.d.ts +++ b/node-calendar/node-calendar.d.ts @@ -15,7 +15,7 @@ interface IMonthRow extends Array> { [monthColumnIndex: number]: IMonthGrid; } -interface IYearGrid extends Array>{ +interface IYearGrid extends Array> { [monthRowIndex: number]: IMonthRow; } @@ -59,7 +59,7 @@ declare module 'node-calendar' { export var MARCH: number; /** 4 */ - export var APRIL:number; + export var APRIL: number; /** 5 */ export var MAY: number; @@ -150,6 +150,7 @@ declare module 'node-calendar' { * * @param {number} year * Year for which the calendar should be generated. + * * @param {number} month * Month for which the calendar should be generated. */ @@ -161,6 +162,7 @@ declare module 'node-calendar' { * * @param {number} year * Year for which the calendar should be generated. + * * @param {number} month * Month for which the calendar should be generated. */ @@ -172,6 +174,7 @@ declare module 'node-calendar' { * * @param {number} year * Year for which the calendar should be generated. + * * @param {number} month * Month for which the calendar should be generated. */ @@ -183,6 +186,7 @@ declare module 'node-calendar' { * * @param {number} year * Year for which the calendar should be generated. + * * @param {number} month * Month for which the calendar should be generated. */ @@ -194,6 +198,7 @@ declare module 'node-calendar' { * * @param {number} year * Year for which the calendar should be generated. + * * @param {number} month * Month for which the calendar should be generated. */ @@ -206,6 +211,7 @@ declare module 'node-calendar' { * * @param {number} year * Year for which the calendar should be generated. + * * @param {number} month * Month for which the calendar should be generated. */ @@ -219,6 +225,7 @@ declare module 'node-calendar' { * * @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 */ @@ -230,7 +237,8 @@ declare module 'node-calendar' { * month are zero. * * @param {number} year - * Year for which the calendar should be generated. + * Year for which the calendar should be generated + * * @param {number} width * The number of months to include in each row. Default: 3 */ @@ -242,22 +250,153 @@ declare module 'node-calendar' { * Day numbers outside this month are zero. * * @param {number} year - * Year for which the calendar should be generated. + * 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]>; } - // Undocumented - //export function isleap(year: number): boolean; - //export function leapdays(beginYear: number, endYear: number): number; - //export function monthrange(year: number, month: number): number[]; - //export function weekday(year: number, month: number, day: number): number; - //export function timegm(dateParams: number[]): number; - //export function IllegalLocaleError(): Error; - //export function IllegalDayError(): Error; - //export function IllegalMonthError(): Error; - //export function IllegalTimeError(): Error; - //export function IllegalWeekdayError(): Error; + /** + * @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[]} + * starting weekday (0-6 ~ Mon-Sun) and number of days (28-31) for year, month. + */ + export function monthrange(year: number, month: 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); + + /** + * 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. + * + * @param {string} message + * Optional custom error message. + */ + export class IllegalLocaleError implements Error { + public name: string; + public message: string; + constructor(message?: string) + } + + /** + * Error indicating a day index specified outside of the valid range. + * + * @param {string} message + * Optional custom error message. + */ + export class IllegalDayError implements Error { + public name: string; + public message: string; + constructor(message?: string) + } + + /** + * Error indicating a month index specified outside of the expected range (1-12 ~ Jan-Dec). + * + * @param {string} message + * Optional custom error message. + */ + export class IllegalMonthError implements Error { + public name: string; + public message: string; + constructor(message?: string) + } + + /** + * Error indicating a time element is outside of the valid range. + * + * @param {string} message + * Optional custom error message. + */ + export class IllegalTimeError implements Error { + public name: string; + public message: string; + constructor(message?: string) + } + + /** + * Error indicating a weekday index specified outside of the expected range (0-6 ~ Mon-Sun). + * + * @param {string} message + * Optional custom error message. + */ + export class IllegalWeekdayError implements Error { + public name: string; + public message: string; + constructor(message?: string) + } } \ No newline at end of file From cc6e98cc6be9849851c2d8879ec5c9134145b988 Mon Sep 17 00:00:00 2001 From: Luzian Zagadinow Date: Thu, 4 Jun 2015 01:46:31 -0400 Subject: [PATCH 5/9] add tests to reflect new definitions --- node-calendar/node-calendar-tests.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/node-calendar/node-calendar-tests.ts b/node-calendar/node-calendar-tests.ts index 6de5d6cc48..b57cd9f845 100644 --- a/node-calendar/node-calendar-tests.ts +++ b/node-calendar/node-calendar-tests.ts @@ -88,6 +88,25 @@ assertYearGrid(cal.yeardatescalendar(2009, 3), assertIsDate); assertYearGrid(cal.yeardays2calendar(2008, 2), assertDayOfWeekMonth); assertYearGrid(cal.yeardayscalendar(2007, 4), assertIsNumber); +node_calendar.setlocale('en_US'); + +assertIsError(new node_calendar.IllegalDayError()); +assertIsError(new node_calendar.IllegalLocaleError()); +assertIsError(new node_calendar.IllegalMonthError()); +assertIsError(new node_calendar.IllegalTimeError); +assertIsError(new node_calendar.IllegalWeekdayError()); + +assertIsBoolean(node_calendar.isleap(2000)); +assertIsNumber(node_calendar.weekday(2015, node_calendar.JULY, 7)); +assertIsNumber(node_calendar.leapdays(2000, 2010)); + +node_calendar.monthrange(2015, node_calendar.JANUARY).forEach(assertIsNumber); + +var timegmt:[number,number,number,number,number,number] = [2014, node_calendar.JULY, 7, 12, 41, 59]; +assertIsNumber(node_calendar.timegm(timegmt)); + + +// FUNCTIONS ------------------------------------------------------------------ function assertIsDate(d: Date) { assert(d instanceof Date, 'Should be a date'); } @@ -96,6 +115,10 @@ function assertIsNumber(n: number) { assert(typeof n == 'number', 'Should be a number'); } +function assertIsBoolean(b: boolean) { + assert(typeof b == 'boolean', 'Should be a boolean'); +} + function assertDayOfWeekMonth(d: [number, number]) { assert(d instanceof Array, 'Day of weak/month should be an array'); assert(d.length == 2, 'Day of weak/month array should contain 2 items'); @@ -122,4 +145,9 @@ function assertYearGrid(grid: IYearGrid, assertItemType: (item: T) => void function assert(condition: boolean, msg?: string): void { if (condition) return; throw new Error(msg); +} + +function assertIsError(error: Error) { + assert(typeof error.name == 'string', 'Error name should exist and be a string'); + assert(typeof error.message == 'string', 'Error message should exist and be a string'); } \ No newline at end of file From 7c4b699df0acd2108fccf00e7fed3e8933eb2327 Mon Sep 17 00:00:00 2001 From: Luzian Zagadinow Date: Thu, 4 Jun 2015 01:49:16 -0400 Subject: [PATCH 6/9] specify return type of setlocal() --- node-calendar/node-calendar.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node-calendar/node-calendar.d.ts b/node-calendar/node-calendar.d.ts index ae4b16cad1..6f2b7814b6 100755 --- a/node-calendar/node-calendar.d.ts +++ b/node-calendar/node-calendar.d.ts @@ -301,7 +301,7 @@ declare module 'node-calendar' { * * @throws {IllegalLocaleError} if the provided locale is invalid. */ - export function setlocale(locale?: string); + export function setlocale(locale?: string): void; /** * Unrelated but handy function to calculate Unix timestamp from GMT. From 034379ca892327cb722466975d5baa71981a61cf Mon Sep 17 00:00:00 2001 From: Luzian Zagadinow Date: Thu, 4 Jun 2015 14:18:34 -0400 Subject: [PATCH 7/9] change return type of monthrange to a tuple --- node-calendar/node-calendar.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node-calendar/node-calendar.d.ts b/node-calendar/node-calendar.d.ts index 6f2b7814b6..e37f438fb8 100755 --- a/node-calendar/node-calendar.d.ts +++ b/node-calendar/node-calendar.d.ts @@ -288,10 +288,10 @@ declare module 'node-calendar' { * * @throws {IllegalMonthError} if the provided month is invalid. * - * @return {number[]} + * @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[]; + export function monthrange(year: number, month: number): [number, number]; /** * Sets the locale for use in extracting month and weekday names. From e118e97028b155ef13e755bcee92afbf9425cc1a Mon Sep 17 00:00:00 2001 From: Luzian Zagadinow Date: Thu, 4 Jun 2015 14:29:53 -0400 Subject: [PATCH 8/9] formatting: correct whitespace inconsistencies --- node-calendar/node-calendar.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/node-calendar/node-calendar.d.ts b/node-calendar/node-calendar.d.ts index e37f438fb8..6d5c12eece 100755 --- a/node-calendar/node-calendar.d.ts +++ b/node-calendar/node-calendar.d.ts @@ -348,7 +348,7 @@ declare module 'node-calendar' { */ export class IllegalLocaleError implements Error { public name: string; - public message: string; + public message: string; constructor(message?: string) } @@ -360,7 +360,7 @@ declare module 'node-calendar' { */ export class IllegalDayError implements Error { public name: string; - public message: string; + public message: string; constructor(message?: string) } @@ -372,7 +372,7 @@ declare module 'node-calendar' { */ export class IllegalMonthError implements Error { public name: string; - public message: string; + public message: string; constructor(message?: string) } @@ -384,7 +384,7 @@ declare module 'node-calendar' { */ export class IllegalTimeError implements Error { public name: string; - public message: string; + public message: string; constructor(message?: string) } @@ -396,7 +396,7 @@ declare module 'node-calendar' { */ export class IllegalWeekdayError implements Error { public name: string; - public message: string; + public message: string; constructor(message?: string) } } \ No newline at end of file From 42cb5d2749a91f518edc39cf77464149fb6d055e Mon Sep 17 00:00:00 2001 From: Luzian Zagadinow Date: Thu, 4 Jun 2015 15:07:31 -0400 Subject: [PATCH 9/9] move @param documentation from Error classes at their class level to the constructor where they belong. --- node-calendar/node-calendar.d.ts | 60 ++++++++++++++++---------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/node-calendar/node-calendar.d.ts b/node-calendar/node-calendar.d.ts index 6d5c12eece..204ec69216 100755 --- a/node-calendar/node-calendar.d.ts +++ b/node-calendar/node-calendar.d.ts @@ -340,63 +340,63 @@ declare module 'node-calendar' { */ export function weekday(year: number, month: number, day: number): number; - /** - * Error indicating a nonexistent or unsupported locale specified. - * - * @param {string} message - * Optional custom error message. - */ + /** 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. - * - * @param {string} message - * Optional custom error message. - */ + /** 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). - * - * @param {string} message - * Optional custom error message. - */ + /** 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. - * - * @param {string} message - * Optional custom error message. - */ + /** 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). - * - * @param {string} message - * Optional custom error message. - */ + /** 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) } } \ No newline at end of file