datility
Version:
Missing javascript Date object utilities
80 lines (79 loc) • 3.21 kB
TypeScript
declare global {
interface Date {
/**
* @name isWorkingDay
* @category Working Days
* @summary Returns true if the date is a working day.
*
* @description
* Returns true if the date is a working day.
*
* @returns {boolean}
*
* @example
* ```ts
* new Date(2022, 5, 6).isWorkingDay() // true, Monday
* new Date(2022, 5, 10).isWorkingDay() // true, Friday
* new Date(2022, 5, 11).isWorkingDay() // false, Saturday
* new Date(2022, 5, 12).isWorkingDay() // false, Sunday
* ```
*/
isWorkingDay(): boolean;
/**
* @name isWeekend
* @category Working Days
* @summary Returns true if the date is weekend.
*
* @description
* Returns true if the date is weekend.
*
* @returns {boolean}
*
* @example
* ```ts
* new Date(2022, 5, 6).isWeekend() // false, Monday
* new Date(2022, 5, 10).isWeekend() // false, Friday
* new Date(2022, 5, 11).isWeekend() // true, Saturday
* new Date(2022, 5, 12).isWeekend() // true, Sunday
* ```
*/
isWeekend(): boolean;
/**
* @name addWorkingDays
* @category Working Days
* @summary Add the specified number of business days (mon - fri) to the date.
*
* @description
* Add the specified number of business days (mon - fri) to the date, ignoring weekends.
*
* @param {number} days - the value of business days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @returns {Date} the new date with the business days added.
*
* @example
* ```ts
* new Date(2022, 5, 6).addWorkingDays(10) // => "Mon Jun 20 2022 00:00:00 GMT+0300 (GMT+03:00)"
* new Date(2022, 5, 20).addWorkingDays(-10) // => "Mon Jun 06 2022 00:00:00 GMT+0300 (GMT+03:00)"
* ```
*/
addWorkingDays(days: number): Date;
/**
* @name subtractWorkingDays
* @category Working Days
* @summary Subtract the specified number of business days (mon - fri) from the date.
*
* @description
* Subtract the specified number of business days (mon - fri) from the date, ignoring weekends.
*
* @param {number} days - the amount of business days to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @returns {Date} the new date with the business days subtracted.
*
* @example
* ```ts
* new Date(2022, 5, 6).subtractWorkingDays(10) // => "Mon May 23 2022 00:00:00 GMT+0300 (GMT+03:00)"
* new Date(2022, 5, 6).subtractWorkingDays(-10) // => "Mon Jun 20 2022 00:00:00 GMT+0300 (GMT+03:00)"
* ```
*/
subtractWorkingDays(days: number): Date;
}
}
export {};