diff --git a/src/Webapi.res b/src/Webapi.res index c68d2ae5..b613f7bd 100644 --- a/src/Webapi.res +++ b/src/Webapi.res @@ -16,6 +16,7 @@ module ReadableStream = Webapi__ReadableStream module IntersectionObserver = Webapi__IntersectionObserver module ResizeObserver = Webapi__ResizeObserver module Url = Webapi__Url +module Temporal = Webapi__Temporal module WebSocket = Webapi__WebSocket type rafId diff --git a/src/Webapi/Temporal/Webapi__Temporal__Calendar.res b/src/Webapi/Temporal/Webapi__Temporal__Calendar.res new file mode 100644 index 00000000..42506a7e --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__Calendar.res @@ -0,0 +1 @@ +type t = Webapi__Temporal__Types.calendar diff --git a/src/Webapi/Temporal/Webapi__Temporal__Difference.res b/src/Webapi/Temporal/Webapi__Temporal__Difference.res new file mode 100644 index 00000000..d5b7e8fa --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__Difference.res @@ -0,0 +1,22 @@ +module DifferenceOptions = { + type t + + type durationUnit = [ + | #auto + | #hour + | #minute + | #second + | #millisecond + | #microsecond + | #nanosecond + ] + + @obj + external make: ( + ~largestUnit: durationUnit=?, + ~smallestUnit: durationUnit=?, + ~roundingIncrement: int=?, + ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit + ) => t = "" +} diff --git a/src/Webapi/Temporal/Webapi__Temporal__Duration.res b/src/Webapi/Temporal/Webapi__Temporal__Duration.res new file mode 100644 index 00000000..e31c4b28 --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__Duration.res @@ -0,0 +1,105 @@ +type t = Webapi__Temporal__Types.duration + +@new +external make: ( + ~years: int=?, + ~months: int=?, + ~weeks: int=?, + ~days: int=?, + ~hours: int=?, + ~minutes: int=?, + ~seconds: int=?, + ~milliseconds: int=?, + ~microseconds: int=?, + ~nanoseconds: int=?, + unit, +) => t = "Temporal.Duration" + +@scope("Temporal.Duration") @val external fromString: string => t = "from" +@scope("Temporal.Duration") @val external compare: (t, t) => int = "compare" +@scope("Temporal.Duration") @val +external compareRelativeToPlainDate: (t, {"relativeTo": Webapi__Temporal__Types.plainDate}) => int = + "compare" +@scope("Temporal.Duration") @val +external compareRelativeToZonedDateTime: ( + t, + {"relativeTo": Webapi__Temporal__Types.zonedDateTime}, +) => int = "compare" + +@get external years: t => int = "years" +@get external months: t => int = "months" +@get external days: t => int = "days" +@get external hours: t => int = "hours" +@get external minutes: t => int = "minutes" +@get external seconds: t => int = "seconds" +@get external milliseconds: t => int = "milliseconds" +@get external microseconds: t => int = "microseconds" +@get external nanoseconds: t => int = "nanoseconds" +@get external sign: t => int = "sign" +@get external blank: t => bool = "blank" +// TODO: Add `with` binding +@send external add: (t, t) => t = "add" +@send +external addRelativeToPlainDate: (t, t, {"relativeTo": Webapi__Temporal__Types.plainDate}) => t = + "add" +@send +external addRelativeToZonedDateTime: ( + t, + t, + {"relativeTo": Webapi__Temporal__Types.zonedDateTime}, +) => t = "add" +@send external subtract: (t, t) => t = "subtract" +@send +external subtractRelativeToPlainDate: ( + t, + t, + {"relativeTo": Webapi__Temporal__Types.plainDate}, +) => t = "subtract" +@send +external subtractRelativeToZonedDateTime: ( + t, + t, + {"relativeTo": Webapi__Temporal__Types.zonedDateTime}, +) => t = "subtract" +@send external negated: t => t = "negated" +@send external abs: t => t = "abs" + +type roundTo = [ + | #day + | #hour + | #minute + | #second + | #millisecond + | #microsecond + | #nanosecond +] + +@send external round: (t, ~to: roundTo) => t = "round" +// TODO: roundWithOptions. Tough because relativeTo can be either a PlainDate or ZonedDateTime +@send +external total: ( + t, + [#hour | #minute | #second | #millisecond | #microsecond | #nanosecond], +) => float = "total" +// TODO: totalWithOptions. Tough because relativeTo can be either a PlainDate or ZonedDateTime + +module ToStringOptions = { + type t + + @obj + external make: ( + ~fractionalSecondDigits: [#auto | #0 | #1 | #2 | #3 | #4 | #5 | #6 | #7 | #8 | #9]=?, + ~smallestUnit: [ + | #second + | #millisecond + | #microsecond + | #nanosecond + ]=?, + ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit + ) => t = "" +} + +@send external toString: t => string = "toString" +@send external toStringWithOptions: (t, ToStringOptions.t) => string = "toString" +// TODO: toLocaleString, need Intl bindings diff --git a/src/Webapi/Temporal/Webapi__Temporal__Instant.res b/src/Webapi/Temporal/Webapi__Temporal__Instant.res new file mode 100644 index 00000000..7bef70cf --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__Instant.res @@ -0,0 +1,92 @@ +type t = Webapi__Temporal__Types.instant + +// @new external make: BigInt.t => t = "Temporal.Instant" +@scope("Temporal.Instant") @val external fromString: string => t = "from" +@scope("Temporal.Instant") @val external fromInstant: t => t = "from" +@scope("Temporal.Instant") @val external fromEpochSeconds: float => t = "fromEpochSeconds" +@scope("Temporal.Instant") @val +external fromEpochMilliseconds: float => t = "fromEpochMilliseconds" +// @scope("Temporal.Instant") @val external fromEpochMicroseconds: BigInt.t => t = "fromEpochMicroseconds" +// @scope("Temporal.Instant") @val external fromEpochNanoseconds: BigInt.t => t = "fromEpochNanoseconds" +@scope("Temporal.Instant") @val external compare: (t, t) => int = "compare" +@scope("Temporal.Instant") @val external compareStrings: (string, string) => int = "compare" + +@get external epochSeconds: t => float = "epochSeconds" +@get external epochMilliseconds: t => float = "epochMilliseconds" +// @get external epochMicroseconds: t => BigInt.t = "epochMicroseconds" +// @get external epochNanoseconds: t => BigInt.t = "epochNanoseconds" +@send +external toZonedDateTimeISO: ( + t, + Webapi__Temporal__Types.timeZone, +) => Webapi__Temporal__ZonedDateTime.t = "toZonedDateTimeISO" +@send +external toZonedDateTime: ( + t, + {"timeZone": Webapi__Temporal__Types.timeZone, "calendar": Webapi__Temporal__Types.calendar}, +) => Webapi__Temporal__ZonedDateTime.t = "toZonedDateTime" +@send external add: (t, Webapi__Temporal__Types.duration) => t = "add" +@send external subtract: (t, Webapi__Temporal__Types.duration) => t = "subtract" + +@send external until: (t, t) => Webapi__Temporal__Types.duration = "until" +@send +external untilWithOptions: ( + t, + t, + Webapi__Temporal__Difference.DifferenceOptions.t, +) => Webapi__Temporal__Types.duration = "until" +@send external since: (t, t) => Webapi__Temporal__Types.duration = "since" +@send +external sinceWithOptions: ( + t, + t, + Webapi__Temporal__Difference.DifferenceOptions.t, +) => Webapi__Temporal__Types.duration = "since" + +type roundTo = [ + | #hour + | #minute + | #second + | #millisecond + | #microsecond + | #nanosecond +] + +module RoundOptions = { + type t + + @obj + external make: ( + ~smallestUnit: roundTo, + ~roundingIncrement: int=?, + ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit + ) => t = "" +} + +@send external round: (t, ~to: roundTo) => t = "round" +@send external roundWithOptions: (t, RoundOptions.t) => t = "round" +@send external equals: (t, t) => bool = "equals" + +module ToStringOptions = { + type t + + @obj + external make: ( + ~timeZone: Webapi__Temporal__Types.timeZone=?, + ~fractionalSecondDigits: [#auto | #0 | #1 | #2 | #3 | #4 | #5 | #6 | #7 | #8 | #9]=?, + ~smallestUnit: [ + | #minute + | #second + | #millisecond + | #microsecond + | #nanosecond + ]=?, + ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit + ) => t = "" +} + +@send external toString: t => string = "toString" +@send external toStringWithOptions: (t, ToStringOptions.t) => string = "toString" +// TODO: toLocaleString, need Intl bindings diff --git a/src/Webapi/Temporal/Webapi__Temporal__Now.res b/src/Webapi/Temporal/Webapi__Temporal__Now.res new file mode 100644 index 00000000..86252544 --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__Now.res @@ -0,0 +1,49 @@ +@scope("Temporal.Now") @val +external zonedDateTimeISO: unit => Webapi__Temporal__Types.zonedDateTime = "zonedDateTimeISO" +@scope("Temporal.Now") @val +external zonedDateTimeISOWithTimeZone: Webapi__Temporal__Types.timeZone => Webapi__Temporal__Types.zonedDateTime = + "zonedDateTimeISO" +@scope("Temporal.Now") @val +external zonedDateTime: Webapi__Temporal__Types.calendar => Webapi__Temporal__Types.zonedDateTime = + "zonedDateTime" +@scope("Temporal.Now") @val +external zonedDateTimeWithTimeZone: ( + Webapi__Temporal__Types.calendar, + Webapi__Temporal__Types.timeZone, +) => Webapi__Temporal__Types.zonedDateTime = "zonedDateTimeWithTimeZone" +@scope("Temporal.Now") @val external instant: unit => Webapi__Temporal__Types.instant = "instant" +@scope("Temporal.Now") @val external timeZone: unit => Webapi__Temporal__Types.timeZone = "timeZone" + +@scope("Temporal.Now") @val +external plainDateTimeISO: unit => Webapi__Temporal__Types.plainDateTime = "plainDateTimeISO" +@scope("Temporal.Now") @val +external plainDateTimeISOWithTimeZone: Webapi__Temporal__Types.timeZone => Webapi__Temporal__Types.plainDateTime = + "plainDateTimeISO" +@scope("Temporal.Now") @val +external plainDateTime: Webapi__Temporal__Types.calendar => Webapi__Temporal__Types.plainDateTime = + "plainDateTime" +@scope("Temporal.Now") @val +external plainDateTimeWithTimeZone: ( + Webapi__Temporal__Types.calendar, + Webapi__Temporal__Types.timeZone, +) => Webapi__Temporal__Types.plainDateTime = "plainDateTime" + +@scope("Temporal.Now") @val +external plainDateISO: unit => Webapi__Temporal__Types.plainDate = "plainDateISO" +@scope("Temporal.Now") @val +external plainDateISOWithTimeZone: Webapi__Temporal__Types.timeZone => Webapi__Temporal__Types.plainDate = + "plainDateISO" +@scope("Temporal.Now") @val +external plainDate: Webapi__Temporal__Types.calendar => Webapi__Temporal__Types.plainDate = + "plainDate" +@scope("Temporal.Now") @val +external plainDateWithTimeZone: ( + Webapi__Temporal__Types.calendar, + Webapi__Temporal__Types.timeZone, +) => Webapi__Temporal__Types.plainDate = "plainDate" + +@scope("Temporal.Now") @val +external plainTimeISO: unit => Webapi__Temporal__Types.plainTime = "plainTimeISO" +@scope("Temporal.Now") @val +external plainTimeISOWithTimeZone: Webapi__Temporal__Types.timeZone => Webapi__Temporal__Types.plainTime = + "plainTimeISO" diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res new file mode 100644 index 00000000..6ae9fad4 --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res @@ -0,0 +1,123 @@ +type t = Webapi__Temporal__Types.plainDate + +@new +external make: ( + ~isoYear: int, + ~isoMonth: int, + ~isoDay: int, + ~calendar: Webapi__Temporal__Types.calendar=?, + unit +) => t = "Temporal.PlainDate" + +module PlainDateInit = { + type t + + // TODO: Review type safety. Not all of these options are valid together when passed to fromInit + @obj + external make: ( + ~year: int=?, + ~month: int=?, + ~day: int=?, + ~era: string=?, + ~eraYear: int=?, + ~monthCode: string=?, + unit + ) => t = "" +} + +@scope("Temporal.PlainDate") @val external fromString: string => t = "from" +@scope("Temporal.PlainDate") @val +external fromStringWithOptions: (string, {"overflow": [#constrain | #reject]}) => t = "from" +@scope("Temporal.PlainDate") @val external fromInit: PlainDateInit.t => t = "from" +@scope("Temporal.PlainDate") @val +external fromInitWithOptions: (PlainDateInit.t, {"overflow": [#constrain | #reject]}) => t = "from" +@scope("Temporal.PlainDate") @val external compare: (t, t) => int = "compare" +@get external year: t => int = "year" +@get external month: t => int = "month" +@get external day: t => int = "day" +@get external monthCode: t => int = "monthCode" +@get external calendar: t => Webapi__Temporal__Types.calendar = "calendar" +@get external timeZone: t => Webapi__Temporal__Types.timeZone = "timeZone" +@get external era: t => option = "era" +@get external eraYear: t => option = "eraYear" +@get external dayOfWeek: t => int = "dayOfWeek" +@get external dayOfYear: t => int = "dayOfYear" +@get external weekOfYear: t => int = "weekOfYear" +@get external daysInWeek: t => int = "daysInWeek" +@get external daysInMonth: t => int = "daysInMonth" +@get external daysInYear: t => int = "daysInYear" +@get external monthsInYear: t => int = "monthsInYear" +@get external inLeapYear: t => bool = "inLeapYear" +// TODO: add `with` binding +@send external withCalendar: (t, Webapi__Temporal__Types.calendar) => t = "withCalendar" +@send external add: (t, Webapi__Temporal__Types.duration) => t = "add" +@send +external addWithOptions: ( + t, + Webapi__Temporal__Types.duration, + {"overflow": [#constrain | #reject]}, +) => t = "add" +@send external subtract: (t, Webapi__Temporal__Types.duration) => t = "subtract" +@send +external subtractWithOptions: ( + t, + Webapi__Temporal__Types.duration, + {"overflow": [#constrain | #reject]}, +) => t = "subtract" +@send external until: (t, t) => Webapi__Temporal__Types.duration = "until" +@send +external untilWithOptions: ( + t, + t, + // TODO: Need a different type as the valid units don't include time here + Webapi__Temporal__Difference.DifferenceOptions.t, +) => Webapi__Temporal__Types.duration = "until" +@send external since: (t, t) => Webapi__Temporal__Types.duration = "since" +@send +external sinceWithOptions: ( + t, + t, + Webapi__Temporal__Difference.DifferenceOptions.t, +) => Webapi__Temporal__Types.duration = "since" +@send external equals: (t, t) => bool = "equals" + +module ToStringOptions = { + type t + + @obj + external make: (~calendarName: [#auto | #always | #never]=?) => t = "" +} + +@send external toString: t => string = "toString" +@send external toStringWithOptions: (t, ToStringOptions.t) => string = "toString" +// TODO: toLocaleString, need Intl bindings + +module ToZonedDateTimeOptions = { + type t + @obj + external make: ( + ~plainTime: Webapi__Temporal__Types.plainTime=?, + ~timeZone: Webapi__Temporal__Types.timeZone, + unit + ) => t = "" +} + +@send +external toZonedDateTime: (t, ToZonedDateTimeOptions.t) => Webapi__Temporal__Types.zonedDateTime = + "toZonedDateTime" +@send external toPlainDateTime: t => Webapi__Temporal__Types.plainDateTime = "toPlainDateTime" +@send +external toPlainDateTimeWithPlainTime: ( + t, + Webapi__Temporal__Types.plainTime, +) => Webapi__Temporal__Types.plainDateTime = "toPlainDateTime" +@send external toPlainYearMonth: t => Webapi__Temporal__Types.plainYearMonth = "toPlainYearMonth" +@send external toPlainMonthDay: t => Webapi__Temporal__Types.plainMonthDay = "toPlainMonthDay" + +type isoFields = { + isoYear: int, + isoMonth: int, + isoDay: int, + calendar: Webapi__Temporal__Types.calendar, +} +@send external getISOFields: t => isoFields = "getISOFields" diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res new file mode 100644 index 00000000..4ce63740 --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res @@ -0,0 +1,129 @@ +type t = Webapi__Temporal__Types.plainTime + +@new +external make: ( + ~isoHour: int=?, + ~isoMinute: int=?, + ~isoSecond: int=?, + ~isoMillisecond: int=?, + ~isoMicrosecond: int=?, + ~isoNanosecond: int=?, + unit +) => t = "Temporal.PlainTime" + +module PlainTimeInit = { + type t + @obj + external make: ( + ~hour: int=?, + ~minute: int=?, + ~second: int=?, + ~millisecond: int=?, + ~microsecond: int=?, + ~nanosecond: int=?, + unit + ) => t = "" +} + +@scope("Temporal.PlainTime") @val external fromString: string => t = "from" +@scope("Temporal.PlainDate") @val +external fromStringWithOptions: (string, {"overflow": [#constrain | #reject]}) => t = "from" +@scope("Temporal.PlainTime") @val external fromInit: PlainTimeInit.t => t = "from" +@scope("Temporal.PlainTime") @val +external fromInitWithOptions: (PlainTimeInit.t, {"overflow": [#constrain | #reject]}) => t = "from" +@scope("Temporal.PlainTime") @val external compare: (t, t) => int = "compare" +@get external hour: t => int = "hour" +@get external minute: t => int = "minute" +@get external second: t => int = "second" +@get external millisecond: t => int = "millisecond" +@get external microsecond: t => int = "microsecond" +@get external nanosecond: t => int = "nanosecond" +@get external calendar: t => Webapi__Temporal__Types.calendar = "calendar" +// TODO: add `with` binding +@send external add: (t, Webapi__Temporal__Types.duration) => t = "add" +@send external subtract: (t, Webapi__Temporal__Types.duration) => t = "subtract" +@send external until: (t, t) => Webapi__Temporal__Types.duration = "until" +@send +external untilWithOptions: ( + t, + t, + // TODO: Need a different type as the valid units don't include time here + Webapi__Temporal__Difference.DifferenceOptions.t, +) => Webapi__Temporal__Types.duration = "until" +@send external since: (t, t) => Webapi__Temporal__Types.duration = "since" +@send +external sinceWithOptions: ( + t, + t, + Webapi__Temporal__Difference.DifferenceOptions.t, +) => Webapi__Temporal__Types.duration = "since" +@send external equals: (t, t) => bool = "equals" + +type roundTo = [ + | #hour + | #minute + | #second + | #millisecond + | #microsecond + | #nanosecond +] + +module RoundOptions = { + type t + + @obj + external make: ( + ~smallestUnit: roundTo, + ~roundingIncrement: int=?, + ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit + ) => t = "" +} + +@send external round: (t, ~to: roundTo) => t = "round" +@send external roundWithOptions: (t, RoundOptions.t) => t = "round" + +module ToStringOptions = { + type t + + @obj + external make: ( + ~timeZone: Webapi__Temporal__Types.timeZone=?, + ~fractionalSecondDigits: [#auto | #0 | #1 | #2 | #3 | #4 | #5 | #6 | #7 | #8 | #9]=?, + ~smallestUnit: [ + | #minute + | #second + | #millisecond + | #microsecond + | #nanosecond + ]=?, + ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit + ) => t = "" +} + +@send external toString: t => string = "toString" +@send external toStringWithOptions: (t, ToStringOptions.t) => string = "toString" +// TODO: toLocaleString, need Intl bindings +@send +external toZonedDateTime: ( + t, + {"timeZone": Webapi__Temporal__Types.timeZone, "plainDate": Webapi__Temporal__Types.plainDate}, +) => Webapi__Temporal__ZonedDateTime.t = "toZonedDateTime" +@send +external toPlainDateTime: ( + t, + Webapi__Temporal__Types.plainDate, +) => Webapi__Temporal__ZonedDateTime.t = "toPlainDateTime" + +type isoFields = { + isoHour: int, + isoMinute: int, + isoSecond: int, + isoMillisecond: int, + isoMicrosecond: int, + isoNanosecond: int, + calendar: Webapi__Temporal__Types.calendar, +} + +@send external getISOFields: t => isoFields = "getISOFields" diff --git a/src/Webapi/Temporal/Webapi__Temporal__TimeZone.res b/src/Webapi/Temporal/Webapi__Temporal__TimeZone.res new file mode 100644 index 00000000..4ef2cdf9 --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__TimeZone.res @@ -0,0 +1 @@ +type t = Webapi__Temporal__Types.timeZone diff --git a/src/Webapi/Temporal/Webapi__Temporal__Types.res b/src/Webapi/Temporal/Webapi__Temporal__Types.res new file mode 100644 index 00000000..9304d6ff --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__Types.res @@ -0,0 +1,10 @@ +type calendar +type duration +type instant +type plainDate +type plainDateTime +type plainTime +type plainYearMonth +type plainMonthDay +type timeZone +type zonedDateTime diff --git a/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res b/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res new file mode 100644 index 00000000..0c61821c --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res @@ -0,0 +1,155 @@ +type t = Webapi__Temporal__Types.zonedDateTime + +// @new external make: (~epochNanoseconds: BigInt.t, ~timeZone: TimeZone.t, unit) => t = "Temporal.ZonedDateTime" +// @new external makeWithCalendar: (~epochNanoseconds: BigInt.t, ~timeZone: TimeZone.t, ~calendar: Calendar.t, unit) => t = "Temporal.ZonedDateTime" + +module ZonedDateTimeInit = { + type t + + @obj + external make: ( + ~timeZone: Webapi__Temporal__Types.timeZone=?, + ~year: int=?, + ~month: int=?, + ~day: int=?, + ~minute: int=?, + ~second: int=?, + ~millisecond: int=?, + ~microsecond: int=?, + ~nanosecond: int=?, + unit + ) => t = "" +} + +module FromOptions = { + type t + + @obj + external make: ( + ~overflow: [#constrain | #reject]=?, + ~disambiguation: [#compatible | #earlier | #later | #reject]=?, + ~offset: [#use | #ignore | #prefer | #reject]=?, + unit + ) => t = "" +} + +@scope("Temporal.ZonedDateTime") @val external fromString: string => t = "from" +@scope("Temporal.ZonedDateTime") @val +external fromStringWithOptions: (string, FromOptions.t) => t = "from" +@scope("Temporal.ZonedDateTime") @val external fromInit: ZonedDateTimeInit.t => t = "from" +@scope("Temporal.ZonedDateTime") @val +external fromInitWithOptions: (ZonedDateTimeInit.t, FromOptions.t) => t = "from" +@send external compare: (t, t) => int = "compare" +@get external year: t => int = "year" +@get external month: t => int = "month" +@get external day: t => int = "day" +@get external hour: t => int = "hour" +@get external minute: t => int = "minute" +@get external second: t => int = "second" +@get external millisecond: t => int = "millisecond" +@get external microsecond: t => int = "microsecond" +@get external nanosecond: t => int = "nanosecond" +@get external monthCode: t => int = "monthCode" +@get external epochSeconds: t => float = "epochSeconds" +@get external epochMilliseconds: t => float = "epochMilliseconds" +// @get external epochMicroseconds: t => BigInt.t = "epochMicroseconds" +// @get external epochNanoseconds: t => BigInt.t = "epochNanoseconds" +@get external calendar: t => Webapi__Temporal__Types.calendar = "calendar" +@get external timeZone: t => Webapi__Temporal__Types.timeZone = "timeZone" +@get external era: t => option = "era" +@get external eraYear: t => option = "eraYear" +@get external dayOfWeek: t => int = "dayOfWeek" +@get external dayOfYear: t => int = "dayOfYear" +@get external weekOfYear: t => int = "weekOfYear" +@get external daysInWeek: t => int = "daysInWeek" +@get external daysInMonth: t => int = "daysInMonth" +@get external daysInYear: t => int = "daysInYear" +@get external monthsInYear: t => int = "monthsInYear" +@get external inLeapYear: t => bool = "inLeapYear" +@get external hoursInDay: t => int = "hoursInDay" +@get external startOfDay: t => t = "startOfDay" +@get external offsetNanoseconds: t => float = "offsetNanoseconds" +@get external offset: t => string = "offset" +// TODO: Add `with` binding +@send external withPlainTime: (t, Webapi__Temporal__Types.plainTime) => t = "withPlainTime" +@send external withPlainDate: (t, Webapi__Temporal__Types.plainDate) => t = "withPlainDate" +@send external withTimeZone: (t, Webapi__Temporal__Types.timeZone) => t = "withTimeZone" +@send external withCalendar: (t, Webapi__Temporal__Types.calendar) => t = "withCalendar" +@send external add: (t, Webapi__Temporal__Types.duration) => t = "add" +@send +external addWithOptions: ( + t, + Webapi__Temporal__Types.duration, + {"overflow": [#constrain | #reject]}, +) => t = "add" +@send external subtract: (t, Webapi__Temporal__Types.duration) => t = "subtract" +@send +external subtractWithOptions: ( + t, + Webapi__Temporal__Types.duration, + {"overflow": [#constrain | #reject]}, +) => t = "subtract" + +@send external until: (t, t) => Webapi__Temporal__Types.duration = "until" +@send +external untilWithOptions: ( + t, + t, + Webapi__Temporal__Difference.DifferenceOptions.t, +) => Webapi__Temporal__Types.duration = "until" +@send external since: (t, t) => Webapi__Temporal__Types.duration = "since" +@send +external sinceWithOptions: ( + t, + t, + Webapi__Temporal__Difference.DifferenceOptions.t, +) => Webapi__Temporal__Types.duration = "since" +@send external equals: (t, t) => bool = "equals" + +module ToStringOptions = { + type t + + @obj + external make: ( + ~offset: [#auto | #never]=?, + ~timeZoneName: [#auto | #never]=?, + ~calendarName: [#auto | #always | #never]=?, + ~fractionalSecondDigits: [#auto | #0 | #1 | #2 | #3 | #4 | #5 | #6 | #7 | #8 | #9]=?, + ~smallestUnit: [ + | #minute + | #second + | #millisecond + | #microsecond + | #nanosecond + ]=?, + ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit + ) => t = "" +} + +@send external toString: t => string = "toString" +@send external toStringWithOptions: (t, ToStringOptions.t) => string = "toString" +// TODO: toLocaleString, need Intl bindings +@send external toInstant: t => Webapi__Temporal__Types.instant = "toInstant" +@send external toPlainDate: t => Webapi__Temporal__Types.plainDate = "toPlainDate" +@send external toPlainTime: t => Webapi__Temporal__Types.plainTime = "toPlainTime" +@send external toPlainDateTime: t => Webapi__Temporal__Types.plainDateTime = "toPlainDateTime" +@send external toPlainYearMonth: t => Webapi__Temporal__Types.plainYearMonth = "toPlainYearMonth" +@send external toPlainMonthDay: t => Webapi__Temporal__Types.plainMonthDay = "toPlainMonthDay" + +type isoFields = { + isoYear: int, + isoMonth: int, + isoDay: int, + hour: int, + minute: int, + second: int, + millisecond: int, + microsecond: int, + nanosecond: int, + offset: string, + timeZone: Webapi__Temporal__Types.timeZone, + calendar: Webapi__Temporal__Types.calendar, +} + +@send external getISOFields: t => isoFields = "getISOFields" diff --git a/src/Webapi/Webapi__Temporal.res b/src/Webapi/Webapi__Temporal.res new file mode 100644 index 00000000..f63a8975 --- /dev/null +++ b/src/Webapi/Webapi__Temporal.res @@ -0,0 +1,8 @@ +module Calendar = Webapi__Temporal__Calendar +module Duration = Webapi__Temporal__Duration +module Instant = Webapi__Temporal__Instant +module Now = Webapi__Temporal__Now +module PlainDate = Webapi__Temporal__PlainDate +module PlainTime = Webapi__Temporal__PlainTime +module TimeZone = Webapi__Temporal__TimeZone +module ZonedDateTime = Webapi__Temporal__ZonedDateTime