MCPcopy
hub / github.com/rjsf-team/react-jsonschema-form / parseDateString

Function parseDateString

packages/utils/src/parseDateString.ts:10–33  ·  view source on GitHub ↗
(dateString?: string, includeTime = true)

Source from the content-addressed store, hash-verified

8 * @throws - Error when the date cannot be parsed from the string
9 */
10export default function parseDateString(dateString?: string, includeTime = true): DateObject {
11 if (!dateString) {
12 return {
13 year: -1,
14 month: -1,
15 day: -1,
16 hour: includeTime ? -1 : 0,
17 minute: includeTime ? -1 : 0,
18 second: includeTime ? -1 : 0,
19 };
20 }
21 const date = new Date(dateString);
22 if (Number.isNaN(date.getTime())) {
23 throw new Error(`Unable to parse date ${dateString}`);
24 }
25 return {
26 year: date.getUTCFullYear(),
27 month: date.getUTCMonth() + 1, // oh you, javascript.
28 day: date.getUTCDate(),
29 hour: includeTime ? date.getUTCHours() : 0,
30 minute: includeTime ? date.getUTCMinutes() : 0,
31 second: includeTime ? date.getUTCSeconds() : 0,
32 };
33}

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…