main page
This commit is contained in:
86
node_modules/date-fns/esm/parse/_lib/parsers/MonthParser.js
generated
vendored
Normal file
86
node_modules/date-fns/esm/parse/_lib/parsers/MonthParser.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
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 { mapValue, parseNDigits, parseNumericPattern } from "../utils.js";
|
||||
import { Parser } from "../Parser.js";
|
||||
import { numericPatterns } from "../constants.js";
|
||||
export var MonthParser = /*#__PURE__*/function (_Parser) {
|
||||
_inherits(MonthParser, _Parser);
|
||||
var _super = _createSuper(MonthParser);
|
||||
function MonthParser() {
|
||||
var _this;
|
||||
_classCallCheck(this, MonthParser);
|
||||
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), "incompatibleTokens", ['Y', 'R', 'q', 'Q', 'L', 'w', 'I', 'D', 'i', 'e', 'c', 't', 'T']);
|
||||
_defineProperty(_assertThisInitialized(_this), "priority", 110);
|
||||
return _this;
|
||||
}
|
||||
_createClass(MonthParser, [{
|
||||
key: "parse",
|
||||
value: function parse(dateString, token, match) {
|
||||
var valueCallback = function valueCallback(value) {
|
||||
return value - 1;
|
||||
};
|
||||
switch (token) {
|
||||
// 1, 2, ..., 12
|
||||
case 'M':
|
||||
return mapValue(parseNumericPattern(numericPatterns.month, dateString), valueCallback);
|
||||
// 01, 02, ..., 12
|
||||
case 'MM':
|
||||
return mapValue(parseNDigits(2, dateString), valueCallback);
|
||||
// 1st, 2nd, ..., 12th
|
||||
case 'Mo':
|
||||
return mapValue(match.ordinalNumber(dateString, {
|
||||
unit: 'month'
|
||||
}), valueCallback);
|
||||
// Jan, Feb, ..., Dec
|
||||
case 'MMM':
|
||||
return match.month(dateString, {
|
||||
width: 'abbreviated',
|
||||
context: 'formatting'
|
||||
}) || match.month(dateString, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
// J, F, ..., D
|
||||
case 'MMMMM':
|
||||
return match.month(dateString, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
// January, February, ..., December
|
||||
case 'MMMM':
|
||||
default:
|
||||
return match.month(dateString, {
|
||||
width: 'wide',
|
||||
context: 'formatting'
|
||||
}) || match.month(dateString, {
|
||||
width: 'abbreviated',
|
||||
context: 'formatting'
|
||||
}) || match.month(dateString, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "validate",
|
||||
value: function validate(_date, value) {
|
||||
return value >= 0 && value <= 11;
|
||||
}
|
||||
}, {
|
||||
key: "set",
|
||||
value: function set(date, _flags, value) {
|
||||
date.setUTCMonth(value, 1);
|
||||
date.setUTCHours(0, 0, 0, 0);
|
||||
return date;
|
||||
}
|
||||
}]);
|
||||
return MonthParser;
|
||||
}(Parser);
|
||||
Reference in New Issue
Block a user