-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Temporal bindings #76
base: main
Are you sure you want to change the base?
Changes from 7 commits
666e0f6
1349d11
015fb3e
0a605a6
ec33d4e
b95c333
1e2c573
2e67cd7
96371e2
74d3dd1
0d260c7
37df1c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
type t | ||
@obj external make: (~overflow: [#constrain | #reject]=?) => t = "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type t = Webapi__Temporal__Types.calendar |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type t = Webapi__Temporal__Types.duration |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
{"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]=?, | ||
) => 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
type t = Webapi__Temporal__Types.plainDate | ||
|
||
@new | ||
external make: ( | ||
~isoYear: int, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if these (as well as the params for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
~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=?, | ||
~month: int=?, | ||
~day: int=?, | ||
~era: string=?, | ||
~eraYear: int=?, | ||
~monthCode: string=?, | ||
) => 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<string> = "era" | ||
@get external eraYear: t => option<float> = "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" | ||
@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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
type t = Webapi__Temporal__Types.plainTime | ||
|
||
@new | ||
external make: ( | ||
~isoHour: int=?, | ||
~isoMinute: int=?, | ||
~isoSecond: int=?, | ||
~isoMillisecond: int=?, | ||
~isoMicrosecond: int=?, | ||
~isoNanosecond: int=?, | ||
) => 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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type t = Webapi__Temporal__Types.timeZone |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type calendar | ||
type duration | ||
type instant | ||
type plainDate | ||
type plainDateTime | ||
type plainTime | ||
type plainYearMonth | ||
type plainMonthDay | ||
type timeZone | ||
type zonedDateTime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This submodule doesn't seem to add anything? I think it would work just as well without the submodule wrapper.