From e4ca7c03b1b2214940e0d247ec4064ec0afd3afb Mon Sep 17 00:00:00 2001 From: mlogozzo Date: Fri, 10 Jan 2025 18:31:07 +1100 Subject: [PATCH] feat: add day strings to customParseFormat --- src/plugin/customParseFormat/index.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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')],