MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / formatDate

Function formatDate

packages/app-core/src/lib/template-render.ts:70–110  ·  view source on GitHub ↗
(date: Date, format: string)

Source from the content-addressed store, hash-verified

68 * `[brackets]` to protect letters that would otherwise be read as tokens.
69 */
70export function formatDate(date: Date, format: string): string {
71 const year = date.getFullYear()
72 const month = date.getMonth()
73 const day = date.getDate()
74 const hours = date.getHours()
75 const minutes = date.getMinutes()
76 const seconds = date.getSeconds()
77 return format.replace(DATE_FORMAT_RE, (match, escaped: string | undefined) => {
78 if (escaped !== undefined) return escaped
79 switch (match) {
80 case 'YYYY':
81 return String(year)
82 case 'YY':
83 return pad2(year % 100)
84 case 'MMMM':
85 return localeName(date, 'month', 'long')
86 case 'MMM':
87 return localeName(date, 'month', 'short')
88 case 'MM':
89 return pad2(month + 1)
90 case 'M':
91 return String(month + 1)
92 case 'DD':
93 return pad2(day)
94 case 'D':
95 return String(day)
96 case 'dddd':
97 return localeName(date, 'weekday', 'long')
98 case 'ddd':
99 return localeName(date, 'weekday', 'short')
100 case 'HH':
101 return pad2(hours)
102 case 'mm':
103 return pad2(minutes)
104 case 'ss':
105 return pad2(seconds)
106 default:
107 return match
108 }
109 })
110}
111
112function isoWeekParts(date: Date): { week: number; year: number } {
113 // Shift to the Thursday of the current ISO week, working in UTC to avoid DST.

Callers 2

substituteTokensFunction · 0.70

Calls 2

localeNameFunction · 0.85
pad2Function · 0.70

Tested by

no test coverage detected