From 666e0f6723f0511f7418bd5e123f7742b33a5a4b Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 10:49:20 +0000 Subject: [PATCH 01/12] WIP --- .../Webapi__Temporal__ArithmaticOptions.res | 2 + .../Temporal/Webapi__Temporal__Calendar.res | 1 + .../Temporal/Webapi__Temporal__Difference.res | 21 +++ .../Temporal/Webapi__Temporal__Duration.res | 1 + .../Temporal/Webapi__Temporal__Instant.res | 90 +++++++++++ src/Webapi/Temporal/Webapi__Temporal__Now.res | 49 ++++++ .../Temporal/Webapi__Temporal__PlainDate.res | 62 ++++++++ .../Temporal/Webapi__Temporal__PlainTime.res | 1 + .../Temporal/Webapi__Temporal__TimeZone.res | 1 + .../Temporal/Webapi__Temporal__Types.res | 10 ++ .../Webapi__Temporal__ZonedDateTime.res | 145 ++++++++++++++++++ 11 files changed, 383 insertions(+) create mode 100644 src/Webapi/Temporal/Webapi__Temporal__ArithmaticOptions.res create mode 100644 src/Webapi/Temporal/Webapi__Temporal__Calendar.res create mode 100644 src/Webapi/Temporal/Webapi__Temporal__Difference.res create mode 100644 src/Webapi/Temporal/Webapi__Temporal__Duration.res create mode 100644 src/Webapi/Temporal/Webapi__Temporal__Instant.res create mode 100644 src/Webapi/Temporal/Webapi__Temporal__Now.res create mode 100644 src/Webapi/Temporal/Webapi__Temporal__PlainDate.res create mode 100644 src/Webapi/Temporal/Webapi__Temporal__PlainTime.res create mode 100644 src/Webapi/Temporal/Webapi__Temporal__TimeZone.res create mode 100644 src/Webapi/Temporal/Webapi__Temporal__Types.res create mode 100644 src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res diff --git a/src/Webapi/Temporal/Webapi__Temporal__ArithmaticOptions.res b/src/Webapi/Temporal/Webapi__Temporal__ArithmaticOptions.res new file mode 100644 index 00000000..01de19f0 --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__ArithmaticOptions.res @@ -0,0 +1,2 @@ +type t +@obj external make: (~overflow: [#constrain | #reject]=?) => t = "" diff --git a/src/Webapi/Temporal/Webapi__Temporal__Calendar.res b/src/Webapi/Temporal/Webapi__Temporal__Calendar.res new file mode 100644 index 00000000..80dc489c --- /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..62a36628 --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__Difference.res @@ -0,0 +1,21 @@ +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]=?, + ) => 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..dadf1ad0 --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__Duration.res @@ -0,0 +1 @@ +type t= Webapi__Temporal__Types.duration diff --git a/src/Webapi/Temporal/Webapi__Temporal__Instant.res b/src/Webapi/Temporal/Webapi__Temporal__Instant.res new file mode 100644 index 00000000..e82f631e --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__Instant.res @@ -0,0 +1,90 @@ +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, + {"timneZone": 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]=?, + ) => 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]=?, + ) => 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..aa531870 --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res @@ -0,0 +1,62 @@ +type t = Webapi__Temporal__Types.plainDate + +@new +external make: ( + ~isoYear: int, + ~isoMonth: int, + ~isoDay: int, + ~calendar: Webapi__Temporal__Types.calendar, +) => 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=?, + ~era: string=?, + ~eraYear: int=?, + ~month: int=?, + ~monthCode: string=?, + ) => t = "" +} + +module FromOptions = { + type t + + @obj external make: (~overflow: [#constrain | #reject]=?) => t = "" +} + +@scope("Temporal.PlainDate") @val external fromString: string => t = "from" +@scope("Temporal.PlainDate") @val +external fromStringWithOptions: (string, FromOptions.t) => t = "from" +@scope("Temporal.PlainDate") @val external fromInit: PlainDateInit.t => t = "from" +@scope("Temporal.PlainDate") @val +external fromInitWithOptions: (PlainDateInit.t, FromOptions.t) => 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, Webapi__Temporal__ArithmaticOptions.t) => t = "add" +@send external subtract: (t, Webapi__Temporal__Types.duration) => t = "subtract" +@send +external subtractWithOptions: (t, Webapi__Temporal__Types.duration, Webapi__Temporal__ArithmaticOptions.t) => t = + "subtract" diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res new file mode 100644 index 00000000..d4275bca --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res @@ -0,0 +1 @@ +type t = Webapi__Temporal__Types.plainTime 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..436e91c4 --- /dev/null +++ b/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res @@ -0,0 +1,145 @@ +type t = Webapi__Temporal__Types.zonedDateTime + +// @new external make: (~epochNanoseconds: BigInt.t, ~timeZone: TimeZone.t) => t = "Temporal.ZonedDateTime" +// @new external makeWithCalendar: (~epochNanoseconds: BigInt.t, ~timeZone: TimeZone.t, ~calendar: Calendar.t) => 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=?, + ) => t = "" +} + +module FromOptions = { + type t + + @obj + external make: ( + ~overflow: [#constrain | #reject]=?, + ~disambiguation: [#compatible | #earlier | #later | #reject]=?, + ~offset: [#use | #ignore | #prefer | #reject]=?, + ) => 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, Webapi__Temporal__ArithmaticOptions.t) => t = "add" +@send external subtract: (t, Webapi__Temporal__Types.duration) => t = "subtract" +@send +external subtractWithOptions: (t, Webapi__Temporal__Types.duration, Webapi__Temporal__ArithmaticOptions.t) => 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]=?, + ) => 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" From 1349d118cfca1b646fd51245470fa66c6408fd11 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 11:10:56 +0000 Subject: [PATCH 02/12] Expose in top level module --- src/Webapi.res | 1 + src/Webapi/Webapi__Temporal.res | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 src/Webapi/Webapi__Temporal.res 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/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 From 015fb3ee56d8f2dc64a47303de7682a0002e5078 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 11:11:50 +0000 Subject: [PATCH 03/12] Formatting --- src/Webapi/Temporal/Webapi__Temporal__Calendar.res | 2 +- src/Webapi/Temporal/Webapi__Temporal__Duration.res | 2 +- src/Webapi/Temporal/Webapi__Temporal__PlainDate.res | 13 ++++++++++--- .../Temporal/Webapi__Temporal__ZonedDateTime.res | 13 ++++++++++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Webapi/Temporal/Webapi__Temporal__Calendar.res b/src/Webapi/Temporal/Webapi__Temporal__Calendar.res index 80dc489c..42506a7e 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__Calendar.res +++ b/src/Webapi/Temporal/Webapi__Temporal__Calendar.res @@ -1 +1 @@ -type t= Webapi__Temporal__Types.calendar +type t = Webapi__Temporal__Types.calendar diff --git a/src/Webapi/Temporal/Webapi__Temporal__Duration.res b/src/Webapi/Temporal/Webapi__Temporal__Duration.res index dadf1ad0..cb44c04c 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__Duration.res +++ b/src/Webapi/Temporal/Webapi__Temporal__Duration.res @@ -1 +1 @@ -type t= Webapi__Temporal__Types.duration +type t = Webapi__Temporal__Types.duration diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res index aa531870..efb023fc 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res @@ -55,8 +55,15 @@ external fromInitWithOptions: (PlainDateInit.t, FromOptions.t) => t = "from" @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, Webapi__Temporal__ArithmaticOptions.t) => t = "add" +external addWithOptions: ( + t, + Webapi__Temporal__Types.duration, + Webapi__Temporal__ArithmaticOptions.t, +) => t = "add" @send external subtract: (t, Webapi__Temporal__Types.duration) => t = "subtract" @send -external subtractWithOptions: (t, Webapi__Temporal__Types.duration, Webapi__Temporal__ArithmaticOptions.t) => t = - "subtract" +external subtractWithOptions: ( + t, + Webapi__Temporal__Types.duration, + Webapi__Temporal__ArithmaticOptions.t, +) => t = "subtract" diff --git a/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res b/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res index 436e91c4..5f949089 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res +++ b/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res @@ -75,11 +75,18 @@ external fromInitWithOptions: (ZonedDateTimeInit.t, FromOptions.t) => t = "from" @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, Webapi__Temporal__ArithmaticOptions.t) => t = "add" +external addWithOptions: ( + t, + Webapi__Temporal__Types.duration, + Webapi__Temporal__ArithmaticOptions.t, +) => t = "add" @send external subtract: (t, Webapi__Temporal__Types.duration) => t = "subtract" @send -external subtractWithOptions: (t, Webapi__Temporal__Types.duration, Webapi__Temporal__ArithmaticOptions.t) => t = - "subtract" +external subtractWithOptions: ( + t, + Webapi__Temporal__Types.duration, + Webapi__Temporal__ArithmaticOptions.t, +) => t = "subtract" @send external until: (t, t) => Webapi__Temporal__Types.duration = "until" @send From 0a605a6aa21723ccbeff13da9842672a075fbf35 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 15:46:11 +0000 Subject: [PATCH 04/12] WIP --- .../Temporal/Webapi__Temporal__Instant.res | 2 +- .../Temporal/Webapi__Temporal__PlainDate.res | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/Webapi/Temporal/Webapi__Temporal__Instant.res b/src/Webapi/Temporal/Webapi__Temporal__Instant.res index e82f631e..67fdabd7 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__Instant.res +++ b/src/Webapi/Temporal/Webapi__Temporal__Instant.res @@ -23,7 +23,7 @@ external toZonedDateTimeISO: ( @send external toZonedDateTime: ( t, - {"timneZone": Webapi__Temporal__Types.timeZone, "calendar": Webapi__Temporal__Types.calendar}, + {"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" diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res index efb023fc..e83132b1 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res @@ -67,3 +67,53 @@ external subtractWithOptions: ( Webapi__Temporal__Types.duration, Webapi__Temporal__ArithmaticOptions.t, ) => 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, + ) => 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" From ec33d4e14d97eeb589669e7e2737e76233ae97b3 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 15:47:08 +0000 Subject: [PATCH 05/12] WIP --- src/Webapi/Temporal/Webapi__Temporal__PlainDate.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res index e83132b1..688bed44 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res @@ -5,7 +5,7 @@ external make: ( ~isoYear: int, ~isoMonth: int, ~isoDay: int, - ~calendar: Webapi__Temporal__Types.calendar, + ~calendar: Webapi__Temporal__Types.calendar=?, ) => t = "Temporal.PlainDate" module PlainDateInit = { From b95c33348078562fad3bab11c3adc4ca5ca28205 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 15:48:03 +0000 Subject: [PATCH 06/12] WIP --- src/Webapi/Temporal/Webapi__Temporal__PlainTime.res | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res index d4275bca..cdd33d0e 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res @@ -1 +1,11 @@ type t = Webapi__Temporal__Types.plainTime + +@new +external make: ( + ~isoHour: int=?, + ~isoMinute: int=?, + ~isoSecond: int=?, + ~isoMillisecond: int=?, + ~isoMicrosecond: int=?, + ~isoNanosecond: int=?, +) => t = "Temporal.PlainDate" From 1e2c573b5d3fc4993102189cf0ca79c1f0c729eb Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 15:58:12 +0000 Subject: [PATCH 07/12] WIP --- .../Temporal/Webapi__Temporal__PlainDate.res | 23 ++++++++++--------- .../Temporal/Webapi__Temporal__PlainTime.res | 18 ++++++++++++++- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res index 688bed44..614aadcb 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res @@ -15,25 +15,20 @@ module PlainDateInit = { @obj external make: ( ~year: int=?, + ~month: int=?, + ~day: int=?, ~era: string=?, ~eraYear: int=?, - ~month: int=?, ~monthCode: string=?, ) => t = "" } -module FromOptions = { - type t - - @obj external make: (~overflow: [#constrain | #reject]=?) => t = "" -} - @scope("Temporal.PlainDate") @val external fromString: string => t = "from" @scope("Temporal.PlainDate") @val -external fromStringWithOptions: (string, FromOptions.t) => t = "from" +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, FromOptions.t) => t = "from" +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" @@ -104,9 +99,15 @@ module ToZonedDateTimeOptions = { ) => t = "" } -@send external toZonedDateTime: (t, ToZonedDateTimeOptions.t) => Webapi__Temporal__Types.zonedDateTime = "toZonedDateTime" +@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 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" diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res index cdd33d0e..40e6d64a 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res @@ -8,4 +8,20 @@ external make: ( ~isoMillisecond: int=?, ~isoMicrosecond: int=?, ~isoNanosecond: int=?, -) => t = "Temporal.PlainDate" +) => t = "Temporal.PlainTime" + +module PlainTimeInit = { + type t + @obj + external make: ( + ~hour: int=?, + ~minute: int=?, + ~second: int=?, + ~millisecond: int=?, + ~microsecond: int=?, + ~nanosecond: int=?, + ~calendar: Webapi__Temporal__Types.calendar=?, + ) => t = "" +} + +@scope("Temporal.PlainTime") @val external fromString: string => t = "from" From 2e67cd764135d4233c546df69f750c55b044110d Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 16:05:20 +0000 Subject: [PATCH 08/12] WIP --- src/Webapi/Temporal/Webapi__Temporal__PlainTime.res | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res index 40e6d64a..7d5bfa87 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res @@ -25,3 +25,16 @@ module PlainTimeInit = { } @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" From 96371e21d10bf39184fb2ec630673e8e2aafc90c Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 16:37:50 +0000 Subject: [PATCH 09/12] WIP --- src/Webapi/Temporal/Webapi__Temporal__ArithmaticOptions.res | 2 -- src/Webapi/Temporal/Webapi__Temporal__PlainDate.res | 4 ++-- src/Webapi/Temporal/Webapi__Temporal__PlainTime.res | 4 +++- src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 src/Webapi/Temporal/Webapi__Temporal__ArithmaticOptions.res diff --git a/src/Webapi/Temporal/Webapi__Temporal__ArithmaticOptions.res b/src/Webapi/Temporal/Webapi__Temporal__ArithmaticOptions.res deleted file mode 100644 index 01de19f0..00000000 --- a/src/Webapi/Temporal/Webapi__Temporal__ArithmaticOptions.res +++ /dev/null @@ -1,2 +0,0 @@ -type t -@obj external make: (~overflow: [#constrain | #reject]=?) => t = "" diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res index 614aadcb..3d92438c 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res @@ -53,14 +53,14 @@ external fromInitWithOptions: (PlainDateInit.t, {"overflow": [#constrain | #reje external addWithOptions: ( t, Webapi__Temporal__Types.duration, - Webapi__Temporal__ArithmaticOptions.t, + {"overflow": [#constrain | #reject]}, ) => t = "add" @send external subtract: (t, Webapi__Temporal__Types.duration) => t = "subtract" @send external subtractWithOptions: ( t, Webapi__Temporal__Types.duration, - Webapi__Temporal__ArithmaticOptions.t, + {"overflow": [#constrain | #reject]}, ) => t = "subtract" @send external until: (t, t) => Webapi__Temporal__Types.duration = "until" @send diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res index 7d5bfa87..505ad5dd 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res @@ -20,7 +20,6 @@ module PlainTimeInit = { ~millisecond: int=?, ~microsecond: int=?, ~nanosecond: int=?, - ~calendar: Webapi__Temporal__Types.calendar=?, ) => t = "" } @@ -38,3 +37,6 @@ external fromInitWithOptions: (PlainTimeInit.t, {"overflow": [#constrain | #reje @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" diff --git a/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res b/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res index 5f949089..17a2168d 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res +++ b/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res @@ -78,14 +78,14 @@ external fromInitWithOptions: (ZonedDateTimeInit.t, FromOptions.t) => t = "from" external addWithOptions: ( t, Webapi__Temporal__Types.duration, - Webapi__Temporal__ArithmaticOptions.t, + {"overflow": [#constrain | #reject]}, ) => t = "add" @send external subtract: (t, Webapi__Temporal__Types.duration) => t = "subtract" @send external subtractWithOptions: ( t, Webapi__Temporal__Types.duration, - Webapi__Temporal__ArithmaticOptions.t, + {"overflow": [#constrain | #reject]}, ) => t = "subtract" @send external until: (t, t) => Webapi__Temporal__Types.duration = "until" From 74d3dd1d39279c3cdeb61a0274cdc9f22a5224d6 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 16:44:06 +0000 Subject: [PATCH 10/12] WIP --- .../Temporal/Webapi__Temporal__PlainTime.res | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res index 505ad5dd..1e3edfca 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res @@ -40,3 +40,86 @@ external fromInitWithOptions: (PlainTimeInit.t, {"overflow": [#constrain | #reje // 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]=?, + ) => 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]=?, + ) => 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" From 0d260c7a637519e67f2c7a8ba8e3cfdb2dea506a Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 16:50:58 +0000 Subject: [PATCH 11/12] WIP --- .../Temporal/Webapi__Temporal__Difference.res | 1 + .../Temporal/Webapi__Temporal__Duration.res | 15 +++++++++++++++ src/Webapi/Temporal/Webapi__Temporal__Instant.res | 2 ++ .../Temporal/Webapi__Temporal__PlainDate.res | 3 +++ .../Temporal/Webapi__Temporal__PlainTime.res | 4 ++++ .../Temporal/Webapi__Temporal__ZonedDateTime.res | 7 +++++-- 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Webapi/Temporal/Webapi__Temporal__Difference.res b/src/Webapi/Temporal/Webapi__Temporal__Difference.res index 62a36628..d5b7e8fa 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__Difference.res +++ b/src/Webapi/Temporal/Webapi__Temporal__Difference.res @@ -17,5 +17,6 @@ module DifferenceOptions = { ~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 index cb44c04c..87189a0e 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__Duration.res +++ b/src/Webapi/Temporal/Webapi__Temporal__Duration.res @@ -1 +1,16 @@ 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" diff --git a/src/Webapi/Temporal/Webapi__Temporal__Instant.res b/src/Webapi/Temporal/Webapi__Temporal__Instant.res index 67fdabd7..7bef70cf 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__Instant.res +++ b/src/Webapi/Temporal/Webapi__Temporal__Instant.res @@ -60,6 +60,7 @@ module RoundOptions = { ~smallestUnit: roundTo, ~roundingIncrement: int=?, ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit ) => t = "" } @@ -82,6 +83,7 @@ module ToStringOptions = { | #nanosecond ]=?, ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit ) => t = "" } diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res index 3d92438c..6ae9fad4 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainDate.res @@ -6,6 +6,7 @@ external make: ( ~isoMonth: int, ~isoDay: int, ~calendar: Webapi__Temporal__Types.calendar=?, + unit ) => t = "Temporal.PlainDate" module PlainDateInit = { @@ -20,6 +21,7 @@ module PlainDateInit = { ~era: string=?, ~eraYear: int=?, ~monthCode: string=?, + unit ) => t = "" } @@ -96,6 +98,7 @@ module ToZonedDateTimeOptions = { external make: ( ~plainTime: Webapi__Temporal__Types.plainTime=?, ~timeZone: Webapi__Temporal__Types.timeZone, + unit ) => t = "" } diff --git a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res index 1e3edfca..4ce63740 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res +++ b/src/Webapi/Temporal/Webapi__Temporal__PlainTime.res @@ -8,6 +8,7 @@ external make: ( ~isoMillisecond: int=?, ~isoMicrosecond: int=?, ~isoNanosecond: int=?, + unit ) => t = "Temporal.PlainTime" module PlainTimeInit = { @@ -20,6 +21,7 @@ module PlainTimeInit = { ~millisecond: int=?, ~microsecond: int=?, ~nanosecond: int=?, + unit ) => t = "" } @@ -74,6 +76,7 @@ module RoundOptions = { ~smallestUnit: roundTo, ~roundingIncrement: int=?, ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit ) => t = "" } @@ -95,6 +98,7 @@ module ToStringOptions = { | #nanosecond ]=?, ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit ) => t = "" } diff --git a/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res b/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res index 17a2168d..0c61821c 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res +++ b/src/Webapi/Temporal/Webapi__Temporal__ZonedDateTime.res @@ -1,7 +1,7 @@ type t = Webapi__Temporal__Types.zonedDateTime -// @new external make: (~epochNanoseconds: BigInt.t, ~timeZone: TimeZone.t) => t = "Temporal.ZonedDateTime" -// @new external makeWithCalendar: (~epochNanoseconds: BigInt.t, ~timeZone: TimeZone.t, ~calendar: Calendar.t) => t = "Temporal.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 @@ -17,6 +17,7 @@ module ZonedDateTimeInit = { ~millisecond: int=?, ~microsecond: int=?, ~nanosecond: int=?, + unit ) => t = "" } @@ -28,6 +29,7 @@ module FromOptions = { ~overflow: [#constrain | #reject]=?, ~disambiguation: [#compatible | #earlier | #later | #reject]=?, ~offset: [#use | #ignore | #prefer | #reject]=?, + unit ) => t = "" } @@ -121,6 +123,7 @@ module ToStringOptions = { | #nanosecond ]=?, ~roundingMode: [#halfExpand | #ceil | #trunc | #floor]=?, + unit ) => t = "" } From 37df1c15fd089c0b4135ae63824d4ee4157b0734 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Thu, 30 Dec 2021 17:09:51 +0000 Subject: [PATCH 12/12] WIP --- .../Temporal/Webapi__Temporal__Duration.res | 91 ++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/src/Webapi/Temporal/Webapi__Temporal__Duration.res b/src/Webapi/Temporal/Webapi__Temporal__Duration.res index 87189a0e..e31c4b28 100644 --- a/src/Webapi/Temporal/Webapi__Temporal__Duration.res +++ b/src/Webapi/Temporal/Webapi__Temporal__Duration.res @@ -12,5 +12,94 @@ external make: ( ~milliseconds: int=?, ~microseconds: int=?, ~nanoseconds: int=?, - unit + 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