diff --git a/types/moment-business-time/index.d.ts b/types/moment-business-time/index.d.ts new file mode 100644 index 0000000000..dc4022f161 --- /dev/null +++ b/types/moment-business-time/index.d.ts @@ -0,0 +1,41 @@ +// Type definitions for moment-business-time 0.7 +// Project: https://github.com/lennym/moment-business-time +// Definitions by: Tomasz Nguyen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/*~ On this line, import the module which this module adds to */ +import * as moment from 'moment'; + +/*~ Here, declare the same module as the one you imported above */ +declare module 'moment' { + interface Moment { + nextWorkingDay: () => Moment; + nextWorkingTime: () => Moment; + + lastWorkingDay: () => Moment; + lastWorkingTime: () => Moment; + + addWorkingTime: (...args: Array) => Moment; + subtractWorkingTime: (...args: Array) => Moment; + + workingDiff: (moment: Moment, unit: unitOfTime.Base, fractions?: boolean) => Moment; + + isWorkingDay: () => boolean; + isWorkingTime: () => boolean; + } + + interface WorkingHoursMap { + 0: string[] | null; + 1: string[] | null; + 2: string[] | null; + 3: string[] | null; + 4: string[] | null; + 5: string[] | null; + 6: string[] | null; + } + + interface LocaleSpecification { + workinghours?: WorkingHoursMap; + holidays?: string[]; + } +} diff --git a/types/moment-business-time/moment-business-time-tests.ts b/types/moment-business-time/moment-business-time-tests.ts new file mode 100644 index 0000000000..79f25a720a --- /dev/null +++ b/types/moment-business-time/moment-business-time-tests.ts @@ -0,0 +1,56 @@ +import * as moment from 'moment'; +import 'moment-business-time'; + +moment('2015-02-28T10:00:00Z').nextWorkingDay(); +moment('2015-02-28T20:00:00Z').nextWorkingDay(); +moment('2015-02-28T10:00:00Z').nextWorkingTime(); +moment('2015-02-28T20:00:00Z').nextWorkingTime(); +moment('2015-02-28T10:00:00Z').lastWorkingDay(); +// Fri Feb 27 2015 10:00:00 GMT+0000 +moment('2015-02-28T20:00:00Z').lastWorkingDay(); +// Fri Feb 27 2015 20:00:00 GMT+0000 +moment('2015-02-27T10:00:00Z').addWorkingTime(5, 'hours'); +// Fri Feb 27 2015 15:00:00 GMT+0000 +moment('2015-02-28T10:00:00Z').addWorkingTime(5, 'hours'); +// Mon Mar 02 2015 14:00:00 GMT+0000 +moment('2015-02-27T10:00:00Z').addWorkingTime(5, 'hours', 30, 'minutes'); +// Fri Feb 27 2015 15:30:00 GMT+0000 +moment('2015-02-27T16:00:00Z').subtractWorkingTime(5, 'hours'); +// Fri Feb 27 2015 11:00:00 GMT+0000 +moment('2015-02-28T16:00:00Z').subtractWorkingTime(5, 'hours'); +// Fri Feb 27 2015 12:00:00 GMT+0000 +moment('2015-02-27T16:00:00Z').subtractWorkingTime(5, 'hours', 30, 'minutes'); +// Fri Feb 27 2015 10:30:00 GMT+0000 +moment('2015-02-27T16:30:00Z').workingDiff(moment('2015-02-26T12:00:00Z'), 'hours'); +// 12 +moment('2015-02-27T16:30:00Z').workingDiff(moment('2015-02-26T12:00:00Z'), 'hours', true); +// 12.5 +// set opening time to 09:30 and close early on Wednesdays +moment.updateLocale('en', { + workinghours: { + 0: null, + 1: ['09:30:00', '17:00:00'], + 2: ['09:30:00', '17:00:00'], + 3: ['09:30:00', '13:00:00'], + 4: ['09:30:00', '17:00:00'], + 5: ['09:30:00', '17:00:00'], + 6: null + } +}); +moment('2015-02-25T15:00:00Z').isWorkingTime(); // false +moment('2015-02-23T09:00:00Z').isWorkingTime(); // false +moment.updateLocale('en', { + holidays: [ + '2015-05-04' + ] +}); +moment('2015-05-04T09:30:00Z').isWorkingDay(); // false +moment.updateLocale('en', { + holidays: [ + '*-12-25' + ] +}); +moment('2015-12-25T16:30:00Z').isWorkingDay(); // false +moment('2016-12-25T16:30:00Z').isWorkingDay(); // false +moment('2017-12-25T16:30:00Z').isWorkingDay(); // false +moment('2018-12-25T16:30:00Z').isWorkingDay(); // false diff --git a/types/moment-business-time/tsconfig.json b/types/moment-business-time/tsconfig.json new file mode 100644 index 0000000000..c1212caa2f --- /dev/null +++ b/types/moment-business-time/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "moment-business-time-tests.ts" + ] +} diff --git a/types/moment-business-time/tslint.json b/types/moment-business-time/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/moment-business-time/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }