22 lines
1.8 KiB
JavaScript
22 lines
1.8 KiB
JavaScript
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 startOfUTCWeek(dirtyDate, options) {
|
|
var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
|
|
|
|
requiredArgs(1, 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 = date.getUTCDay();
|
|
var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
|
|
date.setUTCDate(date.getUTCDate() - diff);
|
|
date.setUTCHours(0, 0, 0, 0);
|
|
return date;
|
|
} |