Merge pull request #21829 from swist/master

Adds types for moment-business-time@0.7.1
This commit is contained in:
Bowden Kelly
2017-12-06 16:02:58 -08:00
committed by GitHub
4 changed files with 121 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
// Type definitions for moment-business-time 0.7
// Project: https://github.com/lennym/moment-business-time
// Definitions by: Tomasz Nguyen <https://github.com/swist>
// 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<number | unitOfTime.Base>) => Moment;
subtractWorkingTime: (...args: Array<number | unitOfTime.Base>) => 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[];
}
}
@@ -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
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }