( value: string, format: JSONDateTimeFormat )
| 9 | | Temporal.PlainTime; |
| 10 | |
| 11 | export 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 | } |
no outgoing calls
no test coverage detected