Skip to content

Commit 089cab1

Browse files
feat: Intl.RelativeTimeFormat
1 parent fd52be4 commit 089cab1

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed
Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
type t
22

3+
type numeric = [#always | #auto]
4+
type style = [#long | #short | #narrow]
5+
type timeUnit = [#year | #quarter | #month | #week | #day | #hour | #minute | #second]
6+
7+
type options = {
8+
localeMatcher?: Core__Intl__Common.localeMatcher,
9+
numeric?: numeric,
10+
style?: style,
11+
}
12+
13+
type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher}
14+
15+
type resolvedOptions = {
16+
locale: string,
17+
numeric: numeric,
18+
style: style,
19+
numberingSystem: string,
20+
}
21+
22+
type relativeTimePartComponent = [#literal | #integer]
23+
type relativeTimePart = {
24+
\"type": relativeTimePartComponent,
25+
value: string,
26+
unit?: timeUnit,
27+
}
28+
329
@new external make: unit => t = "Intl.RelativeTimeFormat"
430
@new external makeWithLocale: string => t = "Intl.RelativeTimeFormat"
531
@new external makeWithLocales: array<string> => t = "Intl.RelativeTimeFormat"
6-
@new external makeWithLocaleAndOptions: (string, {..}) => t = "Intl.RelativeTimeFormat"
7-
@new external makeWithLocalesAndOptions: (array<string>, {..}) => t = "Intl.RelativeTimeFormat"
8-
@new external makeWithOptions: (@as(json`undefined`) _, {..}) => t = "Intl.RelativeTimeFormat"
32+
@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.RelativeTimeFormat"
33+
@new external makeWithLocalesAndOptions: (array<string>, options) => t = "Intl.RelativeTimeFormat"
34+
@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.RelativeTimeFormat"
935

1036
@val
1137
external supportedLocalesOf: array<string> => t = "Intl.RelativeTimeFormat.supportedLocalesOf"
1238
@val
13-
external supportedLocalesOfWithOptions: (array<string>, {..}) => t =
39+
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
1440
"Intl.RelativeTimeFormat.supportedLocalesOf"
1541

16-
@send external resolvedOptions: t => {..} = "resolvedOptions"
17-
18-
type timeUnit = [#year | #quarter | #month | #week | #day | #hour | #minute | #second]
42+
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"
1943

2044
@send external format: (t, int, timeUnit) => string = "format"
2145
@send
22-
external formatToParts: (
23-
t,
24-
int,
25-
timeUnit,
26-
) => array<{
27-
"type": string,
28-
"value": string,
29-
"unit": option<string>,
30-
}> = "formatToParts"
46+
external formatToParts: (t, int, timeUnit) => array<relativeTimePart> = "formatToParts"

0 commit comments

Comments
 (0)