Skip to content

Commit

Permalink
feat: add day strings to customParseFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
mlogozzo committed Jan 12, 2025
1 parent 45e5c9d commit e4ca7c0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')],
Expand Down

0 comments on commit e4ca7c0

Please sign in to comment.