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

Function parseDateTime

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

Source from the content-addressed store, hash-verified

75
76/** Parses an ISO 8601 date and time string, with no time zone. */
77export function parseDateTime(value: string): CalendarDateTime {
78 let m = value.match(DATE_TIME_RE);
79 if (!m) {
80 if (ABSOLUTE_RE.test(value)) {
81 throw new Error(`Invalid ISO 8601 date time string: ${value}. Use parseAbsolute() instead.`);
82 }
83 throw new Error('Invalid ISO 8601 date time string: ' + value);
84 }
85
86 let year = parseNumber(m[1], -9999, 9999);
87 let era = year < 1 ? 'BC' : 'AD';
88
89 let date: Mutable<CalendarDateTime> = new CalendarDateTime(
90 era,
91 year < 1 ? -year + 1 : year,
92 parseNumber(m[2], 1, 12),
93 1,
94 m[4] ? parseNumber(m[4], 0, 23) : 0,
95 m[5] ? parseNumber(m[5], 0, 59) : 0,
96 m[6] ? parseNumber(m[6], 0, 59) : 0,
97 m[7] ? parseNumber(m[7], 0, Infinity) * 1000 : 0
98 );
99
100 date.day = parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));
101 return date as CalendarDateTime;
102}
103
104/**
105 * Parses an ISO 8601 date and time string with a time zone extension and optional UTC offset (e.g.

Callers 5

useHiddenDateInputFunction · 0.90
RenderFunction · 0.90
string.test.jsFile · 0.85

Calls 2

parseNumberFunction · 0.85
getDaysInMonthMethod · 0.65

Tested by

no test coverage detected