diff --git a/src/plugin/customParseFormat/index.js b/src/plugin/customParseFormat/index.js index c7082833c..e3d90673d 100644 --- a/src/plugin/customParseFormat/index.js +++ b/src/plugin/customParseFormat/index.js @@ -1,6 +1,6 @@ import { u } from '../localizedFormat/utils' -const formattingTokens = /(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|Q|YYYY|YY?|ww?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g +const formattingTokens = /(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|Q|YYYY|YY?|ww?|MM?M?M?|Do|DD?|dd?d?d?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g const match1 = /\d/ // 0 - 9 const match2 = /\d\d/ // 00 - 99 @@ -98,6 +98,29 @@ const expressions = { } } }], + dd: [matchWord, function (input) { + const weekdays = getLocalePart('weekdays') + const weekdaysMin = getLocalePart('weekdaysMin') + const matchIndex = (weekdaysMin || weekdays.map(_ => _.slice(0, 2))).indexOf(input) + 1 + if (matchIndex < 1) { + throw new Error() + } + }], + ddd: [matchWord, function (input) { + const weekdays = getLocalePart('weekdays') + const weekdaysShort = getLocalePart('weekdaysShort') + const matchIndex = (weekdaysShort || weekdays.map(_ => _.slice(0, 3))).indexOf(input) + 1 + if (matchIndex < 1) { + throw new Error() + } + }], + dddd: [matchWord, function (input) { + const weekdays = getLocalePart('weekdays') + const matchIndex = weekdays.indexOf(input) + 1 + if (matchIndex < 1) { + throw new Error() + } + }], w: [match1to2, addInput('week')], ww: [match2, addInput('week')], M: [match1to2, addInput('month')],