Skip to content

Commit f594ec5

Browse files
committed
Update changelog; Add return values of code examples
1 parent 1ac4d86 commit f594ec5

File tree

2 files changed

+90
-72
lines changed

2 files changed

+90
-72
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Add `Array.at` binding for returning an array item by its index. https://github.com/rescript-association/rescript-core/pull/48
1212
- Fixed type signatures of `Array.fromArrayLikeWithMap` and `Array.fromIteratorWithMap`. https://github.com/rescript-association/rescript-core/pull/50
1313
- Remove internal async/await helpers that do not need to be exposed in `Core`.
14+
- Add locale and formatting options to `localeDateString`, `localeString` and `localTimeString` functions https://github.com/rescript-association/rescript-core/pull/30
1415

1516
### Documentation
1617

src/Core__Date.resi

Lines changed: 89 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ type t = Js.Date.t
66
type time = float
77

88
/**
9-
A type representing date time format options.
10-
11-
Note: There are some properties missing:
12-
- fractionalSecondDigits
13-
- dayPeriod
14-
- calendar
15-
- numberingSystem
16-
- localeMatcher
17-
- timeZone
18-
- hour12
19-
- hourCycle
20-
- formatMatcher
21-
22-
See full spec at https://tc39.es/ecma402/#datetimeformat-objects
9+
A type representing date time format options.
10+
11+
Note: There are some properties missing:
12+
- fractionalSecondDigits
13+
- dayPeriod
14+
- calendar
15+
- numberingSystem
16+
- localeMatcher
17+
- timeZone
18+
- hour12
19+
- hourCycle
20+
- formatMatcher
21+
22+
See full spec at https://tc39.es/ecma402/#datetimeformat-objects
2323
*/
2424
type localeOptions = {
2525
dateStyle?: [#full | #long | #medium | #short],
@@ -167,123 +167,140 @@ external setUTCMinutesSMs: (t, ~minutes: int, ~seconds: int, ~milliseconds: int)
167167
@send external toTimeString: t => string = "toTimeString"
168168

169169
/**
170-
`toLocaleDateString(date)`
170+
`toLocaleDateString(date)`
171171
172-
Converts a JavaScript date to a localized date string. It will use the current locale.
172+
Converts a JavaScript date to a localized date string. It will use the current locale.
173173
174-
## Examples
175-
```rescript
176-
Date.make()->Date.toLocaleDateString->Console.log
177-
```
174+
## Examples
175+
```rescript
176+
Date.make()->Date.toLocaleDateString->Console.log
177+
// 2/19/2023
178+
```
178179
*/
179180
@send
180181
external toLocaleDateString: t => string = "toLocaleDateString"
181182

182183
/**
183-
`toLocaleDateStringWithLocale(date, locale)`
184+
`toLocaleDateStringWithLocale(date, locale)`
184185
185-
Converts a JavaScript date to a localized date string. It will use the specified locale.
186+
Converts a JavaScript date to a localized date string. It will use the specified locale.
186187
187-
## Examples
188-
```rescript
189-
Date.make()->Date.toLocaleDateStringWithLocale("en-US")->Console.log
190-
```
188+
## Examples
189+
```rescript
190+
Date.make()->Date.toLocaleDateStringWithLocale("en-US")->Console.log
191+
// 2/19/2023
192+
```
191193
*/
192194
@send
193195
external toLocaleDateStringWithLocale: (t, string) => string = "toLocaleDateString"
194196

195197
/**
196-
`toLocaleDateStringWithLocaleAndOptions(date, locale, options)`
198+
`toLocaleDateStringWithLocaleAndOptions(date, locale, options)`
197199
198-
Converts a JavaScript date to a localized date string. It will use the specified locale and formatting options.
200+
Converts a JavaScript date to a localized date string. It will use the specified locale and formatting options.
199201
200-
## Examples
201-
```rescript
202-
Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("en-US", { dateStyle: #long })->Console.log
203-
Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", { hour: #"2-digit", minute: #"2-digit" })->Console.log
204-
Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", { year: #numeric })->Console.log
205-
```
202+
## Examples
203+
```rescript
204+
Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("en-US", { dateStyle: #long })->Console.log
205+
// February 19, 2023
206+
207+
Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", { hour: #"2-digit", minute: #"2-digit" })->Console.log
208+
// 19.2.2023, 15:40
209+
210+
Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", { year: #numeric })->Console.log
211+
// 2023
212+
```
206213
*/
207214
@send
208215
external toLocaleDateStringWithLocaleAndOptions: (t, string, localeOptions) => string =
209216
"toLocaleDateString"
210217

211218
/**
212-
`toLocaleString(date)`
219+
`toLocaleString(date)`
213220
214-
Converts a JavaScript date to a localized date-time string. It will use the current locale.
221+
Converts a JavaScript date to a localized date-time string. It will use the current locale.
215222
216-
## Examples
217-
```rescript
218-
Date.make()->Date.toLocaleString->Console.log
219-
```
223+
## Examples
224+
```rescript
225+
Date.make()->Date.toLocaleString->Console.log
226+
// 2/19/2023, 3:40:00 PM
227+
```
220228
*/
221229
@send
222230
external toLocaleString: t => string = "toLocaleString"
223231

224232
/**
225-
`toLocaleStringWithLocale(date, locale)`
233+
`toLocaleStringWithLocale(date, locale)`
226234
227-
Converts a JavaScript date to a localized date-time string. It will use the specified locale.
235+
Converts a JavaScript date to a localized date-time string. It will use the specified locale.
228236
229-
## Examples
230-
```rescript
231-
Date.make()->Date.toLocaleStringWithLocale("en-US")->Console.log
232-
```
237+
## Examples
238+
```rescript
239+
Date.make()->Date.toLocaleStringWithLocale("en-US")->Console.log
240+
// 2/19/2023, 3:40:00 PM
241+
```
233242
*/
234243
@send
235244
external toLocaleStringWithLocale: (t, string) => string = "toLocaleString"
236245

237246
/**
238-
`toLocaleStringWithLocaleAndOptions(date, locale, options)`
247+
`toLocaleStringWithLocaleAndOptions(date, locale, options)`
239248
240-
Converts a JavaScript date to a localized date-time string. It will use the specified locale and formatting options.
249+
Converts a JavaScript date to a localized date-time string. It will use the specified locale and formatting options.
241250
242-
## Examples
243-
```rescript
244-
Date.make()->Date.toLocaleStringWithLocaleAndOptions("en", { dateStyle: #short, timeStyle: #short })->Console.log
245-
Date.make()->Date.toLocaleStringWithLocaleAndOptions("en", { era: #long, year: #numeric, month: #"2-digit", day: #"2-digit", hour: #numeric, timeZoneName: #short })->Console.log
246-
```
251+
## Examples
252+
```rescript
253+
Date.make()->Date.toLocaleStringWithLocaleAndOptions("en", { dateStyle: #short, timeStyle: #short })->Console.log
254+
// 2/19/23, 3:40 PM
255+
256+
Date.make()->Date.toLocaleStringWithLocaleAndOptions("en", { era: #long, year: #numeric, month: #"2-digit", day: #"2-digit", hour: #numeric, timeZoneName: #short })->Console.log
257+
// 02/19/2023 Anno Domini, 3 PM GMT+1
258+
```
247259
*/
248260
@send
249261
external toLocaleStringWithLocaleAndOptions: (t, string, localeOptions) => string = "toLocaleString"
250262

251263
/**
252-
`toLocaleTimeString(date)`
264+
`toLocaleTimeString(date)`
253265
254-
Converts a JavaScript date to a localized time string. It will use the current locale.
266+
Converts a JavaScript date to a localized time string. It will use the current locale.
255267
256-
## Examples
257-
```rescript
258-
Date.make()->Date.toLocaleTimeString->Console.log
259-
```
268+
## Examples
269+
```rescript
270+
Date.make()->Date.toLocaleTimeString->Console.log
271+
// 3:40:00 PM
272+
```
260273
*/
261274
@send
262275
external toLocaleTimeString: t => string = "toLocaleTimeString"
263276

264277
/**
265-
`toLocaleTimeStringWithLocale(date, locale)`
278+
`toLocaleTimeStringWithLocale(date, locale)`
266279
267-
Converts a JavaScript date to a localized time string. It will use the specified locale.
280+
Converts a JavaScript date to a localized time string. It will use the specified locale.
268281
269-
## Examples
270-
```rescript
271-
Date.make()->Date.toLocaleTimeStringWithLocale("en-US")->Console.log
272-
```
282+
## Examples
283+
```rescript
284+
Date.make()->Date.toLocaleTimeStringWithLocale("en-US")->Console.log
285+
// 3:40:00 PM
286+
```
273287
*/
274288
@send
275289
external toLocaleTimeStringWithLocale: (t, string) => string = "toLocaleTimeString"
276290

277291
/**
278-
`toLocaleTimeStringWithLocaleAndOptions(date, locale, options)`
292+
`toLocaleTimeStringWithLocaleAndOptions(date, locale, options)`
293+
294+
Converts a JavaScript date to a localized time string. It will use the specified locale and formatting options.
279295
280-
Converts a JavaScript date to a localized time string. It will use the specified locale and formatting options.
296+
## Examples
297+
```rescript
298+
Date.make()->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", { timeStyle: #long })->Console.log
299+
// 3:40:00 PM GMT+1
281300
282-
## Examples
283-
```rescript
284-
Date.make()->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", { timeStyle: #long })->Console.log
285-
Date.make()->Date.toLocaleTimeStringWithLocaleAndOptions("de", { hour: #"2-digit", minute: #"2-digit" })->Console.log
286-
```
301+
Date.make()->Date.toLocaleTimeStringWithLocaleAndOptions("de", { hour: #"2-digit", minute: #"2-digit" })->Console.log
302+
// 15:40
303+
```
287304
*/
288305
@send
289306
external toLocaleTimeStringWithLocaleAndOptions: (t, string, localeOptions) => string =

0 commit comments

Comments
 (0)