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

Function utcToLocal

packages/utils/src/utcToLocal.ts:8–30  ·  view source on GitHub ↗
(jsonDate: string)

Source from the content-addressed store, hash-verified

6 * @returns - An empty string when `jsonDate` is falsey, otherwise a date string in local format
7 */
8export default function utcToLocal(jsonDate: string) {
9 if (!jsonDate) {
10 return '';
11 }
12
13 // required format of `'yyyy-MM-ddThh:mm' followed by optional ':ss' or ':ss.SSS'
14 // https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type%3Ddatetime-local)
15 // > should be a _valid local date and time string_ (not GMT)
16
17 // Note - date constructor passed local ISO-8601 does not correctly
18 // change time to UTC in node pre-8
19 const date = new Date(jsonDate);
20
21 const yyyy = pad(date.getFullYear(), 4);
22 const MM = pad(date.getMonth() + 1, 2);
23 const dd = pad(date.getDate(), 2);
24 const hh = pad(date.getHours(), 2);
25 const mm = pad(date.getMinutes(), 2);
26 const ss = pad(date.getSeconds(), 2);
27 const SSS = pad(date.getMilliseconds(), 3);
28
29 return `${yyyy}-${MM}-${dd}T${hh}:${mm}:${ss}.${SSS}`;
30}

Callers 3

utcToLocal.test.tsFile · 0.90
DateTimeWidgetFunction · 0.90

Calls 1

padFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…