import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _createSuper from "@babel/runtime/helpers/esm/createSuper"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import { Parser } from "../Parser.js"; import { parseNDigits, normalizeTwoDigitYear, mapValue } from "../utils.js"; import getUTCWeekYear from "../../../_lib/getUTCWeekYear/index.js"; import startOfUTCWeek from "../../../_lib/startOfUTCWeek/index.js"; // Local week-numbering year export var LocalWeekYearParser = /*#__PURE__*/function (_Parser) { _inherits(LocalWeekYearParser, _Parser); var _super = _createSuper(LocalWeekYearParser); function LocalWeekYearParser() { var _this; _classCallCheck(this, LocalWeekYearParser); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "priority", 130); _defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['y', 'R', 'u', 'Q', 'q', 'M', 'L', 'I', 'd', 'D', 'i', 't', 'T']); return _this; } _createClass(LocalWeekYearParser, [{ key: "parse", value: function parse(dateString, token, match) { var valueCallback = function valueCallback(year) { return { year: year, isTwoDigitYear: token === 'YY' }; }; switch (token) { case 'Y': return mapValue(parseNDigits(4, dateString), valueCallback); case 'Yo': return mapValue(match.ordinalNumber(dateString, { unit: 'year' }), valueCallback); default: return mapValue(parseNDigits(token.length, dateString), valueCallback); } } }, { key: "validate", value: function validate(_date, value) { return value.isTwoDigitYear || value.year > 0; } }, { key: "set", value: function set(date, flags, value, options) { var currentYear = getUTCWeekYear(date, options); if (value.isTwoDigitYear) { var normalizedTwoDigitYear = normalizeTwoDigitYear(value.year, currentYear); date.setUTCFullYear(normalizedTwoDigitYear, 0, options.firstWeekContainsDate); date.setUTCHours(0, 0, 0, 0); return startOfUTCWeek(date, options); } var year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year; date.setUTCFullYear(year, 0, options.firstWeekContainsDate); date.setUTCHours(0, 0, 0, 0); return startOfUTCWeek(date, options); } }]); return LocalWeekYearParser; }(Parser);