MCPcopy Index your code
hub / github.com/adobe/react-spectrum / dateToString

Function dateToString

packages/@internationalized/date/src/string.ts:218–230  ·  view source on GitHub ↗
(date: CalendarDate)

Source from the content-addressed store, hash-verified

216}
217
218export function dateToString(date: CalendarDate): string {
219 let gregorianDate = toCalendar(date, new GregorianCalendar());
220 let year: string;
221 if (gregorianDate.era === 'BC') {
222 year =
223 gregorianDate.year === 1
224 ? '0000'
225 : '-' + String(Math.abs(1 - gregorianDate.year)).padStart(6, '00');
226 } else {
227 year = String(gregorianDate.year).padStart(4, '0');
228 }
229 return `${year}-${String(gregorianDate.month).padStart(2, '0')}-${String(gregorianDate.day).padStart(2, '0')}`;
230}
231
232export function dateTimeToString(date: AnyDateTime): string {
233 // @ts-ignore

Callers 2

toStringMethod · 0.90
dateTimeToStringFunction · 0.85

Calls 1

toCalendarFunction · 0.90

Tested by

no test coverage detected