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

Function makeDateParts

packages/effect/src/unstable/cli/Prompt.ts:1773–1802  ·  view source on GitHub ↗
(
  dateMask: string,
  date: globalThis.Date,
  locales: DateOptions["locales"]
)

Source from the content-addressed store, hash-verified

1771}
1772
1773const makeDateParts = (
1774 dateMask: string,
1775 date: globalThis.Date,
1776 locales: DateOptions["locales"]
1777) => {
1778 const parts: Array<DatePart> = []
1779 let result: RegExpExecArray | null = null
1780 // oxlint-disable-next-line no-cond-assign
1781 while (result = DATE_PART_REGEXP.exec(dateMask)) {
1782 const match = result.shift()
1783 const index = result.findIndex((group) => group !== undefined)
1784 if (index in regExpGroups) {
1785 const token = (result[index] || match)!
1786 parts.push(regExpGroups[index]({ token, date, parts, locales }))
1787 } else {
1788 parts.push(new Token({ token: (result[index] || match)!, date, parts, locales }))
1789 }
1790 }
1791 const orderedParts = parts.reduce((array, element) => {
1792 const lastElement = array[array.length - 1]
1793 if (element.isToken() && lastElement !== undefined && lastElement.isToken()) {
1794 lastElement.setValue(element.token)
1795 } else {
1796 array.push(element)
1797 }
1798 return array
1799 }, Arr.empty<DatePart>())
1800 parts.splice(0, parts.length, ...orderedParts)
1801 return parts
1802}
1803
1804interface DatePartParams {
1805 readonly token: string

Callers 1

dateFunction · 0.85

Calls 4

execMethod · 0.80
pushMethod · 0.80
isTokenMethod · 0.80
setValueMethod · 0.45

Tested by

no test coverage detected