MCPcopy Create free account
hub / github.com/adobe/react-spectrum / parseDate

Function parseDate

packages/@internationalized/date/src/string.ts:57–74  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

55
56/** Parses an ISO 8601 date string, with no time components. */
57export function parseDate(value: string): CalendarDate {
58 let m = value.match(DATE_RE);
59 if (!m) {
60 if (ABSOLUTE_RE.test(value)) {
61 throw new Error(`Invalid ISO 8601 date string: ${value}. Use parseAbsolute() instead.`);
62 }
63 throw new Error('Invalid ISO 8601 date string: ' + value);
64 }
65
66 let date: Mutable<CalendarDate> = new CalendarDate(
67 parseNumber(m[1], 0, 9999),
68 parseNumber(m[2], 1, 12),
69 1
70 );
71
72 date.day = parseNumber(m[3], 1, date.calendar.getDaysInMonth(date));
73 return date as CalendarDate;
74}
75
76/** Parses an ISO 8601 date and time string, with no time zone. */
77export function parseDateTime(value: string): CalendarDateTime {

Callers 13

useHiddenDateInputFunction · 0.90
RenderFunction · 0.90
InvalidWithTimeFunction · 0.90
DefaultValueZonedFunction · 0.90

Calls 2

parseNumberFunction · 0.85
getDaysInMonthMethod · 0.65

Tested by

no test coverage detected