project files added
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addBusinessDays } from 'date-fns'
|
||||
export default addBusinessDays
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addBusinessDays;
|
||||
|
||||
var _index = _interopRequireDefault(require("../isWeekend/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name addBusinessDays
|
||||
* @category Day Helpers
|
||||
* @summary Add the specified number of business days (mon - fri) to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of business days (mon - fri) to the given date, ignoring weekends.
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of business days to be added
|
||||
* @returns {Date} the new date with the business days added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 10 business days to 1 September 2014:
|
||||
* var result = addBusinessDays(new Date(2014, 8, 1), 10)
|
||||
* //=> Mon Sep 15 2014 00:00:00 (skipped weekend days)
|
||||
*/
|
||||
function addBusinessDays(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index2.default)(dirtyDate);
|
||||
var amount = (0, _index3.default)(dirtyAmount);
|
||||
if (isNaN(amount)) return new Date(NaN);
|
||||
var hours = date.getHours();
|
||||
var sign = amount < 0 ? -1 : 1;
|
||||
date.setDate(date.getDate() + (0, _index3.default)(amount / 5) * 7);
|
||||
amount %= 5; // to get remaining days not part of a full week
|
||||
|
||||
var shiftSize = Math.abs(amount); // only loops over remaining days or if day is a weekend, ensures a business day is returned
|
||||
|
||||
while (shiftSize > 0 || (0, _index.default)(date)) {
|
||||
if (!(0, _index.default)(date)) shiftSize -= 1;
|
||||
date.setDate(date.getDate() + sign);
|
||||
}
|
||||
|
||||
date.setHours(hours);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addBusinessDays/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
Reference in New Issue
Block a user