Skip to content

Commit 64f449d

Browse files
authored
add docs for date module (#61)
* add docs for date module (WIP) * add docs for date module * remove Date.valueOf, add more examples for Date.makeXY functions * update CHANGELOG * change type time to msSinceEpoch and add doc strings * add examples for utc make functions * fix formatting * add more information about epoch * added disclaimer to examples and fixed one example and its output * fixed formatting of date module
1 parent ae939fa commit 64f449d

File tree

3 files changed

+1209
-148
lines changed

3 files changed

+1209
-148
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Remove internal async/await helpers that do not need to be exposed in `Core`.
1414
- Add locale and formatting options to `localeDateString`, `localeString` and `localTimeString` functions https://github.com/rescript-association/rescript-core/pull/30
1515
- Change `RegExp.source` to return a `string`. Was previously returning a `bool`, which is wrong. https://github.com/rescript-association/rescript-core/pull/47
16+
- Remove `Date.valueOf` as it returns the same as `Date.getTime`. https://github.com/rescript-association/rescript-core/pull/61
1617

1718
### Documentation
1819

@@ -24,3 +25,4 @@
2425
- Docstrings for `Int`. https://github.com/rescript-association/rescript-core/pull/37
2526
- Docstrings for `Dict`. https://github.com/rescript-association/rescript-core/pull/40
2627
- Docstrings for `RegExp`. https://github.com/rescript-association/rescript-core/pull/47
28+
- Docstrings for `Date`. https://github.com/rescript-association/rescript-core/pull/61

src/Core__Date.res

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type t = Js.Date.t
22

3-
type time = float
3+
type msSinceEpoch = float
44

55
type localeOptions = {
66
dateStyle?: [#full | #long | #medium | #short],
@@ -16,11 +16,9 @@ type localeOptions = {
1616
timeZoneName?: [#long | #short],
1717
}
1818

19-
@send external valueOf: t => time = "valueOf"
20-
2119
@new external make: unit => t = "Date"
2220
@new external fromString: string => t = "Date"
23-
@new external fromTime: time => t = "Date"
21+
@new external fromTime: msSinceEpoch => t = "Date"
2422

2523
@new external makeWithYM: (~year: int, ~month: int) => t = "Date"
2624
@new external makeWithYMD: (~year: int, ~month: int, ~date: int) => t = "Date"
@@ -49,18 +47,19 @@ external makeWithYMDHMSM: (
4947
) => t = "Date"
5048

5149
module UTC = {
52-
@val external makeWithYM: (~year: int, ~month: int) => time = "Date.UTC"
53-
@val external makeWithYMD: (~year: int, ~month: int, ~date: int) => time = "Date.UTC"
50+
@val external makeWithYM: (~year: int, ~month: int) => msSinceEpoch = "Date.UTC"
51+
@val external makeWithYMD: (~year: int, ~month: int, ~date: int) => msSinceEpoch = "Date.UTC"
5452
@val
55-
external makeWithYMDH: (~year: int, ~month: int, ~date: int, ~hours: int) => time = "Date.UTC"
53+
external makeWithYMDH: (~year: int, ~month: int, ~date: int, ~hours: int) => msSinceEpoch =
54+
"Date.UTC"
5655
@val
5756
external makeWithYMDHM: (
5857
~year: int,
5958
~month: int,
6059
~date: int,
6160
~hours: int,
6261
~minutes: int,
63-
) => time = "Date.UTC"
62+
) => msSinceEpoch = "Date.UTC"
6463
@val
6564
external makeWithYMDHMS: (
6665
~year: int,
@@ -69,7 +68,7 @@ module UTC = {
6968
~hours: int,
7069
~minutes: int,
7170
~seconds: int,
72-
) => time = "Date.UTC"
71+
) => msSinceEpoch = "Date.UTC"
7372
@val
7473
external makeWithYMDHMSM: (
7574
~year: int,
@@ -79,12 +78,12 @@ module UTC = {
7978
~minutes: int,
8079
~seconds: int,
8180
~milliseconds: int,
82-
) => time = "Date.UTC"
81+
) => msSinceEpoch = "Date.UTC"
8382
}
8483

85-
@val external now: unit => time = "Date.now"
84+
@val external now: unit => msSinceEpoch = "Date.now"
8685

87-
@send external getTime: t => time = "getTime"
86+
@send external getTime: t => msSinceEpoch = "getTime"
8887
@send external getTimezoneOffset: t => int = "getTimezoneOffset"
8988

9089
// Locale

0 commit comments

Comments
 (0)