registration
This commit is contained in:
60
frontend/style/node_modules/date-fns/differenceInBusinessDays.js
generated
vendored
60
frontend/style/node_modules/date-fns/differenceInBusinessDays.js
generated
vendored
@@ -1,11 +1,13 @@
|
||||
"use strict";
|
||||
exports.differenceInBusinessDays = differenceInBusinessDays;
|
||||
var _index = require("./addDays.js");
|
||||
var _index2 = require("./differenceInCalendarDays.js");
|
||||
var _index3 = require("./isSameDay.js");
|
||||
var _index4 = require("./isValid.js");
|
||||
var _index5 = require("./isWeekend.js");
|
||||
var _index6 = require("./toDate.js");
|
||||
import { normalizeDates } from "./_lib/normalizeDates.js";
|
||||
import { addDays } from "./addDays.js";
|
||||
import { differenceInCalendarDays } from "./differenceInCalendarDays.js";
|
||||
import { isSameDay } from "./isSameDay.js";
|
||||
import { isValid } from "./isValid.js";
|
||||
import { isWeekend } from "./isWeekend.js";
|
||||
|
||||
/**
|
||||
* The {@link differenceInBusinessDays} function options.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name differenceInBusinessDays
|
||||
@@ -14,14 +16,13 @@ var _index6 = require("./toDate.js");
|
||||
*
|
||||
* @description
|
||||
* Get the number of business day periods between the given dates.
|
||||
* Business days being days that arent in the weekend.
|
||||
* Business days being days that aren't in the weekend.
|
||||
* Like `differenceInCalendarDays`, the function removes the times from
|
||||
* the dates before calculating the difference.
|
||||
*
|
||||
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
||||
*
|
||||
* @param dateLeft - The later date
|
||||
* @param dateRight - The earlier date
|
||||
* @param laterDate - The later date
|
||||
* @param earlierDate - The earlier date
|
||||
* @param options - An object with options
|
||||
*
|
||||
* @returns The number of business days
|
||||
*
|
||||
@@ -58,31 +59,32 @@ var _index6 = require("./toDate.js");
|
||||
* )
|
||||
* //=> 0
|
||||
*/
|
||||
function differenceInBusinessDays(dateLeft, dateRight) {
|
||||
const _dateLeft = (0, _index6.toDate)(dateLeft);
|
||||
let _dateRight = (0, _index6.toDate)(dateRight);
|
||||
|
||||
if (!(0, _index4.isValid)(_dateLeft) || !(0, _index4.isValid)(_dateRight))
|
||||
return NaN;
|
||||
|
||||
const calendarDifference = (0, _index2.differenceInCalendarDays)(
|
||||
_dateLeft,
|
||||
_dateRight,
|
||||
export function differenceInBusinessDays(laterDate, earlierDate, options) {
|
||||
const [laterDate_, earlierDate_] = normalizeDates(
|
||||
options?.in,
|
||||
laterDate,
|
||||
earlierDate,
|
||||
);
|
||||
const sign = calendarDifference < 0 ? -1 : 1;
|
||||
|
||||
const weeks = Math.trunc(calendarDifference / 7);
|
||||
if (!isValid(laterDate_) || !isValid(earlierDate_)) return NaN;
|
||||
|
||||
const diff = differenceInCalendarDays(laterDate_, earlierDate_);
|
||||
const sign = diff < 0 ? -1 : 1;
|
||||
const weeks = Math.trunc(diff / 7);
|
||||
|
||||
let result = weeks * 5;
|
||||
_dateRight = (0, _index.addDays)(_dateRight, weeks * 7);
|
||||
let movingDate = addDays(earlierDate_, weeks * 7);
|
||||
|
||||
// the loop below will run at most 6 times to account for the remaining days that don't makeup a full week
|
||||
while (!(0, _index3.isSameDay)(_dateLeft, _dateRight)) {
|
||||
while (!isSameDay(laterDate_, movingDate)) {
|
||||
// sign is used to account for both negative and positive differences
|
||||
result += (0, _index5.isWeekend)(_dateRight) ? 0 : sign;
|
||||
_dateRight = (0, _index.addDays)(_dateRight, sign);
|
||||
result += isWeekend(movingDate, options) ? 0 : sign;
|
||||
movingDate = addDays(movingDate, sign);
|
||||
}
|
||||
|
||||
// Prevent negative zero
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
|
||||
// Fallback for modularized imports:
|
||||
export default differenceInBusinessDays;
|
||||
|
||||
Reference in New Issue
Block a user