Skip to content

replace ~date with ~day for Date.make* #7324

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

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
- Add `Dict.has` and double `Dict.forEachWithKey`/`Dict.mapValues` performance. https://github.com/rescript-lang/rescript/pull/7316
- Add popover attributes to JsxDOM.domProps. https://github.com/rescript-lang/rescript/pull/7317

#### :boom: Breaking Change

- Replace ~date with ~day in Date.make\*. https://github.com/rescript-lang/rescript/pull/7324

#### :house: Internal

- Clean up legacy tags handling. https://github.com/rescript-lang/rescript/pull/7309
Expand Down
24 changes: 12 additions & 12 deletions runtime/Stdlib_Date.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ type localeOptions = {
@new external fromTime: msSinceEpoch => t = "Date"

@new external makeWithYM: (~year: int, ~month: int) => t = "Date"
@new external makeWithYMD: (~year: int, ~month: int, ~date: int) => t = "Date"
@new external makeWithYMDH: (~year: int, ~month: int, ~date: int, ~hours: int) => t = "Date"
@new external makeWithYMD: (~year: int, ~month: int, ~day: int) => t = "Date"
@new external makeWithYMDH: (~year: int, ~month: int, ~day: int, ~hours: int) => t = "Date"
@new
external makeWithYMDHM: (~year: int, ~month: int, ~date: int, ~hours: int, ~minutes: int) => t =
external makeWithYMDHM: (~year: int, ~month: int, ~day: int, ~hours: int, ~minutes: int) => t =
"Date"
@new
external makeWithYMDHMS: (
~year: int,
~month: int,
~date: int,
~day: int,
~hours: int,
~minutes: int,
~seconds: int,
Expand All @@ -39,7 +39,7 @@ external makeWithYMDHMS: (
external makeWithYMDHMSM: (
~year: int,
~month: int,
~date: int,
~day: int,
~hours: int,
~minutes: int,
~seconds: int,
Expand All @@ -48,23 +48,23 @@ external makeWithYMDHMSM: (

module UTC = {
@val external makeWithYM: (~year: int, ~month: int) => msSinceEpoch = "Date.UTC"
@val external makeWithYMD: (~year: int, ~month: int, ~date: int) => msSinceEpoch = "Date.UTC"
@val external makeWithYMD: (~year: int, ~month: int, ~day: int) => msSinceEpoch = "Date.UTC"
@val
external makeWithYMDH: (~year: int, ~month: int, ~date: int, ~hours: int) => msSinceEpoch =
external makeWithYMDH: (~year: int, ~month: int, ~day: int, ~hours: int) => msSinceEpoch =
"Date.UTC"
@val
external makeWithYMDHM: (
~year: int,
~month: int,
~date: int,
~day: int,
~hours: int,
~minutes: int,
) => msSinceEpoch = "Date.UTC"
@val
external makeWithYMDHMS: (
~year: int,
~month: int,
~date: int,
~day: int,
~hours: int,
~minutes: int,
~seconds: int,
Expand All @@ -73,7 +73,7 @@ module UTC = {
external makeWithYMDHMSM: (
~year: int,
~month: int,
~date: int,
~day: int,
~hours: int,
~minutes: int,
~seconds: int,
Expand Down Expand Up @@ -102,7 +102,7 @@ let compare = (a, b) => Stdlib_Float.compare(a->getTime, b->getTime)

@send external setFullYear: (t, int) => unit = "setFullYear"
@send external setFullYearM: (t, ~year: int, ~month: int) => unit = "setFullYear"
@send external setFullYearMD: (t, ~year: int, ~month: int, ~date: int) => unit = "setFullYear"
@send external setFullYearMD: (t, ~year: int, ~month: int, ~day: int) => unit = "setFullYear"
@send external setMonth: (t, int) => unit = "setMonth"
@send external setDate: (t, int) => unit = "setDate"
@send external setHours: (t, int) => unit = "setHours"
Expand Down Expand Up @@ -132,7 +132,7 @@ external setMinutesSMs: (t, ~minutes: int, ~seconds: int, ~milliseconds: int) =>
@send external setUTCFullYear: (t, int) => unit = "setUTCFullYear"
@send external setUTCFullYearM: (t, ~year: int, ~month: int) => unit = "setUTCFullYear"
@send
external setUTCFullYearMD: (t, ~year: int, ~month: int, ~date: int) => unit = "setUTCFullYear"
external setUTCFullYearMD: (t, ~year: int, ~month: int, ~day: int) => unit = "setUTCFullYear"
@send external setUTCMonth: (t, int) => unit = "setUTCMonth"
@send external setUTCDate: (t, int) => unit = "setUTCDate"
@send external setUTCHours: (t, int) => unit = "setUTCHours"
Expand Down
92 changes: 46 additions & 46 deletions runtime/Stdlib_Date.resi
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ Values, which are out of range, will be carried over to the next bigger unit (s.

## Examples
```rescript
Date.makeWithYMD(~year=2023, ~month=1, ~date=20)
Date.makeWithYMD(~year=2023, ~month=1, ~day=20)
// 2023-02-20T00:00:00.000Z

Date.makeWithYMD(~year=2023, ~month=1, ~date=-1)
Date.makeWithYMD(~year=2023, ~month=1, ~day=-1)
// 2022-11-29T00:00:00.000Z

Date.makeWithYMD(~year=2023, ~month=1, ~date=29)
Date.makeWithYMD(~year=2023, ~month=1, ~day=29)
// 2023-03-01T00:00:00.000Z
```
*/
@new
external makeWithYMD: (~year: int, ~month: int, ~date: int) => t = "Date"
external makeWithYMD: (~year: int, ~month: int, ~day: int) => t = "Date"

/**
Creates a date object with the given year, month, date (day of month) and hours.
Expand All @@ -159,13 +159,13 @@ Values, which are out of range, will be carried over to the next bigger unit (s.

## Examples
```rescript
Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16)
Date.makeWithYMDH(~year=2023, ~month=1, ~day=20, ~hours=16)
// 2023-02-20T16:00:00.000Z

Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24)
Date.makeWithYMDH(~year=2023, ~month=1, ~day=20, ~hours=24)
// 2023-02-21T00:00:00.000Z

Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1)
Date.makeWithYMDH(~year=2023, ~month=1, ~day=20, ~hours=-1)
// 2023-02-19T23:00:00.000Z

// Note: The output depends on your local time zone.
Expand All @@ -174,7 +174,7 @@ Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1)
```
*/
@new
external makeWithYMDH: (~year: int, ~month: int, ~date: int, ~hours: int) => t = "Date"
external makeWithYMDH: (~year: int, ~month: int, ~day: int, ~hours: int) => t = "Date"

/**
Creates a date object with the given year, month, date (day of month), hours and minutes.
Expand All @@ -184,13 +184,13 @@ Values, which are out of range, will be carried over to the next bigger unit (s.

## Examples
```rescript
Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40)
Date.makeWithYMDHM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40)
// 2023-02-20T16:40:00.000Z

Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60)
Date.makeWithYMDHM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=60)
// 2023-02-20T17:00:00.000Z

Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1)
Date.makeWithYMDHM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=-1)
// 2023-02-20T15:59:00.000Z

// Note: The output depends on your local time zone.
Expand All @@ -199,7 +199,7 @@ Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1)
```
*/
@new
external makeWithYMDHM: (~year: int, ~month: int, ~date: int, ~hours: int, ~minutes: int) => t =
external makeWithYMDHM: (~year: int, ~month: int, ~day: int, ~hours: int, ~minutes: int) => t =
"Date"

/**
Expand All @@ -210,13 +210,13 @@ Values, which are out of range, will be carried over to the next bigger unit (s.

## Examples
```rescript
Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0)
Date.makeWithYMDHMS(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0)
// 2023-02-20T16:40:00.000Z

Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60)
Date.makeWithYMDHMS(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=60)
// 2023-02-20T16:41:00.000Z

Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1)
Date.makeWithYMDHMS(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=-1)
// 2023-02-20T16:39:59.000Z

// Note: The output depends on your local time zone.
Expand All @@ -228,7 +228,7 @@ Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~sec
external makeWithYMDHMS: (
~year: int,
~month: int,
~date: int,
~day: int,
~hours: int,
~minutes: int,
~seconds: int,
Expand All @@ -242,13 +242,13 @@ Values, which are out of range, will be carried over to the next bigger unit (s.

## Examples
```rescript
Date.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=0)
Date.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=0)
// 2023-02-20T16:40:00.000Z

Date.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=1000)
Date.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=1000)
// 2023-02-20T16:40:01.000Z

Date.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=-1)
Date.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=-1)
// 2023-02-20T16:39:59.999Z

// Note: The output depends on your local time zone.
Expand All @@ -260,7 +260,7 @@ Date.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~se
external makeWithYMDHMSM: (
~year: int,
~month: int,
~date: int,
~day: int,
~hours: int,
~minutes: int,
~seconds: int,
Expand Down Expand Up @@ -299,18 +299,18 @@ module UTC: {

## Examples
```rescript
Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=20)
Date.UTC.makeWithYMD(~year=2023, ~month=1, ~day=20)
// 1676851200000

Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=-1)
Date.UTC.makeWithYMD(~year=2023, ~month=1, ~day=-1)
// 1675036800000

Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=29)
Date.UTC.makeWithYMD(~year=2023, ~month=1, ~day=29)
// 1677628800000
```
*/
@val
external makeWithYMD: (~year: int, ~month: int, ~date: int) => msSinceEpoch = "Date.UTC"
external makeWithYMD: (~year: int, ~month: int, ~day: int) => msSinceEpoch = "Date.UTC"

/**
Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC).
Expand All @@ -320,18 +320,18 @@ module UTC: {

## Examples
```rescript
Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16)
Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~day=20, ~hours=16)
// 1676908800000

Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24)
Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~day=20, ~hours=24)
// 1676937600000

Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1)
Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~day=20, ~hours=-1)
// 1676847600000
```
*/
@val
external makeWithYMDH: (~year: int, ~month: int, ~date: int, ~hours: int) => msSinceEpoch =
external makeWithYMDH: (~year: int, ~month: int, ~day: int, ~hours: int) => msSinceEpoch =
"Date.UTC"

/**
Expand All @@ -342,21 +342,21 @@ module UTC: {

## Examples
```rescript
Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40)
Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40)
// 1676911200000

Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60)
Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=60)
// 1676912400000

Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1)
Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=-1)
// 1676908740000
```
*/
@val
external makeWithYMDHM: (
~year: int,
~month: int,
~date: int,
~day: int,
~hours: int,
~minutes: int,
) => msSinceEpoch = "Date.UTC"
Expand All @@ -369,21 +369,21 @@ module UTC: {

## Examples
```rescript
Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0)
Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0)
// 1676911200000

Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60)
Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=60)
// 1676911260000

Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1)
Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=-1)
// 1676911199000
```
*/
@val
external makeWithYMDHMS: (
~year: int,
~month: int,
~date: int,
~day: int,
~hours: int,
~minutes: int,
~seconds: int,
Expand All @@ -397,21 +397,21 @@ module UTC: {

## Examples
```rescript
Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=0)->Console.log
Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=0)->Console.log
// 1676911200000

Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=1000)->Console.log
Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=1000)->Console.log
// 1676911201000

Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=-1)->Console.log
Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=-1)->Console.log
// 1676911199999
```
*/
@val
external makeWithYMDHMSM: (
~year: int,
~month: int,
~date: int,
~day: int,
~hours: int,
~minutes: int,
~seconds: int,
Expand Down Expand Up @@ -607,18 +607,18 @@ Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearM(~year=2024, ~month=
external setFullYearM: (t, ~year: int, ~month: int) => unit = "setFullYear"

/**
`setFullYearMD(date, ~year, ~month, ~date)`
`setFullYearMD(date, ~year, ~month, ~day)`

Sets the year, month and date (day of month) of a date (according to local time).
Beware this will *mutate* the date.

## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearMD(~year=2024, ~month=0, ~date=1)
Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearMD(~year=2024, ~month=0, ~day=1)
```
*/
@send
external setFullYearMD: (t, ~year: int, ~month: int, ~date: int) => unit = "setFullYear"
external setFullYearMD: (t, ~year: int, ~month: int, ~day: int) => unit = "setFullYear"

/**
`setMonth(date, month)`
Expand Down Expand Up @@ -923,18 +923,18 @@ Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearM(~year=2024, ~mon
external setUTCFullYearM: (t, ~year: int, ~month: int) => unit = "setUTCFullYear"

/**
`setUTCFullYearMD(date, ~year, ~month, ~date)`
`setUTCFullYearMD(date, ~year, ~month, ~day)`

Sets the year, month and date (day of month) of a date (according to UTC time).
Beware this will *mutate* the date.

## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearMD(~year=2024, ~month=0, ~date=1)
Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearMD(~year=2024, ~month=0, ~day=1)
```
*/
@send
external setUTCFullYearMD: (t, ~year: int, ~month: int, ~date: int) => unit = "setUTCFullYear"
external setUTCFullYearMD: (t, ~year: int, ~month: int, ~day: int) => unit = "setUTCFullYear"

/**
`setUTCMonth(date, month)`
Expand Down
Loading