MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / inferTemporal

Function inferTemporal

app/utilities/inferredTemporal.ts:11–52  ·  view source on GitHub ↗
(
  value: string,
  format: JSONDateTimeFormat
)

Source from the content-addressed store, hash-verified

9 | Temporal.PlainTime;
10
11export function inferTemporal(
12 value: string,
13 format: JSONDateTimeFormat
14): InferredTemporal | undefined {
15 if (format.variant === "rfc2822") {
16 return;
17 }
18
19 try {
20 switch (format.parts) {
21 case "datetime": {
22 if (format.extensions && format.extensions.includes("timezone")) {
23 return Temporal.ZonedDateTime.from(value);
24 }
25
26 try {
27 return Temporal.Instant.from(value);
28 } catch {
29 return Temporal.PlainDateTime.from(value);
30 }
31 }
32 case "date": {
33 try {
34 return Temporal.Instant.from(value);
35 } catch {
36 return Temporal.PlainDate.from(value);
37 }
38 }
39 case "time": {
40 try {
41 return Temporal.Instant.from(value);
42 } catch {
43 return Temporal.PlainTime.from(value);
44 }
45 }
46 }
47 } catch (e) {
48 console.error(e);
49
50 return;
51 }
52}

Callers 3

PropertiesDateTimeFunction · 0.90
PreviewDateFunction · 0.90
formatDateTimeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected