aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/date-fns/esm/_lib/setUTCDay/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/date-fns/esm/_lib/setUTCDay/index.js')
-rw-r--r--node_modules/date-fns/esm/_lib/setUTCDay/index.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/node_modules/date-fns/esm/_lib/setUTCDay/index.js b/node_modules/date-fns/esm/_lib/setUTCDay/index.js
new file mode 100644
index 0000000..3af6209
--- /dev/null
+++ b/node_modules/date-fns/esm/_lib/setUTCDay/index.js
@@ -0,0 +1,23 @@
+import toDate from "../../toDate/index.js";
+import requiredArgs from "../requiredArgs/index.js";
+import toInteger from "../toInteger/index.js";
+import { getDefaultOptions } from "../defaultOptions/index.js";
+export default function setUTCDay(dirtyDate, dirtyDay, options) {
+ var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
+ requiredArgs(2, arguments);
+ var defaultOptions = getDefaultOptions();
+ var weekStartsOn = toInteger((_ref = (_ref2 = (_ref3 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.weekStartsOn) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.weekStartsOn) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.weekStartsOn) !== null && _ref !== void 0 ? _ref : 0);
+
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
+ }
+ var date = toDate(dirtyDate);
+ var day = toInteger(dirtyDay);
+ var currentDay = date.getUTCDay();
+ var remainder = day % 7;
+ var dayIndex = (remainder + 7) % 7;
+ var diff = (dayIndex < weekStartsOn ? 7 : 0) + day - currentDay;
+ date.setUTCDate(date.getUTCDate() + diff);
+ return date;
+} \ No newline at end of file
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage