Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

temporal.ts

25 lines679 Bytes

1const temporalTypes = new Set([
2 `Temporal.Duration`,
3 `Temporal.Instant`,
4 `Temporal.PlainDate`,
5 `Temporal.PlainDateTime`,
6 `Temporal.PlainMonthDay`,
7 `Temporal.PlainTime`,
8 `Temporal.PlainYearMonth`,
9 `Temporal.ZonedDateTime`,
10])
11​
12export interface TemporalLike {
13 [Symbol.toStringTag]: string
14 toString: () => string
16​
17export function isTemporal(input: object): input is TemporalLike {
18 const tag = (input as Record<symbol, unknown>)[Symbol.toStringTag]
19 // An own tag on a plain object does not make it a Temporal value.
20 return (
21 typeof tag === `string` &&
22 temporalTypes.has(tag) &&
23 Object.getPrototypeOf(input)?.[Symbol.toStringTag] === tag
24 )