MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeDateParts

Function makeDateParts

packages/cli/src/internal/prompt/date.ts:328–357  ·  view source on GitHub ↗
(
  dateMask: string,
  date: globalThis.Date,
  locales: Prompt.Prompt.DateOptions["locales"]
)

Source from the content-addressed store, hash-verified

326}
327
328const makeDateParts = (
329 dateMask: string,
330 date: globalThis.Date,
331 locales: Prompt.Prompt.DateOptions["locales"]
332) => {
333 const parts: Array<DatePart> = []
334 let result: RegExpExecArray | null = null
335 // eslint-disable-next-line no-cond-assign
336 while (result = DATE_PART_REGEX.exec(dateMask)) {
337 const match = result.shift()
338 const index = result.findIndex((group) => group !== undefined)
339 if (index in regexGroups) {
340 const token = (result[index] || match)!
341 parts.push(regexGroups[index]({ token, date, parts, locales }))
342 } else {
343 parts.push(new Token({ token: (result[index] || match)!, date, parts, locales }))
344 }
345 }
346 const orderedParts = parts.reduce((array, element) => {
347 const lastElement = array[array.length - 1]
348 if (element.isToken() && lastElement !== undefined && lastElement.isToken()) {
349 lastElement.setValue(element.token)
350 } else {
351 array.push(element)
352 }
353 return array
354 }, Arr.empty<DatePart>())
355 parts.splice(0, parts.length, ...orderedParts)
356 return parts
357}
358
359interface DatePartParams {
360 readonly token: string

Callers 1

dateFunction · 0.85

Calls 2

isTokenMethod · 0.80
setValueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…