Files
klz-cables.com/.pnpm-store/v10/files/99/5e5dfff8b18fd1a15360d46a5b383dda638c94c3b7992825348943f8033cfbbd778400fac1c254d8af68ed2d06a5744607c06d50cebc04dd69f82e884820b9
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

60 lines
1.9 KiB
Plaintext

"use strict";
exports.setDay = setDay;
var _index = require("./_lib/defaultOptions.cjs");
var _index2 = require("./addDays.cjs");
var _index3 = require("./toDate.cjs");
/**
* The {@link setDay} function options.
*/
/**
* @name setDay
* @category Weekday Helpers
* @summary Set the day of the week to the given date.
*
* @description
* Set the day of the week to the given date.
*
* @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).
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
*
* @param date - The date to be changed
* @param day - The day of the week of the new date
* @param options - An object with options.
*
* @returns The new date with the day of the week set
*
* @example
* // Set week day to Sunday, with the default weekStartsOn of Sunday:
* const result = setDay(new Date(2014, 8, 1), 0)
* //=> Sun Aug 31 2014 00:00:00
*
* @example
* // Set week day to Sunday, with a weekStartsOn of Monday:
* const result = setDay(new Date(2014, 8, 1), 0, { weekStartsOn: 1 })
* //=> Sun Sep 07 2014 00:00:00
*/
function setDay(date, day, options) {
const defaultOptions = (0, _index.getDefaultOptions)();
const weekStartsOn =
options?.weekStartsOn ??
options?.locale?.options?.weekStartsOn ??
defaultOptions.weekStartsOn ??
defaultOptions.locale?.options?.weekStartsOn ??
0;
const date_ = (0, _index3.toDate)(date, options?.in);
const currentDay = date_.getDay();
const remainder = day % 7;
const dayIndex = (remainder + 7) % 7;
const delta = 7 - weekStartsOn;
const diff =
day < 0 || day > 6
? day - ((currentDay + delta) % 7)
: ((dayIndex + delta) % 7) - ((currentDay + delta) % 7);
return (0, _index2.addDays)(date_, diff, options);
}