├── .all-contributorsrc ├── .github └── FUNDING.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── __tests__ ├── addBusinessDays_test.res ├── addDays_test.res ├── addHours_test.res ├── addMinutes_test.res ├── addMonths_test.res ├── addSeconds_test.res ├── addWeeks_test.res ├── addYears_test.res ├── areIntervalsOverlapping_test.res ├── closestTo_test.res ├── compareAsc_test.res ├── compareDesc_test.res ├── differenceInBusinessDays_test.res ├── differenceInCalendarDays_test.res ├── differenceInCalendarISOWeeks_test.res ├── differenceInCalendarMonths_test.res ├── differenceInCalendarWeeks_test.res ├── differenceInCalendarYears_test.res ├── differenceInDays_test.res ├── differenceInHours_test.res ├── differenceInMinutes_test.res ├── differenceInMonths_test.res ├── differenceInSeconds_test.res ├── differenceInWeeks_test.res ├── differenceInYears_test.res ├── eachDayOfInterval_test.res ├── endOfDay_test.res ├── endOfHour_test.res ├── endOfISOWeek_test.res ├── endOfMinute_test.res ├── endOfMonth_test.res ├── endOfSecond_test.res ├── endOfWeek_test.res ├── endOfYear_test.res ├── getDay.res ├── getDayOfYear_test.res ├── getDaysInMonth_test.res ├── getDaysInYear_test.res ├── getISOWeekYear_test.res ├── getISOWeek_test.res ├── getOverlappingDaysInIntervals_test.res ├── getWeekOfMonth_test.res ├── getWeekYear_test.res ├── getWeek_test.res ├── getWeeksInMonth_test.res ├── isAfter_test.res ├── isBefore_test.res ├── isEqual_test.res ├── isFirstDayOfMonth_test.res ├── isFriday_test.res ├── isFuture_test.res ├── isLastDayOfMonth_test.res ├── isLeapYear_test.res ├── isMonday_test.res ├── isPast_test.res ├── isSameDay_test.res ├── isSameHour_test.res ├── isSameISOWeek_test.res ├── isSameMinute_test.res ├── isSameMonth_test.res ├── isSameSecond_test.res ├── isSameWeek_test.res ├── isSameYear_test.res ├── isSaturday_test.res ├── isSunday_test.res ├── isThisISOWeek_test.res ├── isThursday_test.res ├── isTuesday_test.res ├── isWednesday_test.res ├── isWeekDay_test.res ├── isWeekend_test.res ├── isWithinInterval_test.res ├── lastDayOfISOWeek_test.res ├── lastDayOfMonth_test.res ├── lastDayOfWeek_test.res ├── lastDayOfYear_test.res ├── lastMonthOfYear_test.res ├── max.res ├── min.res ├── roundToNearestMinute_test.res ├── setDate_test.res ├── setHours_test.res ├── setISOWeek_test.res ├── setMinutes_test.res ├── setMonth_test.res ├── setSeconds_test.res ├── setYear_test.res ├── startOfDay_test.res ├── startOfHour_test.res ├── startOfISOWeekYear_test.res ├── startOfISOWeek_test.res ├── startOfMinute_test.res ├── startOfMonth_test.res ├── startOfSecond_test.res ├── startOfWeekYear_test.res ├── startOfWeek_test.res ├── startOfYear_test.res ├── subDays_test.res ├── subHours_test.res ├── subMinutes_test.res ├── subMonths_test.res ├── subSeconds_test.res ├── subWeeks_test.res └── subYears_test.res ├── assets └── rescript-date-frame.png ├── bsconfig.json ├── docs ├── .gitignore ├── api │ ├── common.md │ ├── day.md │ ├── hour.md │ ├── interval.md │ ├── iso-week-numbering.md │ ├── iso-week.md │ ├── minute.md │ ├── month.md │ ├── second.md │ ├── week-numbering.md │ ├── week.md │ ├── weekday.md │ └── year.md ├── babel.config.js ├── docs │ ├── changelog.md │ ├── installation.md │ └── status.md ├── docusaurus.config.js ├── package.json ├── sidebars.api.js ├── sidebars.js ├── src │ ├── css │ │ └── custom.css │ └── pages │ │ ├── index.js │ │ └── styles.module.css ├── static │ ├── .nojekyll │ └── img │ │ ├── favicon.ico │ │ ├── hero-logo.png │ │ └── rescript-date-logo.png └── yarn.lock ├── jest.config.js ├── package.json ├── src ├── ReDate.res ├── ReDate_common.res ├── ReDate_day.res ├── ReDate_hour.res ├── ReDate_interval.res ├── ReDate_iso_week.res ├── ReDate_iso_week_numbering.res ├── ReDate_minute.res ├── ReDate_month.res ├── ReDate_second.res ├── ReDate_types.res ├── ReDate_utils.res ├── ReDate_week.res ├── ReDate_week_numbering.res ├── ReDate_weekday.res └── ReDate_year.res └── yarn.lock /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "re-date", 3 | "projectOwner": "mobily", 4 | "repoType": "github", 5 | "repoHost": "https://github.com", 6 | "files": [ 7 | "README.md" 8 | ], 9 | "imageSize": 100, 10 | "commit": false, 11 | "contributors": [ 12 | { 13 | "login": "mobily", 14 | "name": "Marcin Dziewulski", 15 | "avatar_url": "https://avatars1.githubusercontent.com/u/1467712?v=4", 16 | "profile": "https://twitter.com/__marcin_", 17 | "contributions": [ 18 | "code", 19 | "doc", 20 | "design", 21 | "test" 22 | ] 23 | }, 24 | { 25 | "login": "panr", 26 | "name": "Radek Kozieł", 27 | "avatar_url": "https://avatars3.githubusercontent.com/u/1303365?v=4", 28 | "profile": "http://radoslawkoziel.pl", 29 | "contributions": [ 30 | "code" 31 | ] 32 | }, 33 | { 34 | "login": "mikaello", 35 | "name": "mikaello", 36 | "avatar_url": "https://avatars3.githubusercontent.com/u/2505178?v=4", 37 | "profile": "https://github.com/mikaello", 38 | "contributions": [ 39 | "code", 40 | "doc", 41 | "test" 42 | ] 43 | }, 44 | { 45 | "login": "fccm", 46 | "name": "Florent Monnier", 47 | "avatar_url": "https://avatars.githubusercontent.com/u/2274092?v=4", 48 | "profile": "http://decapode314.free.fr/ocaml/", 49 | "contributions": [ 50 | "code" 51 | ] 52 | } 53 | ], 54 | "commitConvention": "none" 55 | } 56 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ["https://www.buymeacoffee.com/utSC0k7"] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | lib/ 3 | coverage/ 4 | dist/ 5 | .trash/ 6 | 7 | .idea/ 8 | .vscode/ 9 | 10 | .DS_Store 11 | .merlin 12 | .bsb.lock 13 | 14 | *.log 15 | *.bs.js 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | language: node_js 3 | node_js: 4 | - 15 5 | sudo: false 6 | branches: 7 | only: 8 | - master 9 | notifications: 10 | email: 11 | on_success: change 12 | on_failure: always 13 | cache: yarn 14 | script: 15 | - yarn re:clean 16 | - yarn re:build 17 | - yarn test 18 | - cat coverage/lcov.info | node_modules/.bin/coveralls || echo "Coveralls upload failed" 19 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### `v2.1.0` 4 | 5 | - ✨ added [`getDay`](/api/weekday#getday) 6 | - ✨ added [`isWeekDay`](/api/weekday#isweekday) 7 | 8 | ### `v2.0.0` 9 | 10 | Use a pipe-first (`->`) operator instead of deprecated pipe-forward (`|>`). 11 | 12 | Learn more: https://rescript-lang.org/docs/manual/v8.0.0/pipe#triangle-pipe-deprecated 13 | 14 | ### `v1.0.0` 15 | 16 | Initial ReScript implementation. 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Marcin Dziewulski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 |

5 | 6 | Build Status 7 | 8 | 9 | Coverage 10 | 11 | 12 | npm 13 | 14 | 15 | PRs Welcome 16 | 17 | 18 | All Contributors 19 | 20 | 21 | GitHub license 22 | 23 |

24 | 25 | 26 |

27 | Date manipulation in ReScript with the same modern and convenient API as date-fns. 28 |

29 | 30 | ## Documentation 31 | 32 | Full documentation can be found [here](https://mobily.github.io/rescript-date). 33 | 34 | ## Getting started 35 | 36 | ### Installation 37 | 38 | ```shell 39 | yarn add @mobily/rescript-date 40 | ``` 41 | 42 | or with `npm` 43 | 44 | ```shell 45 | npm install @mobily/rescript-date --save 46 | ``` 47 | 48 | ### ReScript config 49 | 50 | Add `@mobily/rescript-date` to `bs-dependencies` in your `bsconfig.json`: 51 | 52 | ```json 53 | { 54 | "bs-dependencies": [ 55 | "@mobily/rescript-date" 56 | ] 57 | } 58 | ``` 59 | 60 | ## Contributors 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |

Marcin Dziewulski

💻 📖 🎨 ⚠️

Radek Kozieł

💻

mikaello

💻 📖 ⚠️

Florent Monnier

💻
73 | 74 | 75 | 76 | 77 | 78 | 79 | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! 80 | 81 | ## License 82 | 83 | The MIT License. 84 | 85 | See [LICENSE](LICENSE) 86 | -------------------------------------------------------------------------------- /__tests__/addBusinessDays_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("addBusinessDays", () => { 6 | open ExpectJs 7 | 8 | test("adds 0 business days", () => { 9 | let date = makeWithYMD(~year=2020., ~month=0., ~date=1., ()) 10 | let expectedDate = makeWithYMD(~year=2020., ~month=0., ~date=1., ()) 11 | 12 | let result = date->ReDate.addBusinessDays(0.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | 17 | test("adds 1 business day", () => { 18 | let date = makeWithYMD(~year=2020., ~month=0., ~date=1., ()) 19 | let expectedDate = makeWithYMD(~year=2020., ~month=0., ~date=2., ()) 20 | 21 | let result = date->ReDate.addBusinessDays(1.) 22 | 23 | result |> expect |> toEqual(expectedDate) 24 | }) 25 | 26 | test("adds 100 business days", () => { 27 | let date = makeWithYMD(~year=2020., ~month=0., ~date=1., ()) 28 | let expectedDate = makeWithYMD(~year=2020., ~month=4., ~date=20., ()) 29 | 30 | let result = date->ReDate.addBusinessDays(100.) 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }) 34 | 35 | test("handles negative number", () => { 36 | let date = makeWithYMD(~year=2020., ~month=4., ~date=20., ()) 37 | let expectedDate = makeWithYMD(~year=2020., ~month=0., ~date=1., ()) 38 | 39 | let result = date->ReDate.addBusinessDays(-100.) 40 | 41 | result |> expect |> toEqual(expectedDate) 42 | }) 43 | 44 | test("returns Monday when 1 day is added on Friday", () => { 45 | let date = makeWithYMD(~year=2020., ~month=0., ~date=10., ()) 46 | let expectedDate = makeWithYMD(~year=2020., ~month=0., ~date=13., ()) 47 | 48 | let result = date->ReDate.addBusinessDays(1.) 49 | 50 | result |> expect |> toEqual(expectedDate) 51 | }) 52 | 53 | test("returns Monday when 1 day is added on Saturday", () => { 54 | let date = makeWithYMD(~year=2020., ~month=0., ~date=11., ()) 55 | let expectedDate = makeWithYMD(~year=2020., ~month=0., ~date=13., ()) 56 | 57 | let result = date->ReDate.addBusinessDays(1.) 58 | 59 | result |> expect |> toEqual(expectedDate) 60 | }) 61 | 62 | test("returns Monday when 1 day is added on Sunday", () => { 63 | let date = makeWithYMD(~year=2020., ~month=0., ~date=12., ()) 64 | let expectedDate = makeWithYMD(~year=2020., ~month=0., ~date=13., ()) 65 | 66 | let result = date->ReDate.addBusinessDays(1.) 67 | 68 | result |> expect |> toEqual(expectedDate) 69 | }) 70 | }) 71 | -------------------------------------------------------------------------------- /__tests__/addDays_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("addDays", () => { 6 | open ExpectJs 7 | 8 | test("adds 1 day", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | let expectedDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 11 | 12 | let result = date->ReDate.addDays(1.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | 17 | test("adds 100 days", () => { 18 | let date = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 19 | let expectedDate = makeWithYMD(~year=2018., ~month=3., ~date=11., ()) 20 | 21 | let result = date->ReDate.addDays(100.) 22 | 23 | result |> expect |> toEqual(expectedDate) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/addHours_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("addHours", () => { 6 | open ExpectJs 7 | 8 | test("adds 1 hour", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=19., 14 | ~minutes=30., 15 | ~seconds=0., 16 | (), 17 | ) 18 | let expectedDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=20., 23 | ~minutes=30., 24 | ~seconds=0., 25 | (), 26 | ) 27 | 28 | let result = date->ReDate.addHours(1.) 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | 33 | test("adds 60 hours", () => { 34 | let date = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=19., 39 | ~minutes=30., 40 | ~seconds=0., 41 | (), 42 | ) 43 | let expectedDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=4., 47 | ~hours=7., 48 | ~minutes=30., 49 | ~seconds=0., 50 | (), 51 | ) 52 | 53 | let result = date->ReDate.addHours(60.) 54 | 55 | result |> expect |> toEqual(expectedDate) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/addMinutes_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("addMinutes", () => { 6 | open ExpectJs 7 | 8 | test("adds 1 minute", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=19., 14 | ~minutes=30., 15 | ~seconds=30., 16 | (), 17 | ) 18 | let expectedDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=19., 23 | ~minutes=31., 24 | ~seconds=30., 25 | (), 26 | ) 27 | 28 | let result = date->ReDate.addMinutes(1.) 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | 33 | test("adds 100 minutes", () => { 34 | let date = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=19., 39 | ~minutes=30., 40 | ~seconds=30., 41 | (), 42 | ) 43 | let expectedDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=1., 47 | ~hours=21., 48 | ~minutes=10., 49 | ~seconds=30., 50 | (), 51 | ) 52 | 53 | let result = date->ReDate.addMinutes(100.) 54 | 55 | result |> expect |> toEqual(expectedDate) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/addMonths_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("addMonths", () => { 6 | open ExpectJs 7 | 8 | test("adds 1 month", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | let expectedDate = makeWithYMD(~year=2018., ~month=1., ~date=1., ()) 11 | 12 | let result = date->ReDate.addMonths(1.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | 17 | test("adds 30 months", () => { 18 | let date = makeWithYMD(~year=2018., ~month=5., ~date=1., ()) 19 | let expectedDate = makeWithYMD(~year=2020., ~month=11., ~date=1., ()) 20 | 21 | let result = date->ReDate.addMonths(30.) 22 | 23 | result |> expect |> toEqual(expectedDate) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/addSeconds_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("addSeconds", () => { 6 | open ExpectJs 7 | 8 | test("adds 1 second", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=19., 14 | ~minutes=30., 15 | ~seconds=0., 16 | (), 17 | ) 18 | let expectedDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=19., 23 | ~minutes=30., 24 | ~seconds=1., 25 | (), 26 | ) 27 | 28 | let result = date->ReDate.addSeconds(1.) 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | 33 | test("adds 100 seconds", () => { 34 | let date = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=19., 39 | ~minutes=30., 40 | ~seconds=0., 41 | (), 42 | ) 43 | let expectedDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=1., 47 | ~hours=19., 48 | ~minutes=31., 49 | ~seconds=40., 50 | (), 51 | ) 52 | 53 | let result = date->ReDate.addSeconds(100.) 54 | 55 | result |> expect |> toEqual(expectedDate) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/addWeeks_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("addWeeks", () => { 6 | open ExpectJs 7 | 8 | test("adds 1 week", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | let expectedDate = makeWithYMD(~year=2018., ~month=0., ~date=8., ()) 11 | 12 | let result = date->ReDate.addWeeks(1.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | 17 | test("adds 10 weeks", () => { 18 | let date = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 19 | let expectedDate = makeWithYMD(~year=2018., ~month=2., ~date=12., ()) 20 | 21 | let result = date->ReDate.addWeeks(10.) 22 | 23 | result |> expect |> toEqual(expectedDate) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/addYears_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("addYears", () => { 6 | open ExpectJs 7 | 8 | test("adds 1 year", () => { 9 | let date = makeWithYMD(~year=2018., ~month=4., ~date=1., ()) 10 | let expectedDate = makeWithYMD(~year=2019., ~month=4., ~date=1., ()) 11 | 12 | let result = date->ReDate.addYears(1.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | 17 | test("adds 10 years", () => { 18 | let date = makeWithYMD(~year=1999., ~month=4., ~date=1., ()) 19 | let expectedDate = makeWithYMD(~year=2009., ~month=4., ~date=1., ()) 20 | 21 | let result = date->ReDate.addYears(10.) 22 | 23 | result |> expect |> toEqual(expectedDate) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/areIntervalsOverlapping_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("areIntervalsOverlapping", () => { 6 | open ExpectJs 7 | open ReDate 8 | 9 | let interval = { 10 | start: makeWithYMD(~year=2018., ~month=3., ~date=1., ()), 11 | end_: makeWithYMD(~year=2018., ~month=4., ~date=10., ()), 12 | } 13 | 14 | test("returns true for an interval included within another interval", () => { 15 | let includedInterval = { 16 | start: makeWithYMD(~year=2018., ~month=3., ~date=5., ()), 17 | end_: makeWithYMD(~year=2018., ~month=4., ~date=5., ()), 18 | } 19 | 20 | interval |> ReDate.areIntervalsOverlapping(includedInterval) |> expect |> toBeTruthy 21 | }) 22 | 23 | test("returns true for an interval including another interval", () => { 24 | let includingInterval = { 25 | start: makeWithYMD(~year=2018., ~month=3., ~date=5., ()), 26 | end_: makeWithYMD(~year=2018., ~month=4., ~date=5., ()), 27 | } 28 | 29 | includingInterval |> ReDate.areIntervalsOverlapping(interval) |> expect |> toBeTruthy 30 | }) 31 | 32 | test("returns false for a valid non overlapping interval before another interval", () => { 33 | let earlierInterval = { 34 | start: makeWithYMD(~year=2018., ~month=2., ~date=20., ()), 35 | end_: makeWithYMD(~year=2018., ~month=2., ~date=30., ()), 36 | } 37 | 38 | earlierInterval |> ReDate.areIntervalsOverlapping(interval) |> expect |> toBeFalsy 39 | }) 40 | 41 | test("returns false for a valid non overlapping interval after another interval", () => { 42 | let laterInterval = { 43 | start: makeWithYMD(~year=2018., ~month=4., ~date=11., ()), 44 | end_: makeWithYMD(~year=2018., ~month=4., ~date=30., ()), 45 | } 46 | 47 | laterInterval |> ReDate.areIntervalsOverlapping(interval) |> expect |> toBeFalsy 48 | }) 49 | }) 50 | -------------------------------------------------------------------------------- /__tests__/closestTo_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("closestTo", () => { 6 | open ExpectJs 7 | 8 | test("returns the date from the given list closest to the given date #1", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | 11 | let a = makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 12 | let b = makeWithYMD(~year=2018., ~month=2., ~date=1., ()) 13 | let c = makeWithYMD(~year=2020., ~month=4., ~date=1., ()) 14 | let d = makeWithYMD(~year=2022., ~month=12., ~date=1., ()) 15 | 16 | let dates = [a, b, c, d] 17 | 18 | let result = date->ReDate.closestTo(dates) 19 | 20 | result |> expect |> toEqual(Some(b)) 21 | }) 22 | 23 | test("returns the date from the given list closest to the given date #2", () => { 24 | let date = makeWithYMDHMS( 25 | ~year=2019., 26 | ~month=0., 27 | ~date=1., 28 | ~hours=8., 29 | ~minutes=45., 30 | ~seconds=15., 31 | (), 32 | ) 33 | 34 | let a = makeWithYMDHMS( 35 | ~year=2019., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=8., 39 | ~minutes=50., 40 | ~seconds=0., 41 | (), 42 | ) 43 | let b = makeWithYMDHMS( 44 | ~year=2019., 45 | ~month=0., 46 | ~date=1., 47 | ~hours=8., 48 | ~minutes=45., 49 | ~seconds=20., 50 | (), 51 | ) 52 | let c = makeWithYMDHMS( 53 | ~year=2019., 54 | ~month=0., 55 | ~date=1., 56 | ~hours=8., 57 | ~minutes=45., 58 | ~seconds=19., 59 | (), 60 | ) 61 | let d = makeWithYMDHMS( 62 | ~year=2019., 63 | ~month=0., 64 | ~date=1., 65 | ~hours=8., 66 | ~minutes=45., 67 | ~seconds=13., 68 | (), 69 | ) 70 | 71 | let dates = [a, b, c, d] 72 | 73 | let result = date->ReDate.closestTo(dates) 74 | 75 | result |> expect |> toEqual(Some(d)) 76 | }) 77 | 78 | test("returns `None` if the given list is empty", () => { 79 | let date = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 80 | let dates = [] 81 | 82 | let result = date->ReDate.closestTo(dates) 83 | 84 | result |> expect |> toEqual(None) 85 | }) 86 | }) 87 | -------------------------------------------------------------------------------- /__tests__/compareAsc_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("compareAsc", () => { 6 | open ExpectJs 7 | 8 | test("returns 0 if the given dates are equal", () => { 9 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 11 | 12 | let result = ReDate.compareAsc(fstDate, sndDate) 13 | 14 | result |> expect |> toEqual(0) 15 | }) 16 | 17 | test("returns 1 if the first date is after the second one", () => { 18 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 19 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 20 | 21 | let result = ReDate.compareAsc(fstDate, sndDate) 22 | 23 | result |> expect |> toEqual(1) 24 | }) 25 | 26 | test("returns -1 if the first date is before the second one", () => { 27 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 28 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 29 | 30 | let result = ReDate.compareAsc(fstDate, sndDate) 31 | 32 | result |> expect |> toEqual(-1) 33 | }) 34 | 35 | test( 36 | "sorts the dates array in the chronological order when function is passed as the argument to sort function", 37 | () => { 38 | let a = makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 39 | let b = makeWithYMD(~year=2017., ~month=2., ~date=1., ()) 40 | let c = makeWithYMD(~year=2017., ~month=4., ~date=1., ()) 41 | let d = makeWithYMD(~year=2018., ~month=12., ~date=1., ()) 42 | 43 | let unsortedArray = [d, b, c, a] 44 | let expected = [a, b, c, d] 45 | let sortedArray = Belt.SortArray.stableSortBy(unsortedArray, ReDate.compareAsc) 46 | 47 | let result = Belt.Array.eq(sortedArray, expected, (x, y) => x == y) 48 | 49 | result |> expect |> toBeTruthy 50 | }, 51 | ) 52 | }) 53 | -------------------------------------------------------------------------------- /__tests__/compareDesc_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("compareDesc", () => { 6 | open ExpectJs 7 | 8 | test("returns 0 if the given dates are equal", () => { 9 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 11 | 12 | let result = ReDate.compareDesc(fstDate, sndDate) 13 | 14 | result |> expect |> toEqual(0) 15 | }) 16 | 17 | test("returns -1 if the first date is after the second one", () => { 18 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 19 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 20 | 21 | let result = ReDate.compareDesc(fstDate, sndDate) 22 | 23 | result |> expect |> toEqual(-1) 24 | }) 25 | 26 | test("returns 1 if the first date is before the second one", () => { 27 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 28 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 29 | 30 | let result = ReDate.compareDesc(fstDate, sndDate) 31 | 32 | result |> expect |> toEqual(1) 33 | }) 34 | 35 | test( 36 | "sorts the dates array in the chronological order when function is passed as the argument to sort function", 37 | () => { 38 | let a = makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 39 | let b = makeWithYMD(~year=2017., ~month=2., ~date=1., ()) 40 | let c = makeWithYMD(~year=2017., ~month=4., ~date=1., ()) 41 | let d = makeWithYMD(~year=2018., ~month=12., ~date=1., ()) 42 | 43 | let unsortedArray = [a, b, d, c] 44 | let expected = [d, c, b, a] 45 | let sortedArray = Belt.SortArray.stableSortBy(unsortedArray, ReDate.compareDesc) 46 | 47 | let result = Belt.Array.eq(sortedArray, expected, (x, y) => x == y) 48 | 49 | result |> expect |> toBeTruthy 50 | }, 51 | ) 52 | }) 53 | -------------------------------------------------------------------------------- /__tests__/differenceInBusinessDays_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInBusinessDays", () => { 6 | open ExpectJs 7 | 8 | test("returns 0 if the given dates are the same", () => { 9 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 11 | 12 | let result = fstDate->ReDate.differenceInBusinessDays(sndDate) 13 | 14 | result |> expect |> toEqual(0.) 15 | }) 16 | 17 | test("returns the number of business days between the given dates, excluding weekends", () => { 18 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=10., ()) 19 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 20 | 21 | let result = fstDate->ReDate.differenceInBusinessDays(sndDate) 22 | 23 | result |> expect |> toEqual(6.) 24 | }) 25 | 26 | test("returns a negative number if the time value of the first date is smaller", () => { 27 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 28 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=10., ()) 29 | 30 | let result = fstDate->ReDate.differenceInBusinessDays(sndDate) 31 | 32 | result |> expect |> toEqual(-6.) 33 | }) 34 | 35 | test("returns a correct number when the first date falls on a weekend", () => { 36 | let fstDate = makeWithYMD(~year=2019., ~month=6., ~date=20., ()) 37 | let sndDate = makeWithYMD(~year=2019., ~month=6., ~date=18., ()) 38 | 39 | let result = fstDate->ReDate.differenceInBusinessDays(sndDate) 40 | 41 | result |> expect |> toEqual(2.) 42 | }) 43 | 44 | test("returns a correct number when the second date falls on a weekend", () => { 45 | let fstDate = makeWithYMD(~year=2019., ~month=6., ~date=23., ()) 46 | let sndDate = makeWithYMD(~year=2019., ~month=6., ~date=20., ()) 47 | 48 | let result = fstDate->ReDate.differenceInBusinessDays(sndDate) 49 | 50 | result |> expect |> toEqual(1.) 51 | }) 52 | 53 | test("returns a correct number when both dates fall on a weekend", () => { 54 | let fstDate = makeWithYMD(~year=2019., ~month=6., ~date=28., ()) 55 | let sndDate = makeWithYMD(~year=2019., ~month=6., ~date=20., ()) 56 | 57 | let result = fstDate->ReDate.differenceInBusinessDays(sndDate) 58 | 59 | result |> expect |> toEqual(5.) 60 | }) 61 | }) 62 | -------------------------------------------------------------------------------- /__tests__/differenceInCalendarDays_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInCalendarDays", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of calendar days between the given dates", () => { 9 | let fstDate = makeWithYMD(~year=2019., ~month=0., ~date=1., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 11 | 12 | let result = fstDate->ReDate.differenceInCalendarDays(sndDate) 13 | 14 | result |> expect |> toEqual(365.) 15 | }) 16 | 17 | test("returns a negative number if the time value of the first date is smaller", () => { 18 | let fstDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=19., 23 | ~minutes=30., 24 | ~seconds=22., 25 | (), 26 | ) 27 | let sndDate = makeWithYMDHMS( 28 | ~year=2019., 29 | ~month=0., 30 | ~date=1., 31 | ~hours=8., 32 | ~minutes=45., 33 | ~seconds=15., 34 | (), 35 | ) 36 | 37 | let result = fstDate->ReDate.differenceInCalendarDays(sndDate) 38 | 39 | result |> expect |> toEqual(-365.) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /__tests__/differenceInCalendarISOWeeks_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInCalendarISOWeeks", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of calendar ISO weeks between the given dates", () => { 9 | let fstDate = makeWithYMDHM(~year=2014., ~month=6., ~date=8., ~hours=18., ~minutes=0., ()) 10 | let sndDate = makeWithYMDHM(~year=2014., ~month=5., ~date=29., ~hours=6., ~minutes=0., ()) 11 | 12 | let result = fstDate->ReDate.differenceInCalendarISOWeeks(sndDate) 13 | 14 | result |> expect |> toEqual(2.) 15 | }) 16 | 17 | test("returns a negative number if the time value of the first date is smaller", () => { 18 | let fstDate = makeWithYMDHM(~year=2014., ~month=5., ~date=29., ~hours=6., ~minutes=0., ()) 19 | let sndDate = makeWithYMDHM(~year=2014., ~month=6., ~date=8., ~hours=18., ~minutes=0., ()) 20 | 21 | let result = fstDate->ReDate.differenceInCalendarISOWeeks(sndDate) 22 | 23 | result |> expect |> toEqual(-2.) 24 | }) 25 | 26 | // edge cases 27 | test( 28 | "the difference is less than an ISO week, but the given dates are in different calendar ISO weeks", 29 | () => { 30 | let fstDate = makeWithYMD(~year=2014., ~month=6., ~date=7., ()) 31 | let sndDate = makeWithYMD(~year=2014., ~month=6., ~date=6., ()) 32 | 33 | let result = fstDate->ReDate.differenceInCalendarISOWeeks(sndDate) 34 | 35 | result |> expect |> toEqual(1.) 36 | }, 37 | ) 38 | 39 | test("the same for the swapped dates", () => { 40 | let fstDate = makeWithYMD(~year=2014., ~month=6., ~date=6., ()) 41 | let sndDate = makeWithYMD(~year=2014., ~month=6., ~date=7., ()) 42 | 43 | let result = fstDate->ReDate.differenceInCalendarISOWeeks(sndDate) 44 | 45 | result |> expect |> toEqual(-1.) 46 | }) 47 | 48 | test("the days of weeks of the given dates are the same", () => { 49 | let fstDate = makeWithYMD(~year=2014., ~month=6., ~date=9., ()) 50 | let sndDate = makeWithYMD(~year=2014., ~month=6., ~date=2., ()) 51 | 52 | let result = fstDate->ReDate.differenceInCalendarISOWeeks(sndDate) 53 | 54 | result |> expect |> toEqual(1.) 55 | }) 56 | 57 | test("the given dates are the same", () => { 58 | let fstDate = makeWithYMDHM(~year=2014., ~month=8., ~date=5., ~hours=0., ~minutes=0., ()) 59 | let sndDate = makeWithYMDHM(~year=2014., ~month=8., ~date=5., ~hours=0., ~minutes=0., ()) 60 | 61 | let result = fstDate->ReDate.differenceInCalendarISOWeeks(sndDate) 62 | 63 | result |> expect |> toEqual(0.) 64 | }) 65 | }) 66 | -------------------------------------------------------------------------------- /__tests__/differenceInCalendarMonths_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInCalendarMonths", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of calendar months between the given dates", () => { 9 | let fstDate = makeWithYMD(~year=2019., ~month=5., ~date=1., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=1., ~date=1., ()) 11 | 12 | let result = fstDate->ReDate.differenceInCalendarMonths(sndDate) 13 | 14 | result |> expect |> toEqual(16.) 15 | }) 16 | 17 | test("returns a negative number if the time value of the first date is smaller", () => { 18 | let fstDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=1., 21 | ~date=1., 22 | ~hours=19., 23 | ~minutes=30., 24 | ~seconds=22., 25 | (), 26 | ) 27 | let sndDate = makeWithYMDHMS( 28 | ~year=2019., 29 | ~month=5., 30 | ~date=1., 31 | ~hours=8., 32 | ~minutes=45., 33 | ~seconds=15., 34 | (), 35 | ) 36 | 37 | let result = fstDate->ReDate.differenceInCalendarMonths(sndDate) 38 | 39 | result |> expect |> toEqual(-16.) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /__tests__/differenceInCalendarWeeks_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInWeeks", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of calendar weeks between the given dates", () => { 9 | let fstDate = makeWithYMD(~year=2018., ~month=8., ~date=20., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=7., ~date=7., ()) 11 | 12 | let result = fstDate->ReDate.differenceInCalendarWeeks(sndDate) 13 | 14 | result |> expect |> toEqual(6.) 15 | }) 16 | 17 | test("allows to specify which day is the first day of the week", () => { 18 | let fstDate = makeWithYMD(~year=2018., ~month=6., ~date=15., ()) 19 | let sndDate = makeWithYMD(~year=2018., ~month=5., ~date=20., ()) 20 | let differenceInCalendarWeeks' = ReDate.differenceInCalendarWeeks(~weekStartsOn=Monday) 21 | 22 | let result = fstDate->differenceInCalendarWeeks'(sndDate) 23 | 24 | result |> expect |> toEqual(3.) 25 | }) 26 | 27 | test("returns a negative number if the time value of the first date is smaller", () => { 28 | let fstDate = makeWithYMDHMS( 29 | ~year=2018., 30 | ~month=7., 31 | ~date=7., 32 | ~hours=19., 33 | ~minutes=30., 34 | ~seconds=22., 35 | (), 36 | ) 37 | let sndDate = makeWithYMDHMS( 38 | ~year=2018., 39 | ~month=8., 40 | ~date=20., 41 | ~hours=8., 42 | ~minutes=45., 43 | ~seconds=15., 44 | (), 45 | ) 46 | 47 | let result = fstDate->ReDate.differenceInCalendarWeeks(sndDate) 48 | 49 | result |> expect |> toEqual(-6.) 50 | }) 51 | }) 52 | -------------------------------------------------------------------------------- /__tests__/differenceInCalendarYears_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInCalendarYears", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of calendar years between the given dates", () => { 9 | let fstDate = makeWithYMD(~year=2020., ~month=5., ~date=1., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=1., ~date=1., ()) 11 | 12 | let result = fstDate->ReDate.differenceInCalendarYears(sndDate) 13 | 14 | result |> expect |> toEqual(2.) 15 | }) 16 | 17 | test("returns a negative number if the time value of the first date is smaller", () => { 18 | let fstDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=1., 21 | ~date=1., 22 | ~hours=19., 23 | ~minutes=30., 24 | ~seconds=22., 25 | (), 26 | ) 27 | let sndDate = makeWithYMDHMS( 28 | ~year=2019., 29 | ~month=5., 30 | ~date=1., 31 | ~hours=8., 32 | ~minutes=45., 33 | ~seconds=15., 34 | (), 35 | ) 36 | 37 | let result = fstDate->ReDate.differenceInCalendarYears(sndDate) 38 | 39 | result |> expect |> toEqual(-1.) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /__tests__/differenceInDays_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInDays", () => { 6 | open ExpectJs 7 | 8 | test("returns 0 if the difference is less than a day", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=23., 14 | ~minutes=59., 15 | ~seconds=59., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=0., 23 | ~minutes=0., 24 | ~seconds=0., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.differenceInDays(sndDate) 29 | 30 | result |> expect |> toEqual(0.) 31 | }) 32 | 33 | test("returns 0 if the given dates are the same", () => { 34 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 35 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 36 | 37 | let result = fstDate->ReDate.differenceInDays(sndDate) 38 | 39 | result |> expect |> toEqual(0.) 40 | }) 41 | 42 | test("returns the number of full days between the given dates", () => { 43 | /* https://www.timeanddate.com/date/durationresult.html?y1=2018&m1=1&d1=10&y2=2018&m2=1&d2=2&h1=10&i1=15&s1=55&h2=20&i2=50&s2=10 */ 44 | let fstDate = makeWithYMDHMS( 45 | ~year=2018., 46 | ~month=0., 47 | ~date=10., 48 | ~hours=10., 49 | ~minutes=15., 50 | ~seconds=55., 51 | (), 52 | ) 53 | let sndDate = makeWithYMDHMS( 54 | ~year=2018., 55 | ~month=0., 56 | ~date=2., 57 | ~hours=20., 58 | ~minutes=50., 59 | ~seconds=10., 60 | (), 61 | ) 62 | 63 | let result = fstDate->ReDate.differenceInDays(sndDate) 64 | 65 | result |> expect |> toEqual(7.) 66 | }) 67 | 68 | test("returns a negative number if the time value of the first date is smaller", () => { 69 | let fstDate = makeWithYMDHMS( 70 | ~year=2018., 71 | ~month=0., 72 | ~date=2., 73 | ~hours=20., 74 | ~minutes=50., 75 | ~seconds=10., 76 | (), 77 | ) 78 | let sndDate = makeWithYMDHMS( 79 | ~year=2018., 80 | ~month=0., 81 | ~date=10., 82 | ~hours=10., 83 | ~minutes=15., 84 | ~seconds=55., 85 | (), 86 | ) 87 | 88 | let result = fstDate->ReDate.differenceInDays(sndDate) 89 | 90 | result |> expect |> toEqual(-7.) 91 | }) 92 | }) 93 | -------------------------------------------------------------------------------- /__tests__/differenceInHours_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInHours", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of hours between the given dates", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=19., 14 | ~minutes=40., 15 | ~seconds=15., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=10., 23 | ~minutes=30., 24 | ~seconds=0., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.differenceInHours(sndDate) 29 | 30 | result |> expect |> toEqual(9.) 31 | }) 32 | 33 | test("returns a negative number if the time value of the first date is smaller", () => { 34 | let fstDate = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=10., 39 | ~minutes=30., 40 | ~seconds=0., 41 | (), 42 | ) 43 | let sndDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=1., 47 | ~hours=19., 48 | ~minutes=40., 49 | ~seconds=15., 50 | (), 51 | ) 52 | 53 | let result = fstDate->ReDate.differenceInHours(sndDate) 54 | 55 | result |> expect |> toEqual(-9.) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/differenceInMinutes_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInMinutes", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of seconds between the given dates", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=19., 14 | ~minutes=40., 15 | ~seconds=15., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=19., 23 | ~minutes=30., 24 | ~seconds=0., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.differenceInMinutes(sndDate) 29 | 30 | result |> expect |> toEqual(10.) 31 | }) 32 | 33 | test("returns a negative number if the time value of the first date is smaller", () => { 34 | let fstDate = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=19., 39 | ~minutes=30., 40 | ~seconds=0., 41 | (), 42 | ) 43 | let sndDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=1., 47 | ~hours=19., 48 | ~minutes=40., 49 | ~seconds=15., 50 | (), 51 | ) 52 | 53 | let result = fstDate->ReDate.differenceInMinutes(sndDate) 54 | 55 | result |> expect |> toEqual(-10.) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/differenceInMonths_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInMonths", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "the difference is less than a month, but the given dates are in different calendar months", 10 | () => { 11 | let fstDate = makeWithYMD(~year=2018., ~month=7., ~date=1., ()) 12 | let sndDate = makeWithYMD(~year=2018., ~month=6., ~date=31., ()) 13 | 14 | let result = fstDate->ReDate.differenceInMonths(sndDate) 15 | 16 | result |> expect |> toEqual(0.) 17 | }, 18 | ) 19 | 20 | test("the days of months of the given dates are the same", () => { 21 | let fstDate = makeWithYMD(~year=2018., ~month=8., ~date=1., ()) 22 | let sndDate = makeWithYMD(~year=2018., ~month=7., ~date=1., ()) 23 | 24 | let result = fstDate->ReDate.differenceInMonths(sndDate) 25 | 26 | result |> expect |> toEqual(1.) 27 | }) 28 | 29 | test("the given dates are the same", () => { 30 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 31 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 32 | 33 | let result = fstDate->ReDate.differenceInMonths(sndDate) 34 | 35 | result |> expect |> toEqual(0.) 36 | }) 37 | 38 | test("returns the number of full months between the given dates", () => { 39 | /* https://www.timeanddate.com/date/durationresult.html?y1=2018&m1=1&d1=10&y2=2018&m2=1&d2=2&h1=10&i1=15&s1=55&h2=20&i2=50&s2=10 */ 40 | let fstDate = makeWithYMD(~year=2018., ~month=1., ~date=10., ()) 41 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 42 | 43 | let result = fstDate->ReDate.differenceInMonths(sndDate) 44 | 45 | result |> expect |> toEqual(1.) 46 | }) 47 | 48 | test("returns a negative number if the time value of the first date is smaller", () => { 49 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 50 | let sndDate = makeWithYMD(~year=2018., ~month=1., ~date=10., ()) 51 | 52 | let result = fstDate->ReDate.differenceInMonths(sndDate) 53 | 54 | result |> expect |> toEqual(-1.) 55 | }) 56 | }) 57 | -------------------------------------------------------------------------------- /__tests__/differenceInSeconds_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInSeconds", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of seconds between the given dates", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=19., 14 | ~minutes=40., 15 | ~seconds=15., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=19., 23 | ~minutes=30., 24 | ~seconds=0., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.differenceInSeconds(sndDate) 29 | 30 | result |> expect |> toEqual(615.) 31 | }) 32 | 33 | test("returns a negative number if the time value of the first date is smaller", () => { 34 | let fstDate = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=19., 39 | ~minutes=30., 40 | ~seconds=0., 41 | (), 42 | ) 43 | let sndDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=1., 47 | ~hours=19., 48 | ~minutes=40., 49 | ~seconds=15., 50 | (), 51 | ) 52 | 53 | let result = fstDate->ReDate.differenceInSeconds(sndDate) 54 | 55 | result |> expect |> toEqual(-615.) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/differenceInWeeks_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInWeeks", () => { 6 | open ExpectJs 7 | 8 | test("returns 0 if the difference is less than a week", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=7., 13 | ~hours=23., 14 | ~minutes=59., 15 | ~seconds=59., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=0., 23 | ~minutes=0., 24 | ~seconds=0., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.differenceInWeeks(sndDate) 29 | 30 | result |> expect |> toEqual(0.) 31 | }) 32 | 33 | test("returns 0 if the given dates are the same", () => { 34 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 35 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 36 | 37 | let result = fstDate->ReDate.differenceInWeeks(sndDate) 38 | 39 | result |> expect |> toEqual(0.) 40 | }) 41 | 42 | test("returns the number of full weeks between the given dates", () => { 43 | /* https://www.timeanddate.com/date/durationresult.html?y1=2018&m1=1&d1=10&y2=2018&m2=1&d2=2&h1=10&i1=15&s1=55&h2=20&i2=50&s2=10 */ 44 | let fstDate = makeWithYMDHMS( 45 | ~year=2018., 46 | ~month=0., 47 | ~date=10., 48 | ~hours=10., 49 | ~minutes=15., 50 | ~seconds=55., 51 | (), 52 | ) 53 | let sndDate = makeWithYMDHMS( 54 | ~year=2018., 55 | ~month=0., 56 | ~date=2., 57 | ~hours=20., 58 | ~minutes=50., 59 | ~seconds=10., 60 | (), 61 | ) 62 | 63 | let result = fstDate->ReDate.differenceInWeeks(sndDate) 64 | 65 | result |> expect |> toEqual(1.) 66 | }) 67 | 68 | test("returns a negative number if the time value of the first date is smaller", () => { 69 | let fstDate = makeWithYMDHMS( 70 | ~year=2018., 71 | ~month=0., 72 | ~date=2., 73 | ~hours=20., 74 | ~minutes=50., 75 | ~seconds=10., 76 | (), 77 | ) 78 | let sndDate = makeWithYMDHMS( 79 | ~year=2018., 80 | ~month=0., 81 | ~date=10., 82 | ~hours=10., 83 | ~minutes=15., 84 | ~seconds=55., 85 | (), 86 | ) 87 | 88 | let result = fstDate->ReDate.differenceInWeeks(sndDate) 89 | 90 | result |> expect |> toEqual(-1.) 91 | }) 92 | }) 93 | -------------------------------------------------------------------------------- /__tests__/differenceInYears_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("differenceInYears", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "the difference is less than a year, but the given dates are in different calendar years", 10 | () => { 11 | let fstDate = makeWithYMD(~year=2019., ~month=0., ~date=1., ()) 12 | let sndDate = makeWithYMD(~year=2018., ~month=1., ~date=1., ()) 13 | 14 | let result = fstDate->ReDate.differenceInYears(sndDate) 15 | 16 | result |> expect |> toEqual(0.) 17 | }, 18 | ) 19 | 20 | test("the days and months of the given dates are the same", () => { 21 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 22 | let sndDate = makeWithYMD(~year=2016., ~month=0., ~date=1., ()) 23 | 24 | let result = fstDate->ReDate.differenceInYears(sndDate) 25 | 26 | result |> expect |> toEqual(2.) 27 | }) 28 | 29 | test("the given dates are the same", () => { 30 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 31 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 32 | 33 | let result = fstDate->ReDate.differenceInYears(sndDate) 34 | 35 | result |> expect |> toEqual(0.) 36 | }) 37 | 38 | test("returns the number of full years between the given dates", () => { 39 | let fstDate = makeWithYMD(~year=2018., ~month=6., ~date=18., ()) 40 | let sndDate = makeWithYMD(~year=2015., ~month=0., ~date=14., ()) 41 | 42 | let result = fstDate->ReDate.differenceInYears(sndDate) 43 | 44 | result |> expect |> toEqual(3.) 45 | }) 46 | 47 | test("returns a negative number if the time value of the first date is smaller", () => { 48 | let fstDate = makeWithYMD(~year=2015., ~month=0., ~date=14., ()) 49 | let sndDate = makeWithYMD(~year=2018., ~month=6., ~date=18., ()) 50 | 51 | let result = fstDate->ReDate.differenceInYears(sndDate) 52 | 53 | result |> expect |> toEqual(-3.) 54 | }) 55 | }) 56 | -------------------------------------------------------------------------------- /__tests__/eachDayOfInterval_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("eachDayOfInterval", () => { 6 | open ExpectJs 7 | 8 | let interval: ReDate.interval = { 9 | start: makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=19., 14 | ~minutes=30., 15 | ~seconds=22., 16 | (), 17 | ), 18 | end_: makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=5., 22 | ~hours=8., 23 | ~minutes=45., 24 | ~seconds=15., 25 | (), 26 | ), 27 | } 28 | 29 | test( 30 | "returns a list with starts of days from the day of the start date to the day of the end date", 31 | () => { 32 | let a = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 33 | let b = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 34 | let c = makeWithYMD(~year=2018., ~month=0., ~date=3., ()) 35 | let d = makeWithYMD(~year=2018., ~month=0., ~date=4., ()) 36 | let e = makeWithYMD(~year=2018., ~month=0., ~date=5., ()) 37 | 38 | let expectedDates = [a, b, c, d, e] 39 | let result = ReDate.eachDayOfInterval(interval) 40 | 41 | Belt.Array.eq(result, expectedDates, (a, b) => getTime(a) == getTime(b)) 42 | |> expect 43 | |> toBeTruthy 44 | }, 45 | ) 46 | }) 47 | -------------------------------------------------------------------------------- /__tests__/endOfDay_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("endOfDay", () => { 6 | open ExpectJs 7 | 8 | test("returns the date with the time set to 23:59:59.999", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=16., 14 | ~minutes=50., 15 | ~seconds=12., 16 | (), 17 | ) 18 | let expectedDate = 19 | setHoursMSMs( 20 | makeWithYMD(~year=2018., ~month=0., ~date=1., ()), 21 | ~hours=23., 22 | ~minutes=59., 23 | ~seconds=59., 24 | ~milliseconds=999., 25 | (), 26 | ) |> fromFloat 27 | 28 | let result = date->ReDate.endOfDay 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | }) 33 | -------------------------------------------------------------------------------- /__tests__/endOfHour_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("endOfSecond", () => { 6 | open ExpectJs 7 | 8 | test("returns the date with the time set to the last millisecond before an hour ends", () => { 9 | let date = 10 | setMilliseconds( 11 | makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=0., 14 | ~date=1., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=10., 18 | (), 19 | ), 20 | 423., 21 | ) |> fromFloat 22 | let expectedDate = 23 | setMilliseconds( 24 | makeWithYMDHMS( 25 | ~year=2018., 26 | ~month=0., 27 | ~date=1., 28 | ~hours=16., 29 | ~minutes=59., 30 | ~seconds=59., 31 | (), 32 | ), 33 | 999., 34 | ) |> fromFloat 35 | 36 | let result = date->ReDate.endOfHour 37 | 38 | result |> expect |> toEqual(expectedDate) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /__tests__/endOfISOWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("endOfISOWeek", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 23:59:59:999 and the date set to the last day of an ISO week", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2014., 13 | ~month=8., 14 | ~date=2., 15 | ~hours=11., 16 | ~minutes=55., 17 | ~seconds=0., 18 | (), 19 | ) 20 | 21 | let expectedDate = 22 | setHoursMSMs( 23 | makeWithYMD(~year=2014., ~month=8., ~date=7., ()), 24 | ~hours=23., 25 | ~minutes=59., 26 | ~seconds=59., 27 | ~milliseconds=999., 28 | (), 29 | ) |> fromFloat 30 | 31 | let result = date->ReDate.endOfISOWeek 32 | 33 | result |> expect |> toEqual(expectedDate) 34 | }, 35 | ) 36 | }) 37 | -------------------------------------------------------------------------------- /__tests__/endOfMinute_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("endOfMinute", () => { 6 | open ExpectJs 7 | 8 | test("returns the date with the time set to the last millisecond of an minute", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=8., 12 | ~date=10., 13 | ~hours=8., 14 | ~minutes=20., 15 | ~seconds=35., 16 | (), 17 | ) 18 | let expectedDate = 19 | setMilliseconds( 20 | makeWithYMDHMS( 21 | ~year=2018., 22 | ~month=8., 23 | ~date=10., 24 | ~hours=8., 25 | ~minutes=20., 26 | ~seconds=59., 27 | (), 28 | ), 29 | 999., 30 | ) |> fromFloat 31 | 32 | let result = date->ReDate.endOfMinute 33 | 34 | result |> expect |> toEqual(expectedDate) 35 | }) 36 | }) 37 | -------------------------------------------------------------------------------- /__tests__/endOfMonth_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("endOfMonth", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 23:59:59.999 and the date set to the last day of a month", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=0., 14 | ~date=24., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=12., 18 | (), 19 | ) 20 | let expectedDate = 21 | setHoursMSMs( 22 | makeWithYMD(~year=2018., ~month=0., ~date=31., ()), 23 | ~hours=23., 24 | ~minutes=59., 25 | ~seconds=59., 26 | ~milliseconds=999., 27 | (), 28 | ) |> fromFloat 29 | 30 | let result = date->ReDate.endOfMonth 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | }) 36 | -------------------------------------------------------------------------------- /__tests__/endOfSecond_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("endOfSecond", () => { 6 | open ExpectJs 7 | 8 | test("returns the date with the time set to the last millisecond before a second ends", () => { 9 | let date = 10 | setMilliseconds( 11 | makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=0., 14 | ~date=1., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=10., 18 | (), 19 | ), 20 | 423., 21 | ) |> fromFloat 22 | let expectedDate = 23 | setMilliseconds( 24 | makeWithYMDHMS( 25 | ~year=2018., 26 | ~month=0., 27 | ~date=1., 28 | ~hours=16., 29 | ~minutes=50., 30 | ~seconds=10., 31 | (), 32 | ), 33 | 999., 34 | ) |> fromFloat 35 | 36 | let result = date->ReDate.endOfSecond 37 | 38 | result |> expect |> toEqual(expectedDate) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /__tests__/endOfWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("endOfWeek", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 23:59:59:999 and the date set to the last day of a week", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=0., 14 | ~date=12., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=12., 18 | (), 19 | ) 20 | let expectedDate = 21 | setHoursMSMs( 22 | makeWithYMD(~year=2018., ~month=0., ~date=13., ()), 23 | ~hours=23., 24 | ~minutes=59., 25 | ~seconds=59., 26 | ~milliseconds=999., 27 | (), 28 | ) |> fromFloat 29 | 30 | let result = date->ReDate.endOfWeek 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | 36 | test("allows to specify which day is the first day of the week", () => { 37 | let date = makeWithYMDHMS( 38 | ~year=2018., 39 | ~month=0., 40 | ~date=12., 41 | ~hours=16., 42 | ~minutes=50., 43 | ~seconds=12., 44 | (), 45 | ) 46 | let expectedDate = 47 | setHoursMSMs( 48 | makeWithYMD(~year=2018., ~month=0., ~date=14., ()), 49 | ~hours=23., 50 | ~minutes=59., 51 | ~seconds=59., 52 | ~milliseconds=999., 53 | (), 54 | ) |> fromFloat 55 | let endOfWeek = ReDate.endOfWeek(~weekStartsOn=Monday) 56 | 57 | let result = date->endOfWeek 58 | 59 | result |> expect |> toEqual(expectedDate) 60 | }) 61 | }) 62 | -------------------------------------------------------------------------------- /__tests__/endOfYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("endOfYear", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 23:59:59.999 and the date set to the last day of a year", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=8., 14 | ~date=10., 15 | ~hours=19., 16 | ~minutes=6., 17 | ~seconds=6., 18 | (), 19 | ) 20 | let expectedDate = 21 | setHoursMSMs( 22 | makeWithYMD(~year=2018., ~month=11., ~date=31., ()), 23 | ~hours=23., 24 | ~minutes=59., 25 | ~seconds=59., 26 | ~milliseconds=999., 27 | (), 28 | ) |> fromFloat 29 | 30 | let result = date->ReDate.endOfYear 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | }) 36 | -------------------------------------------------------------------------------- /__tests__/getDay.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getDay", () => { 6 | open ExpectJs 7 | 8 | test("returns the day of the week of the given date", () => { 9 | let date = makeWithYMD(~year=2021., ~month=11., ~date=10., ()) 10 | 11 | let result = date->ReDate.getDay 12 | 13 | result |> expect |> toEqual(ReDate.Friday) 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /__tests__/getDayOfYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getDayOfYear", () => { 6 | open ExpectJs 7 | 8 | test("returns the day of the year of the given date", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=7., 12 | ~date=23., 13 | ~hours=16., 14 | ~minutes=50., 15 | ~seconds=12., 16 | (), 17 | ) 18 | 19 | /* https://asd.gsfc.nasa.gov/Craig.Markwardt/doy2018.html */ 20 | let result = date->ReDate.getDayOfYear 21 | 22 | result |> expect |> toEqual(235.) 23 | }) 24 | }) 25 | -------------------------------------------------------------------------------- /__tests__/getDaysInMonth_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getDaysInMonth", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of days in the month of the given date", () => { 9 | let date = makeWithYMD(~year=2018., ~month=10., ~date=10., ()) 10 | 11 | let result = date->ReDate.getDaysInMonth 12 | 13 | result |> expect |> toEqual(30.) 14 | }) 15 | 16 | test("works for the February of a leap year", () => { 17 | let date = makeWithYMD(~year=2004., ~month=1., ~date=10., ()) 18 | 19 | let result = date->ReDate.getDaysInMonth 20 | 21 | result |> expect |> toEqual(29.) 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/getDaysInYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getDaysInYear", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of days in the year of the given date", () => { 9 | let date = makeWithYMD(~year=2018., ~month=10., ~date=10., ()) 10 | 11 | let result = date->ReDate.getDaysInYear 12 | 13 | result |> expect |> toEqual(365) 14 | }) 15 | 16 | test("works on a leap year", () => { 17 | let date = makeWithYMD(~year=2020., ~month=1., ~date=10., ()) 18 | 19 | let result = date->ReDate.getDaysInYear 20 | 21 | result |> expect |> toEqual(366) 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/getISOWeekYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getISOWeekYear", () => { 6 | open ExpectJs 7 | 8 | test("returns the ISO week-numbering year of the given date", () => { 9 | let date = makeWithYMD(~year=2007., ~month=11., ~date=31., ()) 10 | 11 | let result = date->ReDate.getISOWeekYear 12 | 13 | result |> expect |> toEqual(2008.) 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /__tests__/getISOWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getISOWeek", () => { 6 | open ExpectJs 7 | 8 | test("returns the ISO week of the given date", () => { 9 | let date = makeWithYMD(~year=2005., ~month=0., ~date=2., ()) 10 | 11 | let result = date->ReDate.getISOWeek 12 | 13 | result |> expect |> toEqual(53.) 14 | }) 15 | 16 | test("returns the ISO week at 1 January 2016", () => { 17 | let date = makeWithYMD(~year=2016., ~month=0., ~date=1., ()) 18 | 19 | let result = date->ReDate.getISOWeek 20 | 21 | result |> expect |> toEqual(53.) 22 | }) 23 | 24 | test("returns the ISO week at 1 May 2016", () => { 25 | let date = makeWithYMD(~year=2016., ~month=4., ~date=1., ()) 26 | 27 | let result = date->ReDate.getISOWeek 28 | 29 | result |> expect |> toEqual(17.) 30 | }) 31 | 32 | test("returns the ISO week at 2 May 2016", () => { 33 | let date = makeWithYMD(~year=2016., ~month=4., ~date=2., ()) 34 | 35 | let result = date->ReDate.getISOWeek 36 | 37 | result |> expect |> toEqual(18.) 38 | }) 39 | 40 | test("returns the ISO week at 31 May 2016", () => { 41 | let date = makeWithYMD(~year=2016., ~month=4., ~date=31., ()) 42 | 43 | let result = date->ReDate.getISOWeek 44 | 45 | result |> expect |> toEqual(22.) 46 | }) 47 | }) 48 | -------------------------------------------------------------------------------- /__tests__/getOverlappingDaysInIntervals_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getOverlappingDaysInIntervals", () => { 6 | open ExpectJs 7 | open ReDate 8 | 9 | let interval = { 10 | start: makeWithYMD(~year=2018., ~month=3., ~date=1., ()), 11 | end_: makeWithYMD(~year=2018., ~month=4., ~date=10., ()), 12 | } 13 | 14 | test("returns the correct value for an interval included within another interval", () => { 15 | let includedInterval = { 16 | start: makeWithYMD(~year=2018., ~month=3., ~date=5., ()), 17 | end_: makeWithYMD(~year=2018., ~month=3., ~date=15., ()), 18 | } 19 | 20 | let result = interval->ReDate.getOverlappingDaysInIntervals(includedInterval) 21 | 22 | result |> expect |> toEqual(10.) 23 | }) 24 | 25 | test("returns the correct value for an interval including another interval", () => { 26 | let includingInterval = { 27 | start: makeWithYMD(~year=2018., ~month=3., ~date=5., ()), 28 | end_: makeWithYMD(~year=2018., ~month=3., ~date=10., ()), 29 | } 30 | 31 | let result = includingInterval->ReDate.getOverlappingDaysInIntervals(interval) 32 | 33 | result |> expect |> toEqual(5.) 34 | }) 35 | 36 | test("returns 0 for a valid non overlapping interval before another interval", () => { 37 | let earlierInterval = { 38 | start: makeWithYMD(~year=2018., ~month=2., ~date=20., ()), 39 | end_: makeWithYMD(~year=2018., ~month=2., ~date=30., ()), 40 | } 41 | 42 | let result = earlierInterval->ReDate.getOverlappingDaysInIntervals(interval) 43 | 44 | result |> expect |> toEqual(0.) 45 | }) 46 | 47 | test("returns 0 for a valid non overlapping interval after another interval", () => { 48 | let laterInterval = { 49 | start: makeWithYMD(~year=2018., ~month=4., ~date=11., ()), 50 | end_: makeWithYMD(~year=2018., ~month=4., ~date=30., ()), 51 | } 52 | 53 | let result = laterInterval->ReDate.getOverlappingDaysInIntervals(interval) 54 | 55 | result |> expect |> toEqual(0.) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/getWeekOfMonth_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getWeekOfMonth", () => { 6 | open ExpectJs 7 | 8 | test("returns the week of the month of the given date #1", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | 11 | let result = date->ReDate.getWeekOfMonth 12 | 13 | result |> expect |> toEqual(1.) 14 | }) 15 | 16 | test("returns the week of the month of the given date #2", () => { 17 | let date = makeWithYMD(~year=2018., ~month=10., ~date=14., ()) 18 | 19 | let result = date->ReDate.getWeekOfMonth 20 | 21 | result |> expect |> toEqual(3.) 22 | }) 23 | 24 | test("returns the week of the month of the given date #3", () => { 25 | let date = makeWithYMD(~year=2018., ~month=10., ~date=25., ()) 26 | 27 | let result = date->ReDate.getWeekOfMonth 28 | 29 | result |> expect |> toEqual(5.) 30 | }) 31 | 32 | test("allows to specify which day is the first day of the week #1", () => { 33 | let date = makeWithYMD(~year=2018., ~month=10., ~date=25., ()) 34 | let getWeekOfMonth' = ReDate.getWeekOfMonth(~weekStartsOn=Monday) 35 | 36 | let result = date->getWeekOfMonth' 37 | 38 | result |> expect |> toEqual(4.) 39 | }) 40 | 41 | test("allows to specify which day is the first day of the week #2", () => { 42 | let date = makeWithYMD(~year=2018., ~month=10., ~date=23., ()) 43 | let getWeekOfMonth = ReDate.getWeekOfMonth(~weekStartsOn=Saturday) 44 | 45 | let result = date->getWeekOfMonth 46 | 47 | result |> expect |> toEqual(4.) 48 | }) 49 | 50 | test("allows to specify which day is the first day of the week #3", () => { 51 | let date = makeWithYMD(~year=2018., ~month=10., ~date=2., ()) 52 | let getWeekOfMonth = ReDate.getWeekOfMonth(~weekStartsOn=Friday) 53 | 54 | let result = date->getWeekOfMonth 55 | 56 | result |> expect |> toEqual(2.) 57 | }) 58 | 59 | test("allows to specify which day is the first day of the week #4", () => { 60 | let date = makeWithYMD(~year=2018., ~month=10., ~date=1., ()) 61 | let getWeekOfMonth = ReDate.getWeekOfMonth(~weekStartsOn=Friday) 62 | 63 | let result = date->getWeekOfMonth 64 | 65 | result |> expect |> toEqual(1.) 66 | }) 67 | }) 68 | -------------------------------------------------------------------------------- /__tests__/getWeekYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getWeekYear", () => { 6 | open ExpectJs 7 | 8 | test("returns the local week-numbering year of the given date", () => { 9 | let date = makeWithYMD(~year=2019., ~month=11., ~date=29., ()) 10 | 11 | let result = date->ReDate.getWeekYear 12 | 13 | result |> expect |> toEqual(2020.) 14 | }) 15 | 16 | test("allows to specify which day is the first day of the week", () => { 17 | let date = makeWithYMD(~year=2019., ~month=11., ~date=23., ()) 18 | let getWeekYear = ReDate.getWeekYear(~weekStartsOn=Monday) 19 | 20 | let result = date->getWeekYear 21 | 22 | result |> expect |> toEqual(2019.) 23 | }) 24 | }) 25 | -------------------------------------------------------------------------------- /__tests__/getWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getWeek", () => { 6 | open ExpectJs 7 | 8 | test("returns the local week of year of the given date", () => { 9 | let date = makeWithYMD(~year=2020., ~month=0., ~date=5., ()) 10 | 11 | let result = date->ReDate.getWeek 12 | 13 | result |> expect |> toEqual(2.) 14 | }) 15 | 16 | test("allows to specify which day is the first day of the week", () => { 17 | let date = makeWithYMD(~year=2020., ~month=0., ~date=5., ()) 18 | let getWeek = ReDate.getWeek(~weekStartsOn=Monday) 19 | 20 | let result = date->getWeek 21 | 22 | result |> expect |> toEqual(1.) 23 | }) 24 | }) 25 | -------------------------------------------------------------------------------- /__tests__/getWeeksInMonth_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("getWeeksInMonth", () => { 6 | open ExpectJs 7 | 8 | test("returns the number of calendar weeks the month in the given date spans", () => { 9 | let date = makeWithYMD(~year=2018., ~month=10., ~date=1., ()) 10 | 11 | let result = date->ReDate.getWeeksInMonth 12 | 13 | result |> expect |> toEqual(5.) 14 | }) 15 | 16 | test("allows to specify which day is the first day of the week", () => { 17 | let date = makeWithYMD(~year=2018., ~month=10., ~date=14., ()) 18 | let getWeeksInMonth = ReDate.getWeeksInMonth(~weekStartsOn=Friday) 19 | 20 | let result = date->getWeeksInMonth 21 | 22 | result |> expect |> toEqual(6.) 23 | }) 24 | }) 25 | -------------------------------------------------------------------------------- /__tests__/isAfter_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isAfter", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the first date is after the second one", () => { 9 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 11 | 12 | let result = fstDate->ReDate.isAfter(sndDate) 13 | 14 | result |> expect |> toBeTruthy 15 | }) 16 | 17 | test("returns false if the first date is after the second one", () => { 18 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 19 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 20 | 21 | let result = fstDate->ReDate.isAfter(sndDate) 22 | 23 | result |> expect |> toBeFalsy 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/isBefore_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isBefore", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the first date is before the second one", () => { 9 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 11 | 12 | let result = fstDate->ReDate.isBefore(sndDate) 13 | 14 | result |> expect |> toBeTruthy 15 | }) 16 | 17 | test("returns false if the first date is before the second one", () => { 18 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 19 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 20 | 21 | let result = fstDate->ReDate.isBefore(sndDate) 22 | 23 | result |> expect |> toBeFalsy 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/isEqual_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isEqual", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given dates are equal", () => { 9 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 11 | 12 | let result = fstDate->ReDate.isEqual(sndDate) 13 | 14 | result |> expect |> toBeTruthy 15 | }) 16 | 17 | test("returns false if the given dates are not equal", () => { 18 | let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 19 | let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 20 | 21 | let result = fstDate->ReDate.isEqual(sndDate) 22 | 23 | result |> expect |> toBeFalsy 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/isFirstDayOfMonth_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isFirstDayOfMonth", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is in the last day of month", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | 11 | let result = date->ReDate.isFirstDayOfMonth 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not in the last day of month", () => { 17 | let date = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 18 | 19 | let result = date->ReDate.isFirstDayOfMonth 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isFriday_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isFriday", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is Friday", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=12., ()) 10 | 11 | let result = date->ReDate.isFriday 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not Friday", () => { 17 | let date = makeWithYMD(~year=2018., ~month=0., ~date=13., ()) 18 | 19 | let result = date->ReDate.isFriday 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isFuture_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isFuture", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is future one", () => { 9 | let date = makeWithYMD(~year=2030., ~month=0., ~date=1., ()) 10 | 11 | let result = date->ReDate.isFuture 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not future one", () => { 17 | let date = makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 18 | 19 | let result = date->ReDate.isFuture 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | 24 | test("returns false if the given date is current time", () => { 25 | let date = make() 26 | 27 | let result = date->ReDate.isFuture 28 | 29 | result |> expect |> toBeFalsy 30 | }) 31 | }) 32 | -------------------------------------------------------------------------------- /__tests__/isLastDayOfMonth_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isLastDayOfMonth", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is in the last day of month", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=31., ()) 10 | 11 | let result = date->ReDate.isLastDayOfMonth 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not in the last day of month", () => { 17 | let date = makeWithYMD(~year=2018., ~month=0., ~date=30., ()) 18 | 19 | let result = date->ReDate.isLastDayOfMonth 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isLeapYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isLeapYear", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is a leap year", () => { 9 | let date = makeWithYMD(~year=2020., ~month=8., ~date=10., ()) 10 | 11 | let result = date->ReDate.isLeapYear 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date isn't a leap year", () => { 17 | let date = makeWithYMD(~year=2018., ~month=8., ~date=10., ()) 18 | 19 | let result = date->ReDate.isLeapYear 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isMonday_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isMonday", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is Monday", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=8., ()) 10 | 11 | let result = date->ReDate.isMonday 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not Monday", () => { 17 | let date = makeWithYMD(~year=2018., ~month=0., ~date=9., ()) 18 | 19 | let result = date->ReDate.isMonday 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isPast_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isPast", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is future one", () => { 9 | let date = makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 10 | 11 | let result = date->ReDate.isPast 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not future one", () => { 17 | let date = makeWithYMD(~year=2030., ~month=0., ~date=1., ()) 18 | 19 | let result = date->ReDate.isPast 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | 24 | test("returns false if the given date is current time", () => { 25 | let date = make() 26 | 27 | let result = date->ReDate.isPast 28 | 29 | result |> expect |> toBeFalsy 30 | }) 31 | }) 32 | -------------------------------------------------------------------------------- /__tests__/isSameDay_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isSameDay", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given dates have the same day", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=16., 14 | ~minutes=50., 15 | ~seconds=12., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=10., 23 | ~minutes=15., 24 | ~seconds=55., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.isSameDay(sndDate) 29 | 30 | result |> expect |> toBeTruthy 31 | }) 32 | 33 | test("returns false if the given dates have different days", () => { 34 | let fstDate = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=23., 39 | ~minutes=59., 40 | ~seconds=59., 41 | (), 42 | ) 43 | let sndDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=2., 47 | ~hours=0., 48 | ~minutes=0., 49 | ~seconds=1., 50 | (), 51 | ) 52 | 53 | let result = fstDate->ReDate.isSameDay(sndDate) 54 | 55 | result |> expect |> toBeFalsy 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/isSameHour_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isSameHour", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given dates have the same hour", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=16., 14 | ~minutes=50., 15 | ~seconds=10., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=16., 23 | ~minutes=0., 24 | ~seconds=0., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.isSameHour(sndDate) 29 | 30 | result |> expect |> toBeTruthy 31 | }) 32 | 33 | test("returns false if the given dates have different hours", () => { 34 | let fstDate = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=23., 39 | ~minutes=0., 40 | ~seconds=0., 41 | (), 42 | ) 43 | let sndDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=1., 47 | ~hours=22., 48 | ~minutes=59., 49 | ~seconds=59., 50 | (), 51 | ) 52 | 53 | let result = fstDate->ReDate.isSameHour(sndDate) 54 | 55 | result |> expect |> toBeFalsy 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/isSameISOWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isSameISOWeek", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given dates have the same ISO week", () => { 9 | let fstDate = makeWithYMD(~year=2014., ~month=8., ~date=1., ()) 10 | let sndDate = makeWithYMD(~year=2014., ~month=8., ~date=7., ()) 11 | 12 | let result = sndDate->ReDate.isSameISOWeek(fstDate) 13 | 14 | result |> expect |> toEqual(true) 15 | }) 16 | 17 | test("returns false if the given dates have different ISO weeks", () => { 18 | let fstDate = makeWithYMD(~year=2014., ~month=8., ~date=1., ()) 19 | let sndDate = makeWithYMD(~year=2014., ~month=8., ~date=14., ()) 20 | 21 | let result = sndDate->ReDate.isSameISOWeek(fstDate) 22 | 23 | result |> expect |> toEqual(false) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/isSameMinute_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isSameMinute", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given dates have the same minute", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=8., 12 | ~date=10., 13 | ~hours=19., 14 | ~minutes=6., 15 | ~seconds=10., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=8., 21 | ~date=10., 22 | ~hours=19., 23 | ~minutes=6., 24 | ~seconds=35., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.isSameMinute(sndDate) 29 | 30 | result |> expect |> toBeTruthy 31 | }) 32 | 33 | test("returns false if the given dates have different minutes", () => { 34 | let fstDate = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=8., 37 | ~date=10., 38 | ~hours=8., 39 | ~minutes=0., 40 | ~seconds=0., 41 | (), 42 | ) 43 | let sndDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=8., 46 | ~date=10., 47 | ~hours=8., 48 | ~minutes=10., 49 | ~seconds=15., 50 | (), 51 | ) 52 | 53 | let result = fstDate->ReDate.isSameMinute(sndDate) 54 | 55 | result |> expect |> toBeFalsy 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/isSameMonth_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isSameMonth", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given dates have the same month (and year)", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=16., 14 | ~minutes=50., 15 | ~seconds=12., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=24., 22 | ~hours=10., 23 | ~minutes=15., 24 | ~seconds=55., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.isSameMonth(sndDate) 29 | 30 | result |> expect |> toBeTruthy 31 | }) 32 | 33 | test("returns false if the given dates have different months", () => { 34 | let fstDate = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=23., 39 | ~minutes=59., 40 | ~seconds=59., 41 | (), 42 | ) 43 | let sndDate = makeWithYMDHMS( 44 | ~year=2019., 45 | ~month=0., 46 | ~date=24., 47 | ~hours=0., 48 | ~minutes=0., 49 | ~seconds=1., 50 | (), 51 | ) 52 | 53 | let result = fstDate->ReDate.isSameMonth(sndDate) 54 | 55 | result |> expect |> toBeFalsy 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/isSameSecond_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isSameSecond", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given dates have the same second", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=16., 14 | ~minutes=50., 15 | ~seconds=10., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=16., 23 | ~minutes=50., 24 | ~seconds=10., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.isSameSecond(sndDate) 29 | 30 | result |> expect |> toBeTruthy 31 | }) 32 | 33 | test("returns false if the given dates have different seconds", () => { 34 | let fstDate = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=23., 39 | ~minutes=59., 40 | ~seconds=59., 41 | (), 42 | ) 43 | let sndDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=1., 47 | ~hours=23., 48 | ~minutes=59., 49 | ~seconds=58., 50 | (), 51 | ) 52 | 53 | let result = fstDate->ReDate.isSameSecond(sndDate) 54 | 55 | result |> expect |> toBeFalsy 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/isSameWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isSameWeek", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given dates have the same week", () => { 9 | let fstDate = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=16., 14 | ~minutes=50., 15 | ~seconds=12., 16 | (), 17 | ) 18 | let sndDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=5., 22 | ~hours=10., 23 | ~minutes=15., 24 | ~seconds=55., 25 | (), 26 | ) 27 | 28 | let result = fstDate->ReDate.isSameWeek(sndDate) 29 | 30 | result |> expect |> toBeTruthy 31 | }) 32 | 33 | test("returns false if the given dates have different weeks", () => { 34 | let fstDate = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=6., 38 | ~hours=23., 39 | ~minutes=59., 40 | ~seconds=59., 41 | (), 42 | ) 43 | let sndDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=7., 47 | ~hours=0., 48 | ~minutes=0., 49 | ~seconds=0., 50 | (), 51 | ) 52 | 53 | let result = fstDate->ReDate.isSameWeek(sndDate) 54 | 55 | result |> expect |> toBeFalsy 56 | }) 57 | 58 | test("allows to specify which day is the first day of the week", () => { 59 | let fstDate = makeWithYMDHMS( 60 | ~year=2018., 61 | ~month=0., 62 | ~date=6., 63 | ~hours=23., 64 | ~minutes=59., 65 | ~seconds=59., 66 | (), 67 | ) 68 | let sndDate = makeWithYMDHMS( 69 | ~year=2018., 70 | ~month=0., 71 | ~date=7., 72 | ~hours=0., 73 | ~minutes=0., 74 | ~seconds=0., 75 | (), 76 | ) 77 | let isSameWeek = ReDate.isSameWeek(~weekStartsOn=Monday) 78 | 79 | let result = fstDate->isSameWeek(sndDate) 80 | 81 | result |> expect |> toBeTruthy 82 | }) 83 | }) 84 | -------------------------------------------------------------------------------- /__tests__/isSameYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isSameYear", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given dates have the same year", () => { 9 | let fstDate = makeWithYMD(~year=2018., ~month=8., ~date=10., ()) 10 | let sndDate = makeWithYMD(~year=2018., ~month=6., ~date=20., ()) 11 | 12 | let result = fstDate->ReDate.isSameYear(sndDate) 13 | 14 | result |> expect |> toBeTruthy 15 | }) 16 | 17 | test("returns false if the given dates have different years", () => { 18 | let fstDate = makeWithYMD(~year=2018., ~month=8., ~date=10., ()) 19 | let sndDate = makeWithYMD(~year=2015., ~month=6., ~date=20., ()) 20 | 21 | let result = fstDate->ReDate.isSameYear(sndDate) 22 | 23 | result |> expect |> toBeFalsy 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/isSaturday_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isSaturday", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is Saturday", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=13., ()) 10 | 11 | let result = date->ReDate.isSaturday 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not Saturday", () => { 17 | let date = makeWithYMD(~year=2018., ~month=0., ~date=14., ()) 18 | 19 | let result = date->ReDate.isSaturday 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isSunday_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isSunday", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is Sunday", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=7., ()) 10 | 11 | let result = date->ReDate.isSunday 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not Sunday", () => { 17 | let date = makeWithYMD(~year=2018., ~month=0., ~date=8., ()) 18 | 19 | let result = date->ReDate.isSunday 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isThisISOWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isThisISOWeek", () => { 6 | open ExpectJs 7 | // HACK: 8 | // https://blog.blakesimpson.co.uk/page.php?id=98&title=how-to-stub-date-in-jest-tests-building-a-stubdate-helper 9 | // https://github.com/facebook/jest/issues/2234#issuecomment-384884729 10 | // alternative solution: https://github.com/mikaello/rescript-jest-date-mock 11 | 12 | let stubDate: Js.Date.t => unit = %raw(` 13 | fixedDate => { 14 | let RealDate; 15 | 16 | beforeAll(() => { 17 | RealDate = Date; 18 | 19 | Date = class extends Date { 20 | constructor(...theArgs) { 21 | if (theArgs.length) { 22 | return new RealDate(...theArgs); 23 | } else { 24 | return new RealDate(fixedDate); 25 | } 26 | } 27 | }; 28 | }); 29 | 30 | afterAll(() => { 31 | Date = RealDate; 32 | }); 33 | } 34 | `) 35 | 36 | stubDate(makeWithYMDH(~year=2014., ~month=8., ~date=25., ~hours=12., ())) 37 | 38 | test("returns true if the given date and the current date have the same ISO week", () => { 39 | let date = makeWithYMD(~year=2014., ~month=8., ~date=22., ()) 40 | 41 | let result = date->ReDate.isThisISOWeek 42 | 43 | result |> expect |> toBeTruthy 44 | }) 45 | 46 | test("returns false if the given date and the current date have different ISO weeks", () => { 47 | let date = makeWithYMD(~year=2014., ~month=8., ~date=21., ()) 48 | 49 | let result = date->ReDate.isThisISOWeek 50 | 51 | result |> expect |> toBeFalsy 52 | }) 53 | }) 54 | -------------------------------------------------------------------------------- /__tests__/isThursday_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isThursday", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is Thursday", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=11., ()) 10 | 11 | let result = date->ReDate.isThursday 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not Thursday", () => { 17 | let date = makeWithYMD(~year=2018., ~month=0., ~date=12., ()) 18 | 19 | let result = date->ReDate.isThursday 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isTuesday_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isTuesday", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is Tuesday", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=9., ()) 10 | 11 | let result = date->ReDate.isTuesday 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not Tuesday", () => { 17 | let date = makeWithYMD(~year=2018., ~month=0., ~date=10., ()) 18 | 19 | let result = date->ReDate.isTuesday 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isWednesday_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isWednesday", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is Wednesday", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=10., ()) 10 | 11 | let result = date->ReDate.isWednesday 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns false if the given date is not Wednesday", () => { 17 | let date = makeWithYMD(~year=2018., ~month=0., ~date=11., ()) 18 | 19 | let result = date->ReDate.isWednesday 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isWeekDay_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isWeekDay", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given day of the week equals to the provided day", () => { 9 | let date = makeWithYMD(~year=2021., ~month=11., ~date=10., ()) 10 | 11 | let result = date->ReDate.isWeekDay(ReDate.Friday) 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns true if the given day of the week does not equal to the provided day", () => { 17 | let date = makeWithYMD(~year=2021., ~month=11., ~date=11., ()) 18 | 19 | let result = date->ReDate.isWeekDay(ReDate.Friday) 20 | 21 | result |> expect |> toBeFalsy 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /__tests__/isWeekend_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isWeekend", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given date is in a weekend (Saturday)", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=13., ()) 10 | 11 | let result = date->ReDate.isWeekend 12 | 13 | result |> expect |> toBeTruthy 14 | }) 15 | 16 | test("returns true if the given date is in a weekend (Sunday)", () => { 17 | let date = makeWithYMD(~year=2018., ~month=0., ~date=14., ()) 18 | 19 | let result = date->ReDate.isWeekend 20 | 21 | result |> expect |> toBeTruthy 22 | }) 23 | 24 | test("returns false if the given date is not in a weekend", () => { 25 | let date = makeWithYMD(~year=2018., ~month=0., ~date=12., ()) 26 | 27 | let result = date->ReDate.isWeekend 28 | 29 | result |> expect |> toBeFalsy 30 | }) 31 | }) 32 | -------------------------------------------------------------------------------- /__tests__/isWithinInterval_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("isWithinInterval", () => { 6 | open ExpectJs 7 | 8 | let interval: ReDate.interval = { 9 | start: makeWithYMD(~year=2018., ~month=0., ~date=1., ()), 10 | end_: makeWithYMD(~year=2018., ~month=0., ~date=10., ()), 11 | } 12 | 13 | test("returns true if the given date in within the given interval", () => { 14 | let date = makeWithYMD(~year=2018., ~month=0., ~date=5., ()) 15 | 16 | let result = date->ReDate.isWithinInterval(interval) 17 | 18 | result |> expect |> toBeTruthy 19 | }) 20 | 21 | test("returns true if the given date has same time as the left boundary of the interval", () => { 22 | let date = makeWithYMD(~year=2018., ~month=0., ~date=5., ()) 23 | 24 | let result = date->ReDate.isWithinInterval(interval) 25 | 26 | result |> expect |> toBeTruthy 27 | }) 28 | 29 | test("returns true if the given date has same time as the right boundary of the interval", () => { 30 | let date = makeWithYMD(~year=2018., ~month=0., ~date=10., ()) 31 | 32 | let result = date->ReDate.isWithinInterval(interval) 33 | 34 | result |> expect |> toBeTruthy 35 | }) 36 | 37 | test("returns true if the given date and the both boundaries are the same", () => { 38 | let date = makeWithYMD(~year=2018., ~month=0., ~date=10., ()) 39 | let interval: ReDate.interval = { 40 | start: makeWithYMD(~year=2018., ~month=0., ~date=10., ()), 41 | end_: makeWithYMD(~year=2018., ~month=0., ~date=10., ()), 42 | } 43 | 44 | let result = date->ReDate.isWithinInterval(interval) 45 | 46 | result |> expect |> toBeTruthy 47 | }) 48 | 49 | test("returns false if the given date is outside of the interval", () => { 50 | let date = makeWithYMD(~year=2018., ~month=0., ~date=20., ()) 51 | 52 | let result = date->ReDate.isWithinInterval(interval) 53 | 54 | result |> expect |> toBeFalsy 55 | }) 56 | }) 57 | -------------------------------------------------------------------------------- /__tests__/lastDayOfISOWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("lastDayOfISOWeek", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the last day of an ISO week", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2014., 13 | ~month=8., 14 | ~date=2., 15 | ~hours=11., 16 | ~minutes=55., 17 | ~seconds=0., 18 | (), 19 | ) 20 | let expectedDate = 21 | setHoursMSMs( 22 | makeWithYMD(~year=2014., ~month=8., ~date=7., ()), 23 | ~hours=0., 24 | ~minutes=0., 25 | ~seconds=0., 26 | ~milliseconds=0., 27 | (), 28 | ) |> fromFloat 29 | 30 | let result = date->ReDate.lastDayOfISOWeek 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | }) 36 | -------------------------------------------------------------------------------- /__tests__/lastDayOfMonth_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("lastDayOfMonth", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the last day of a month", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=0., 14 | ~date=12., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=12., 18 | (), 19 | ) 20 | let expectedDate = 21 | setHoursMSMs( 22 | makeWithYMD(~year=2018., ~month=0., ~date=31., ()), 23 | ~hours=0., 24 | ~minutes=0., 25 | ~seconds=0., 26 | ~milliseconds=0., 27 | (), 28 | ) |> fromFloat 29 | 30 | let result = date->ReDate.lastDayOfMonth 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | }) 36 | -------------------------------------------------------------------------------- /__tests__/lastDayOfWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("lastDayOfWeek", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the last day of a week", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=0., 14 | ~date=12., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=12., 18 | (), 19 | ) 20 | let expectedDate = 21 | setHoursMSMs( 22 | makeWithYMD(~year=2018., ~month=0., ~date=13., ()), 23 | ~hours=0., 24 | ~minutes=0., 25 | ~seconds=0., 26 | ~milliseconds=0., 27 | (), 28 | ) |> fromFloat 29 | 30 | let result = date->ReDate.lastDayOfWeek 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | 36 | test("allows to specify which day is the first day of the week", () => { 37 | let date = makeWithYMDHMS( 38 | ~year=2018., 39 | ~month=0., 40 | ~date=12., 41 | ~hours=16., 42 | ~minutes=50., 43 | ~seconds=12., 44 | (), 45 | ) 46 | let expectedDate = 47 | setHoursMSMs( 48 | makeWithYMD(~year=2018., ~month=0., ~date=14., ()), 49 | ~hours=0., 50 | ~minutes=0., 51 | ~seconds=0., 52 | ~milliseconds=0., 53 | (), 54 | ) |> fromFloat 55 | let lastDayOfWeek = ReDate.lastDayOfWeek(~weekStartsOn=Monday) 56 | 57 | let result = date->lastDayOfWeek 58 | 59 | result |> expect |> toEqual(expectedDate) 60 | }) 61 | }) 62 | -------------------------------------------------------------------------------- /__tests__/lastDayOfYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("lastDayOfYear", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the last day of the last month of the year", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=8., 14 | ~date=10., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=12., 18 | (), 19 | ) 20 | let expectedDate = 21 | setHoursMSMs( 22 | makeWithYMD(~year=2018., ~month=11., ~date=31., ()), 23 | ~hours=0., 24 | ~minutes=0., 25 | ~seconds=0., 26 | ~milliseconds=0., 27 | (), 28 | ) |> fromFloat 29 | 30 | let result = date->ReDate.lastDayOfYear 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | }) 36 | -------------------------------------------------------------------------------- /__tests__/lastMonthOfYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("lastMonthOfYear", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the first day of the last month of the year", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=8., 14 | ~date=10., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=12., 18 | (), 19 | ) 20 | let expectedDate = 21 | setHoursMSMs( 22 | makeWithYMD(~year=2018., ~month=11., ~date=1., ()), 23 | ~hours=0., 24 | ~minutes=0., 25 | ~seconds=0., 26 | ~milliseconds=0., 27 | (), 28 | ) |> fromFloat 29 | 30 | let result = date->ReDate.lastMonthOfYear 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | }) 36 | -------------------------------------------------------------------------------- /__tests__/max.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("max", () => { 6 | open ExpectJs 7 | 8 | test("returns the latest date (list)", () => { 9 | let a = makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 10 | let b = makeWithYMD(~year=2017., ~month=2., ~date=1., ()) 11 | let c = makeWithYMD(~year=2017., ~month=4., ~date=1., ()) 12 | let d = makeWithYMD(~year=2018., ~month=12., ~date=1., ()) 13 | 14 | let dates = [b, c, d, a] 15 | 16 | let result = dates->ReDate.max 17 | 18 | result |> expect |> toEqual(d) 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /__tests__/min.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("min", () => { 6 | open ExpectJs 7 | 8 | test("returns the earliest date (list)", () => { 9 | let a = makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 10 | let b = makeWithYMD(~year=2017., ~month=2., ~date=1., ()) 11 | let c = makeWithYMD(~year=2017., ~month=4., ~date=1., ()) 12 | let d = makeWithYMD(~year=2018., ~month=12., ~date=1., ()) 13 | 14 | let dates = [b, c, d, a] 15 | 16 | let result = dates->ReDate.min 17 | 18 | result |> expect |> toEqual(a) 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /__tests__/roundToNearestMinute_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("roundToNearestMinute", () => { 6 | open ExpectJs 7 | 8 | test("returns true if the given dates round to the closest minute", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=8., 12 | ~date=10., 13 | ~hours=19., 14 | ~minutes=6., 15 | ~seconds=31., 16 | (), 17 | ) 18 | let expectedDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=8., 21 | ~date=10., 22 | ~hours=19., 23 | ~minutes=7., 24 | ~seconds=0., 25 | (), 26 | ) 27 | 28 | let result = date->ReDate.roundToNearestMinute 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | 33 | test("returns true if the given dates round to the nearest 15 minutes", () => { 34 | let date = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=8., 37 | ~date=10., 38 | ~hours=19., 39 | ~minutes=12., 40 | ~seconds=10., 41 | (), 42 | ) 43 | let expectedDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=8., 46 | ~date=10., 47 | ~hours=19., 48 | ~minutes=15., 49 | ~seconds=0., 50 | (), 51 | ) 52 | let roundToNearest15Minute = ReDate.roundToNearestMinute(~nearestTo=15.) 53 | 54 | let result = date->roundToNearest15Minute 55 | 56 | result |> expect |> toEqual(expectedDate) 57 | }) 58 | }) 59 | -------------------------------------------------------------------------------- /__tests__/setDate_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("setDate", () => { 6 | open ExpectJs 7 | 8 | test("sets the date of the given date", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | let expectedDate = makeWithYMD(~year=2018., ~month=0., ~date=20., ()) 11 | 12 | let result = date->ReDate.setDate(20.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /__tests__/setHours_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("setHours", () => { 6 | open ExpectJs 7 | 8 | test("sets the hours of the given date", () => { 9 | let date = makeWithYMDH(~year=2018., ~month=0., ~date=1., ~hours=18., ()) 10 | let expectedDate = makeWithYMDH(~year=2018., ~month=0., ~date=1., ~hours=9., ()) 11 | 12 | let result = date->ReDate.setHours(9.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /__tests__/setISOWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("setISOWeek", () => { 6 | open ExpectJs 7 | 8 | test("sets the ISO week (first week)", () => { 9 | let date = makeWithYMDH(~year=2004., ~month=7., ~date=7., ~hours=12., ()) 10 | let expectedDate = makeWithYMDH(~year=2004., ~month=0., ~date=3., ~hours=12., ()) 11 | 12 | let result = date->ReDate.setISOWeek(1.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | 17 | test("sets the ISO week (last week)", () => { 18 | let date = makeWithYMDH(~year=2004., ~month=7., ~date=7., ~hours=12., ()) 19 | let expectedDate = makeWithYMDH(~year=2005., ~month=0., ~date=1., ~hours=12., ()) 20 | 21 | let result = date->ReDate.setISOWeek(53.) 22 | result |> expect |> toEqual(expectedDate) 23 | }) 24 | 25 | test("original date should not be changed when ISO week is changed", () => { 26 | let date = makeWithYMDH(~year=2004., ~month=7., ~date=7., ~hours=12., ()) 27 | let expectedDate = date->Js.Date.getTime->Js.Date.fromFloat 28 | 29 | date->ReDate.setISOWeek(53.)->ignore 30 | 31 | date |> expect |> toEqual(expectedDate) 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /__tests__/setMinutes_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("setMinutes", () => { 6 | open ExpectJs 7 | 8 | test("sets the minutes of the given date", () => { 9 | let date = makeWithYMDHM(~year=2018., ~month=0., ~date=1., ~hours=18., ~minutes=1., ()) 10 | let expectedDate = makeWithYMDHM(~year=2018., ~month=0., ~date=1., ~hours=18., ~minutes=30., ()) 11 | 12 | let result = date->ReDate.setMinutes(30.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /__tests__/setMonth_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("setMonth", () => { 6 | open ExpectJs 7 | 8 | test("sets the month of the given date", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 10 | let expectedDate = makeWithYMD(~year=2018., ~month=10., ~date=1., ()) 11 | 12 | let result = date->ReDate.setMonth(10.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /__tests__/setSeconds_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("setSeconds", () => { 6 | open ExpectJs 7 | 8 | test("sets the minutes of the given date", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=18., 14 | ~minutes=1., 15 | ~seconds=0., 16 | (), 17 | ) 18 | let expectedDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=18., 23 | ~minutes=1., 24 | ~seconds=50., 25 | (), 26 | ) 27 | 28 | let result = date->ReDate.setSeconds(50.) 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | }) 33 | -------------------------------------------------------------------------------- /__tests__/setYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("setYear", () => { 6 | open ExpectJs 7 | 8 | test("sets the year of the given date", () => { 9 | let date = makeWithYM(~year=2018., ~month=0., ()) 10 | let expectedDate = makeWithYM(~year=2042., ~month=0., ()) 11 | 12 | let result = date->ReDate.setYear(2042.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /__tests__/startOfDay_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("startOfDay", () => { 6 | open ExpectJs 7 | 8 | test("returns the date with the time set to 00:00:00", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=16., 14 | ~minutes=50., 15 | ~seconds=12., 16 | (), 17 | ) 18 | let expectedDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=0., 23 | ~minutes=0., 24 | ~seconds=0., 25 | (), 26 | ) 27 | 28 | let result = date->ReDate.startOfDay 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | }) 33 | -------------------------------------------------------------------------------- /__tests__/startOfHour_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("startOfHour", () => { 6 | open ExpectJs 7 | 8 | test("returns the date with the time set to the first millisecond of an hour", () => { 9 | let date = 10 | setMilliseconds( 11 | makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=0., 14 | ~date=1., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=10., 18 | (), 19 | ), 20 | 423., 21 | ) |> fromFloat 22 | let expectedDate = 23 | setMilliseconds( 24 | makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=16., ~minutes=0., ~seconds=0., ()), 25 | 0., 26 | ) |> fromFloat 27 | 28 | let result = date->ReDate.startOfHour 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | }) 33 | -------------------------------------------------------------------------------- /__tests__/startOfISOWeekYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("startOfISOWeekYear", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the first day of an ISO year", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2009., 13 | ~month=0., 14 | ~date=1., 15 | ~hours=16., 16 | ~minutes=0., 17 | ~seconds=0., 18 | (), 19 | ) 20 | 21 | let expectedDate = 22 | setHoursMSMs( 23 | makeWithYMD(~year=2008., ~month=11., ~date=29., ()), 24 | ~hours=0., 25 | ~minutes=0., 26 | ~seconds=0., 27 | ~milliseconds=0., 28 | (), 29 | ) |> fromFloat 30 | 31 | let result = date->ReDate.startOfISOWeekYear 32 | 33 | result |> expect |> toEqual(expectedDate) 34 | }, 35 | ) 36 | 37 | test("handles dates before 100 AD", () => { 38 | let date = 39 | setFullYearMD( 40 | fromFloat( 41 | setHoursMSMs(fromFloat(0.), ~hours=0., ~minutes=0., ~seconds=0., ~milliseconds=0., ()), 42 | ), 43 | ~year=9., 44 | ~month=0., 45 | ~date=1., 46 | (), 47 | ) |> fromFloat 48 | 49 | let expectedDate = 50 | setFullYearMD( 51 | fromFloat( 52 | setHoursMSMs(fromFloat(0.), ~hours=0., ~minutes=0., ~seconds=0., ~milliseconds=0., ()), 53 | ), 54 | ~year=8., 55 | ~month=11., 56 | ~date=29., 57 | (), 58 | ) |> fromFloat 59 | 60 | let result = date->ReDate.startOfISOWeekYear 61 | 62 | result |> expect |> toEqual(expectedDate) 63 | }) 64 | 65 | test("correctly handles years in which 4 January is Sunday", () => { 66 | let date = makeWithYMD(~year=2009., ~month=6., ~date=2., ()) 67 | 68 | let expectedDate = makeWithYMD(~year=2008., ~month=11., ~date=29., ()) 69 | 70 | let result = date->ReDate.startOfISOWeekYear 71 | 72 | result |> expect |> toEqual(expectedDate) 73 | }) 74 | }) 75 | -------------------------------------------------------------------------------- /__tests__/startOfISOWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("startOfISOWeek", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the first day of an ISO week", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2014., 13 | ~month=8., 14 | ~date=2., 15 | ~hours=11., 16 | ~minutes=55., 17 | ~seconds=0., 18 | (), 19 | ) 20 | 21 | let expectedDate = 22 | setHoursMSMs( 23 | makeWithYMD(~year=2014., ~month=8., ~date=1., ()), 24 | ~hours=0., 25 | ~minutes=0., 26 | ~seconds=0., 27 | ~milliseconds=0., 28 | (), 29 | ) |> fromFloat 30 | 31 | let result = date->ReDate.startOfISOWeek 32 | 33 | result |> expect |> toEqual(expectedDate) 34 | }, 35 | ) 36 | }) 37 | -------------------------------------------------------------------------------- /__tests__/startOfMinute_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("startOfMinute", () => { 6 | open ExpectJs 7 | 8 | test("returns the date with the time set to the first millisecond of an minute", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=8., 12 | ~date=10., 13 | ~hours=8., 14 | ~minutes=20., 15 | ~seconds=35., 16 | (), 17 | ) 18 | let expectedDate = 19 | setMilliseconds( 20 | makeWithYMDHMS(~year=2018., ~month=8., ~date=10., ~hours=8., ~minutes=20., ~seconds=0., ()), 21 | 0., 22 | ) |> fromFloat 23 | 24 | let result = date->ReDate.startOfMinute 25 | 26 | result |> expect |> toEqual(expectedDate) 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /__tests__/startOfMonth_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("startOfMonth", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the first day of a month", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=0., 14 | ~date=24., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=12., 18 | (), 19 | ) 20 | let expectedDate = makeWithYMDHMS( 21 | ~year=2018., 22 | ~month=0., 23 | ~date=1., 24 | ~hours=0., 25 | ~minutes=0., 26 | ~seconds=0., 27 | (), 28 | ) 29 | 30 | let result = date->ReDate.startOfMonth 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | }) 36 | -------------------------------------------------------------------------------- /__tests__/startOfSecond_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("startOfSecond", () => { 6 | open ExpectJs 7 | 8 | test("returns the date with the time set to the first millisecond of a second", () => { 9 | let date = 10 | setMilliseconds( 11 | makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=0., 14 | ~date=1., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=10., 18 | (), 19 | ), 20 | 423., 21 | ) |> fromFloat 22 | let expectedDate = 23 | setMilliseconds( 24 | makeWithYMDHMS( 25 | ~year=2018., 26 | ~month=0., 27 | ~date=1., 28 | ~hours=16., 29 | ~minutes=50., 30 | ~seconds=10., 31 | (), 32 | ), 33 | 0., 34 | ) |> fromFloat 35 | 36 | let result = date->ReDate.startOfSecond 37 | 38 | result |> expect |> toEqual(expectedDate) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /__tests__/startOfWeekYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("startOfWeekYear", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the first day of a week year", 10 | () => { 11 | let date = makeWithYMD(~year=2020., ~month=4., ~date=10., ()) 12 | let expectedDate = makeWithYMDHMS( 13 | ~year=2019., 14 | ~month=11., 15 | ~date=29., 16 | ~hours=0., 17 | ~minutes=0., 18 | ~seconds=0., 19 | (), 20 | ) 21 | 22 | let result = date->ReDate.startOfWeekYear 23 | 24 | result |> expect |> toEqual(expectedDate) 25 | }, 26 | ) 27 | 28 | test("allows to specify which day is the first day of the week", () => { 29 | let date = makeWithYMD(~year=2020., ~month=4., ~date=10., ()) 30 | let expectedDate = 31 | setHoursMSMs( 32 | makeWithYMD(~year=2019., ~month=11., ~date=30., ()), 33 | ~hours=0., 34 | ~minutes=0., 35 | ~seconds=0., 36 | ~milliseconds=0., 37 | (), 38 | ) |> fromFloat 39 | let startOfWeekYear = ReDate.startOfWeekYear(~weekStartsOn=Monday) 40 | 41 | let result = date->startOfWeekYear 42 | 43 | result |> expect |> toEqual(expectedDate) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /__tests__/startOfWeek_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("startOfWeek", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the first day of a week", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=0., 14 | ~date=12., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=12., 18 | (), 19 | ) 20 | let expectedDate = makeWithYMDHMS( 21 | ~year=2018., 22 | ~month=0., 23 | ~date=7., 24 | ~hours=0., 25 | ~minutes=0., 26 | ~seconds=0., 27 | (), 28 | ) 29 | 30 | let result = date->ReDate.startOfWeek 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | 36 | test("allows to specify which day is the first day of the week", () => { 37 | let date = makeWithYMDHMS( 38 | ~year=2018., 39 | ~month=0., 40 | ~date=12., 41 | ~hours=16., 42 | ~minutes=50., 43 | ~seconds=12., 44 | (), 45 | ) 46 | let expectedDate = makeWithYMDHMS( 47 | ~year=2018., 48 | ~month=0., 49 | ~date=8., 50 | ~hours=0., 51 | ~minutes=0., 52 | ~seconds=0., 53 | (), 54 | ) 55 | let startOfWeek = ReDate.startOfWeek(~weekStartsOn=Monday) 56 | 57 | let result = date->startOfWeek 58 | 59 | result |> expect |> toEqual(expectedDate) 60 | }) 61 | }) 62 | -------------------------------------------------------------------------------- /__tests__/startOfYear_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("startOfYear", () => { 6 | open ExpectJs 7 | 8 | test( 9 | "returns the date with the time set to 00:00:00 and the date set to the first day of a year", 10 | () => { 11 | let date = makeWithYMDHMS( 12 | ~year=2018., 13 | ~month=5., 14 | ~date=1., 15 | ~hours=16., 16 | ~minutes=50., 17 | ~seconds=12., 18 | (), 19 | ) 20 | let expectedDate = makeWithYMDHMS( 21 | ~year=2018., 22 | ~month=0., 23 | ~date=1., 24 | ~hours=0., 25 | ~minutes=0., 26 | ~seconds=0., 27 | (), 28 | ) 29 | 30 | let result = date->ReDate.startOfYear 31 | 32 | result |> expect |> toEqual(expectedDate) 33 | }, 34 | ) 35 | }) 36 | -------------------------------------------------------------------------------- /__tests__/subDays_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("subDays", () => { 6 | open ExpectJs 7 | 8 | test("subtracts 1 day", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 10 | let expectedDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 11 | 12 | let result = date->ReDate.subDays(1.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | 17 | test("subtracts 100 days", () => { 18 | let date = makeWithYMD(~year=2018., ~month=3., ~date=11., ()) 19 | let expectedDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 20 | 21 | let result = date->ReDate.subDays(100.) 22 | 23 | result |> expect |> toEqual(expectedDate) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/subHours_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("subHours", () => { 6 | open ExpectJs 7 | 8 | test("subtracts 1 hour", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=19., 14 | ~minutes=30., 15 | ~seconds=0., 16 | (), 17 | ) 18 | let expectedDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=18., 23 | ~minutes=30., 24 | ~seconds=0., 25 | (), 26 | ) 27 | 28 | let result = date->ReDate.subHours(1.) 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | 33 | test("subtracts 60 hours", () => { 34 | let date = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=19., 39 | ~minutes=30., 40 | ~seconds=0., 41 | (), 42 | ) 43 | let expectedDate = makeWithYMDHMS( 44 | ~year=2017., 45 | ~month=11., 46 | ~date=30., 47 | ~hours=7., 48 | ~minutes=30., 49 | ~seconds=0., 50 | (), 51 | ) 52 | 53 | let result = date->ReDate.subHours(60.) 54 | 55 | result |> expect |> toEqual(expectedDate) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/subMinutes_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("subMinutes", () => { 6 | open ExpectJs 7 | 8 | test("subtracts 1 minute", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=19., 14 | ~minutes=30., 15 | ~seconds=30., 16 | (), 17 | ) 18 | let expectedDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=19., 23 | ~minutes=29., 24 | ~seconds=30., 25 | (), 26 | ) 27 | 28 | let result = date->ReDate.subMinutes(1.) 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | 33 | test("subtracts 100 minutes", () => { 34 | let date = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=19., 39 | ~minutes=30., 40 | ~seconds=30., 41 | (), 42 | ) 43 | let expectedDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=1., 47 | ~hours=17., 48 | ~minutes=50., 49 | ~seconds=30., 50 | (), 51 | ) 52 | 53 | let result = date->ReDate.subMinutes(100.) 54 | 55 | result |> expect |> toEqual(expectedDate) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/subMonths_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("subMonths", () => { 6 | open ExpectJs 7 | 8 | test("subtracts 1 month", () => { 9 | let date = makeWithYMD(~year=2018., ~month=1., ~date=1., ()) 10 | let expectedDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 11 | 12 | let result = date->ReDate.subMonths(1.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | 17 | test("subtracts 30 months", () => { 18 | let date = makeWithYMD(~year=2020., ~month=11., ~date=1., ()) 19 | let expectedDate = makeWithYMD(~year=2018., ~month=5., ~date=1., ()) 20 | 21 | let result = date->ReDate.subMonths(30.) 22 | 23 | result |> expect |> toEqual(expectedDate) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/subSeconds_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("subSeconds", () => { 6 | open ExpectJs 7 | 8 | test("subtracts 1 second", () => { 9 | let date = makeWithYMDHMS( 10 | ~year=2018., 11 | ~month=0., 12 | ~date=1., 13 | ~hours=19., 14 | ~minutes=30., 15 | ~seconds=0., 16 | (), 17 | ) 18 | let expectedDate = makeWithYMDHMS( 19 | ~year=2018., 20 | ~month=0., 21 | ~date=1., 22 | ~hours=19., 23 | ~minutes=29., 24 | ~seconds=59., 25 | (), 26 | ) 27 | 28 | let result = date->ReDate.subSeconds(1.) 29 | 30 | result |> expect |> toEqual(expectedDate) 31 | }) 32 | 33 | test("subtracts 100 seconds", () => { 34 | let date = makeWithYMDHMS( 35 | ~year=2018., 36 | ~month=0., 37 | ~date=1., 38 | ~hours=19., 39 | ~minutes=30., 40 | ~seconds=0., 41 | (), 42 | ) 43 | let expectedDate = makeWithYMDHMS( 44 | ~year=2018., 45 | ~month=0., 46 | ~date=1., 47 | ~hours=19., 48 | ~minutes=28., 49 | ~seconds=20., 50 | (), 51 | ) 52 | 53 | let result = date->ReDate.subSeconds(100.) 54 | 55 | result |> expect |> toEqual(expectedDate) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /__tests__/subWeeks_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("subWeeks", () => { 6 | open ExpectJs 7 | 8 | test("subtracts 1 week", () => { 9 | let date = makeWithYMD(~year=2018., ~month=0., ~date=8., ()) 10 | let expectedDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 11 | 12 | let result = date->ReDate.subWeeks(1.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | 17 | test("subtracts 10 weeks", () => { 18 | let date = makeWithYMD(~year=2018., ~month=2., ~date=12., ()) 19 | let expectedDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 20 | 21 | let result = date->ReDate.subWeeks(10.) 22 | 23 | result |> expect |> toEqual(expectedDate) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /__tests__/subYears_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | open Js.Date 4 | 5 | describe("subYears", () => { 6 | open ExpectJs 7 | 8 | test("subtracts 1 year", () => { 9 | let date = makeWithYMD(~year=2019., ~month=4., ~date=1., ()) 10 | let expectedDate = makeWithYMD(~year=2018., ~month=4., ~date=1., ()) 11 | 12 | let result = date->ReDate.subYears(1.) 13 | 14 | result |> expect |> toEqual(expectedDate) 15 | }) 16 | 17 | test("subtracts 10 years", () => { 18 | let date = makeWithYMD(~year=2009., ~month=4., ~date=1., ()) 19 | let expectedDate = makeWithYMD(~year=1999., ~month=4., ~date=1., ()) 20 | 21 | let result = date->ReDate.subYears(10.) 22 | 23 | result |> expect |> toEqual(expectedDate) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /assets/rescript-date-frame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobily/rescript-date/514f8672026d81155fa45ac8eadb16a25d76f59d/assets/rescript-date-frame.png -------------------------------------------------------------------------------- /bsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mobily/rescript-date", 3 | "namespace": false, 4 | "bsc-flags": [ 5 | "-bs-no-version-header", 6 | "-bs-super-errors" 7 | ], 8 | "bs-dev-dependencies": [ 9 | "@glennsl/bs-jest" 10 | ], 11 | "package-specs": { 12 | "module": "commonjs", 13 | "in-source": true 14 | }, 15 | "suffix": ".bs.js", 16 | "sources": [ 17 | { 18 | "dir": "src" 19 | }, 20 | { 21 | "dir": "__tests__", 22 | "type": "dev" 23 | } 24 | ], 25 | "warnings": { 26 | "number": "+R-48", 27 | "error": "+R" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | -------------------------------------------------------------------------------- /docs/api/common.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: common 3 | title: Common 4 | --- 5 | 6 | ### isEqual 7 | 8 | Are the given dates equal? 9 | 10 | ```js 11 | let isEqual: (Js.Date.t, Js.Date.t) => bool 12 | ``` 13 | 14 | ```js 15 | let fstDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 16 | let sndDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 17 | 18 | fstDate->ReDate.isEqual(sndDate) 19 | ``` 20 | 21 | ### isBefore 22 | 23 | Is the first date before the second one? 24 | 25 | ```js 26 | let isBefore: (Js.Date.t, Js.Date.t) => bool 27 | ``` 28 | 29 | ```js 30 | let fstDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 31 | let sndDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 32 | 33 | fstDate->ReDate.isBefore(sndDate) 34 | ``` 35 | 36 | ### isAfter 37 | 38 | Is the first date after the second one? 39 | 40 | ```js 41 | let isAfter: (Js.Date.t, Js.Date.t) => bool 42 | ``` 43 | 44 | ```js 45 | let fstDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 46 | let sndDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 47 | 48 | fstDate->ReDate.isAfter(sndDate) 49 | ``` 50 | 51 | ### isFuture 52 | 53 | Is the given date in the future? 54 | 55 | ```js 56 | let isFuture: Js.Date.t => bool 57 | ``` 58 | 59 | ```js 60 | let date = Js.Date.makeWithYMD(~year=2030., ~month=0., ~date=1., ()) 61 | 62 | date->ReDate.isFuture 63 | ``` 64 | 65 | ### isPast 66 | 67 | Is the given date in the past? 68 | 69 | ```js 70 | let isPast: Js.Date.t => bool 71 | ``` 72 | 73 | ```js 74 | let date = Js.Date.makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 75 | 76 | date->ReDate.isPast 77 | ``` 78 | 79 | ### compareAsc 80 | 81 | Compare the two dates and return 1 if the first date is after the second, -1 if the first date is before the second or 0 if dates are equal. 82 | 83 | ```js 84 | let compareAsc: (Js.Date.t, Js.Date.t) => int 85 | ``` 86 | 87 | ```js 88 | let a = Js.Date.makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 89 | let b = Js.Date.makeWithYMD(~year=2017., ~month=2., ~date=1., ()) 90 | let c = Js.Date.makeWithYMD(~year=2017., ~month=4., ~date=1., ()) 91 | let d = Js.Date.makeWithYMD(~year=2018., ~month=12., ~date=1., ()) 92 | 93 | let unsortedArray = [d, b, c, a] 94 | 95 | Belt.SortArray.stableSortBy(unsortedArray, ReDate.compareAsc) 96 | ``` 97 | 98 | ### compareDesc 99 | 100 | Compare the two dates and return -1 if the first date is after the second, 1 if the first date is before the second or 0 if dates are equal. 101 | 102 | ```js 103 | let compareDesc: (Js.Date.t, Js.Date.t) => int 104 | ``` 105 | 106 | ```js 107 | let a = Js.Date.makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 108 | let b = Js.Date.makeWithYMD(~year=2017., ~month=2., ~date=1., ()) 109 | let c = Js.Date.makeWithYMD(~year=2017., ~month=4., ~date=1., ()) 110 | let d = Js.Date.makeWithYMD(~year=2018., ~month=12., ~date=1., ()) 111 | 112 | let unsortedArray = [a, b, d, c] 113 | 114 | Belt.SortArray.stableSortBy(unsortedArray, ReDate.compareDesc) 115 | ``` 116 | 117 | ### max 118 | 119 | Return the latest of the given dates. 120 | 121 | ```js 122 | let max: array => Js.Date.t 123 | ``` 124 | 125 | ```js 126 | let a = Js.Date.makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 127 | let b = Js.Date.makeWithYMD(~year=2017., ~month=2., ~date=1., ()) 128 | let c = Js.Date.makeWithYMD(~year=2017., ~month=4., ~date=1., ()) 129 | let d = Js.Date.makeWithYMD(~year=2018., ~month=12., ~date=1., ()) 130 | 131 | let dates = [b, c, d, a] 132 | 133 | dates->ReDate.max 134 | ``` 135 | 136 | ### min 137 | 138 | Return the earliest of the given dates. 139 | 140 | ```js 141 | let min: array => Js.Date.t 142 | ``` 143 | 144 | ```js 145 | let a = Js.Date.makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 146 | let b = Js.Date.makeWithYMD(~year=2017., ~month=2., ~date=1., ()) 147 | let c = Js.Date.makeWithYMD(~year=2017., ~month=4., ~date=1., ()) 148 | let d = Js.Date.makeWithYMD(~year=2018., ~month=12., ~date=1., ()) 149 | 150 | let dates = [b, c, d, a] 151 | 152 | dates->ReDate.min 153 | ``` 154 | 155 | ### isValid 156 | 157 | Is the given date valid? 158 | 159 | ```js 160 | let isValid: (~year: float, ~month: float, ~date: float, ~hours: float=?, ~minutes: float=?, ~seconds: float=?, unit) => bool 161 | ``` 162 | 163 | ```js 164 | ReDate.isValid(~year=1999., ~month=1., ~date=29., ()) 165 | ``` 166 | 167 | ### closestTo 168 | 169 | Return a date from the array closest to the given date. 170 | 171 | ```js 172 | let closestTo: (Js.Date.t, array) => option 173 | ``` 174 | 175 | ```js 176 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 177 | 178 | let a = Js.Date.makeWithYMD(~year=1999., ~month=0., ~date=1., ()) 179 | let b = Js.Date.makeWithYMD(~year=2018., ~month=2., ~date=1., ()) 180 | let c = Js.Date.makeWithYMD(~year=2020., ~month=4., ~date=1., ()) 181 | let d = Js.Date.makeWithYMD(~year=2022., ~month=12., ~date=1., ()) 182 | 183 | let dates = [a, b, c, d] 184 | 185 | date->ReDate.closestTo(dates) 186 | ``` 187 | -------------------------------------------------------------------------------- /docs/api/day.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: day 3 | title: Day 4 | --- 5 | 6 | ```js 7 | type day = 8 | | Sunday 9 | | Monday 10 | | Tuesday 11 | | Wednesday 12 | | Thursday 13 | | Friday 14 | | Saturday 15 | ``` 16 | 17 | ### addDays 18 | 19 | Add the specified number of days to the given date. 20 | 21 | ```js 22 | let addDays: (Js.Date.t, float) => Js.Date.t 23 | ``` 24 | 25 | ```js 26 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 27 | 28 | date->ReDate.addDays(5.) 29 | ``` 30 | 31 | ### addBusinessDays 32 | 33 | Add the specified number of business days to the given date (excluding weekends). 34 | 35 | ```js 36 | let addBusinessDays: (Js.Date.t, float) => Js.Date.t 37 | ``` 38 | 39 | ```js 40 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 41 | 42 | date->ReDate.addBusinessDays(5.) 43 | ``` 44 | 45 | ### subDays 46 | 47 | Subtract the specified number of days from the given date. 48 | 49 | ```js 50 | let subDays: (Js.Date.t, float) => Js.Date.t 51 | ``` 52 | 53 | ```js 54 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 55 | 56 | date->ReDate.subDays(5.) 57 | ``` 58 | 59 | ### getDate 60 | 61 | Get the day of the month of the given date. 62 | 63 | ```js 64 | let getDate: Js.Date.t => float 65 | ``` 66 | 67 | ```js 68 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 69 | 70 | date->ReDate.getDate 71 | ``` 72 | 73 | ### setDate 74 | 75 | Set the day of the month to the given date. 76 | 77 | ```js 78 | let setDate: (Js.Date.t, float) => Js.Date.t 79 | ``` 80 | 81 | ```js 82 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 83 | 84 | date->ReDate.setDate(23.) 85 | ``` 86 | 87 | ### startOfDay 88 | 89 | Return the start of a day for the given date. 90 | 91 | ```js 92 | let startOfDay: Js.Date.t => Js.Date.t 93 | ``` 94 | 95 | ```js 96 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=16., ~minutes=50., ~seconds=12., ()) 97 | 98 | date->ReDate.startOfDay 99 | ``` 100 | 101 | ### endOfDay 102 | 103 | Return the end of a day for the given date. 104 | 105 | ```js 106 | let endOfDay: Js.Date.t => Js.Date.t 107 | ``` 108 | 109 | ```js 110 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=16., ~minutes=50., ~seconds=12., ()) 111 | 112 | date->ReDate.endOfDay 113 | ``` 114 | 115 | ### differenceInCalendarDays 116 | 117 | Get the number of calendar days between the given dates. This means that the times are removed from the dates and then the difference in days is calculated. 118 | 119 | ```js 120 | let differenceInCalendarDays: (Js.Date.t, Js.Date.t) => float 121 | ``` 122 | 123 | ```js 124 | let fstDate = Js.Date.makeWithYMD(~year=2019., ~month=0., ~date=1., ()) 125 | let sndDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 126 | 127 | fstDate->ReDate.differenceInCalendarDays(sndDate) 128 | ``` 129 | 130 | ### differenceInDays 131 | 132 | Get the number of full day periods between the given dates. 133 | 134 | ```js 135 | let differenceInDays: (Js.Date.t, Js.Date.t) => float 136 | ``` 137 | 138 | ```js 139 | let fstDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=10., ~hours=10., ~minutes=15., ~seconds=55., ()) 140 | let sndDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=2., ~hours=20., ~minutes=50., ~seconds=10., ()) 141 | 142 | fstDate->ReDate.differenceInDays(sndDate) 143 | ``` 144 | 145 | ### differenceInBusinessDays 146 | 147 | Get the number of full day periods between the given dates. 148 | 149 | ```js 150 | let differenceInBusinessDays: (Js.Date.t, Js.Date.t) => float 151 | ``` 152 | 153 | ```js 154 | let fstDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=10., ()) 155 | let sndDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=2., ()) 156 | 157 | fstDate->ReDate.differenceInBusinessDays(sndDate) 158 | ``` 159 | 160 | ### getDayOfYear 161 | 162 | Get the day of the year of the given date. 163 | 164 | ```js 165 | let getDayOfYear: Js.Date.t => float 166 | ``` 167 | 168 | ```js 169 | let date = Js.Date.makeWithYMD(~year=2018., ~month=7., ~date=23., ()) 170 | 171 | date->ReDate.getDayOfYear 172 | ``` 173 | 174 | ### isSameDay 175 | 176 | Are the given dates in the same day? 177 | 178 | ```js 179 | let isSameDay: (Js.Date.t, Js.Date.t) => bool 180 | ``` 181 | 182 | ```js 183 | let fstDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=16., ~minutes=50., ~seconds=12., ()) 184 | let sndDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=10., ~minutes=15., ~seconds=55., ()) 185 | 186 | fstDate->ReDate.isSameDay(sndDate) 187 | ``` 188 | 189 | ### isToday 190 | 191 | Is the given date today? 192 | 193 | ```js 194 | let isToday: Js.Date.t => bool 195 | ``` 196 | 197 | ```js 198 | let date = Js.Date.make() 199 | 200 | date->ReDate.isToday 201 | ``` 202 | 203 | ### isTomorrow 204 | 205 | Is the given date tomorrow? 206 | 207 | ```js 208 | let isTomorrow: Js.Date.t => bool 209 | ``` 210 | 211 | ```js 212 | let date = Js.Date.make() 213 | 214 | date->ReDate.addDays(.1)->ReDate.isTomorrow 215 | ``` 216 | 217 | ### isYesterday 218 | 219 | Is the given date yesterday? 220 | 221 | ```js 222 | let isYesterday: Js.Date.t => bool 223 | ``` 224 | 225 | ```js 226 | let date = Js.Date.make() 227 | 228 | date->ReDate.subDays(1.)->ReDate.isYesterday 229 | ``` 230 | -------------------------------------------------------------------------------- /docs/api/hour.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: hour 3 | title: Hour 4 | --- 5 | 6 | ### addHours 7 | 8 | Add the specified number of hours to the given date. 9 | 10 | ```js 11 | let addHours: (Js.Date.t, float) => Js.Date.t 12 | ``` 13 | 14 | ```js 15 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=0., ()); 16 | 17 | date->ReDate.addHours(1.); 18 | ``` 19 | 20 | ### subHours 21 | 22 | Subtract the specified number of hours from the given date. 23 | 24 | ```js 25 | let subHours: (Js.Date.t, float) => Js.Date.t 26 | ``` 27 | 28 | ```js 29 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=0., ()); 30 | 31 | date->ReDate.subHours(1.); 32 | ``` 33 | 34 | ### getHours 35 | 36 | Get the hours of the given date. 37 | 38 | ```js 39 | let getHours: Js.Date.t => float 40 | ``` 41 | 42 | ```js 43 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=30., ()); 44 | 45 | date->ReDate.getHours 46 | ``` 47 | 48 | ### setHours 49 | 50 | Set the hours to the given date. 51 | 52 | ```js 53 | let setHours: (Js.Date.t, float) => Js.Date.t 54 | ``` 55 | 56 | ```js 57 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=0., ()); 58 | 59 | date->ReDate.setHours(18.) 60 | ``` 61 | 62 | ### differenceInHours 63 | 64 | Get the number of hours between the given dates. 65 | 66 | ```js 67 | let differenceInHours: (Js.Date.t, Js.Date.t) => float 68 | ``` 69 | 70 | ```js 71 | let fstDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=40., ~seconds=15., ()); 72 | let sndDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=10., ~minutes=30., ~seconds=0., ()); 73 | 74 | fstDate->ReDate.differenceInHours(sndDate); 75 | ``` 76 | 77 | ### startOfHour 78 | 79 | Return the start of an hour for the given date. 80 | 81 | ```js 82 | let startOfHour: Js.Date.t => Js.Date.t 83 | ``` 84 | 85 | ```js 86 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=16., ~minutes=50., ~seconds=10., ()); 87 | 88 | date->ReDate.startOfHour; 89 | ``` 90 | 91 | ### endOfHour 92 | 93 | Return the end of an hour for the given date. 94 | 95 | ```js 96 | let endOfHour: Js.Date.t => Js.Date.t 97 | ``` 98 | 99 | ```js 100 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=16., ~minutes=50., ~seconds=10., ()); 101 | 102 | date->ReDate.endOfHour; 103 | ``` 104 | 105 | ### isSameHour 106 | 107 | Are the given dates in the same hour? 108 | 109 | ```js 110 | let isSameHour: (Js.Date.t, Js.Date.t) => bool 111 | ``` 112 | 113 | ```js 114 | let fstDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=16., ~minutes=50., ~seconds=10., ()); 115 | let sndDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=16., ~minutes=0., ~seconds=0., ()); 116 | 117 | fstDate->ReDate.isSameHour(sndDate); 118 | ``` 119 | -------------------------------------------------------------------------------- /docs/api/interval.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: interval 3 | title: Interval 4 | --- 5 | 6 | ```js 7 | type interval = { 8 | start: Js.Date.t, 9 | end_: Js.Date.t, 10 | } 11 | ``` 12 | 13 | ### isWithinInterval 14 | 15 | Is the given date within the interval? 16 | 17 | ```js 18 | let isWithinInterval: (Js.Date.t, interval) => bool 19 | ``` 20 | 21 | ```js 22 | let interval = { 23 | start: Js.Date.makeWithYMD(~year=2018., ~month=3., ~date=1., ()), 24 | end_: Js.Date.makeWithYMD(~year=2018., ~month=4., ~date=10., ()), 25 | } 26 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=5., ()) 27 | 28 | date->ReDate.isWithinInterval(interval) 29 | ``` 30 | 31 | ### areIntervalsOverlapping 32 | 33 | the given time interval overlapping with another time interval? 34 | 35 | ```js 36 | let areIntervalsOverlapping: (interval, interval) => bool 37 | ``` 38 | 39 | ```js 40 | let interval = { 41 | start: Js.Date.makeWithYMD(~year=2018., ~month=3., ~date=1., ()), 42 | end_: Js.Date.makeWithYMD(~year=2018., ~month=4., ~date=10., ()), 43 | } 44 | let includedInterval = { 45 | start: makeWithYMD(~year=2018., ~month=3., ~date=5., ()), 46 | end_: makeWithYMD(~year=2018., ~month=4., ~date=5., ()), 47 | } 48 | 49 | interval->ReDate.areIntervalsOverlapping(includedInterval) 50 | ``` 51 | 52 | ### getOverlappingDaysInIntervals 53 | 54 | Get the number of days that overlap in two time intervals. 55 | 56 | ```js 57 | let getOverlappingDaysInIntervals: (interval, interval) => float 58 | ``` 59 | 60 | ```js 61 | let interval = { 62 | start: Js.Date.makeWithYMD(~year=2018., ~month=3., ~date=1., ()), 63 | end_: Js.Date.makeWithYMD(~year=2018., ~month=4., ~date=10., ()), 64 | } 65 | let includedInterval = { 66 | start: Js.Date.makeWithYMD(~year=2018., ~month=3., ~date=5., ()), 67 | end_: Js.Date.makeWithYMD(~year=2018., ~month=3., ~date=15., ()), 68 | } 69 | 70 | interval->ReDate.getOverlappingDaysInIntervals(includedInterval) 71 | ``` 72 | 73 | ### eachDayOfInterval 74 | 75 | Return the array of dates within the specified time interval. 76 | 77 | ```js 78 | let eachDayOfInterval: interval => array 79 | ``` 80 | 81 | ```js 82 | let interval = { 83 | start: Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=22., ()), 84 | end_: Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=5., ~hours=8., ~minutes=45., ~seconds=15., ()), 85 | } 86 | 87 | interval->ReDate.eachDayOfInterval 88 | ``` 89 | -------------------------------------------------------------------------------- /docs/api/iso-week-numbering.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: iso-week-numbering 3 | title: ISO Week Numbering 4 | --- 5 | 6 | :::info 7 | ISO week date: http://en.wikipedia.org/wiki/ISO_week_date 8 | ::: 9 | 10 | ### getISOWeekYear 11 | 12 | Get the ISO week-numbering year of the given date, which always starts 3 days before the year's first Thursday. 13 | 14 | ```js 15 | let getISOWeekYear: Js.Date.t => float 16 | ``` 17 | 18 | ```js 19 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=12., ~hours=16., ~minutes=50., ~seconds=12., ()) 20 | 21 | date->ReDate.getISOWeekYear 22 | ``` 23 | 24 | ### startOfISOWeekYear 25 | 26 | Return the start of an ISO week-numbering year, which always starts 3 days before the year's first Thursday. The result will be in the local timezone. 27 | 28 | ```js 29 | let startOfISOWeekYear: Js.Date.t => Js.Date.t 30 | ``` 31 | 32 | ```js 33 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=12., ~hours=16., ~minutes=50., ~seconds=12., ()) 34 | 35 | date->ReDate.startOfISOWeekYear 36 | ``` 37 | -------------------------------------------------------------------------------- /docs/api/iso-week.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: iso-week 3 | title: ISO Week 4 | --- 5 | 6 | :::info 7 | ISO week date: http://en.wikipedia.org/wiki/ISO_week_date 8 | ::: 9 | 10 | ### endOfISOWeek 11 | 12 | Return the end of a week for the given date. 13 | 14 | ```js 15 | let endOfISOWeek: Js.Date.t => Js.Date.t 16 | ``` 17 | 18 | ```js 19 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=10., ~hours=16., ~minutes=50., ~seconds=12., ()) 20 | 21 | date->ReDate.endOfISOWeek 22 | ``` 23 | 24 | ### getISOWeek 25 | 26 | Get the ISO week of the given date. 27 | 28 | ```js 29 | let getISOWeek: Js.Date.t => float 30 | ``` 31 | 32 | ```js 33 | let date = Js.Date.makeWithYMDHMS(~year=2005., ~month=0., ~date=2., ~hours=16., ~minutes=50., ~seconds=12., ()) 34 | 35 | date->ReDate.getISOWeek 36 | ``` 37 | 38 | ### isSameISOWeek 39 | 40 | Are the given dates in the same ISO week? 41 | 42 | ```js 43 | let isSameISOWeek: (Js.Date.t, Js.Date.t) => bool 44 | ``` 45 | 46 | ```js 47 | let fstDate = Js.Date.makeWithYMDHMS(~year=2005., ~month=11., ~date=31., ~hours=16., ~minutes=50., ~seconds=12., ()) 48 | let sndDate = Js.Date.makeWithYMDHMS(~year=2006., ~month=0., ~date=1., ~hours=10., ~minutes=15., ~seconds=55., ()) 49 | 50 | fstDate->ReDate.isSameISOWeek(sndDate) 51 | ``` 52 | 53 | ### isThisISOWeek 54 | 55 | Is the given date in the same ISO week as the current date? 56 | 57 | ```js 58 | let isThisISOWeek: Js.Date.t => bool 59 | ``` 60 | 61 | ```js 62 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=12., ~hours=16., ~minutes=50., ~seconds=12., ()) 63 | 64 | date->ReDate.isThisISOWeek 65 | ``` 66 | 67 | ### lastDayOfISOWeek 68 | 69 | Return the last day of an ISO week for the given date. The result will be in the local timezone. 70 | 71 | ```js 72 | let lastDayOfISOWeek: Js.Date.t => bool 73 | ``` 74 | 75 | ```js 76 | let date = Js.Date.makeWithYMDHMS(~year=2014., ~month=8., ~date=2., ~hours=11., ~minutes=55., ~seconds=12., ()) 77 | 78 | date->ReDate.lastDayOfISOWeek 79 | ``` 80 | 81 | ### setISOWeek 82 | 83 | Set the ISO week for the given date, preserving the weekday number. A new date will be returned, the original date will not be changed. 84 | 85 | ```js 86 | let setISOWeek: (Js.Date.t, float) => Js.Date.t 87 | ``` 88 | 89 | ```js 90 | let date = Js.Date.makeWithYMD(~year=2004., ~month=7., ~date=7., ()) 91 | 92 | date->ReDate.setISOWeek(53.) 93 | ``` 94 | 95 | ### startOfISOWeek 96 | 97 | Return the start of an ISO week for the given date. The result will be in the local timezone. 98 | 99 | ```js 100 | let startOfISOWeek: Js.Date.t => Js.Date.t 101 | ``` 102 | 103 | ```js 104 | let date = Js.Date.makeWithYMDHMS(~year=2014., ~month=8., ~date=2., ~hours=11., ~minutes=55., ~seconds=0., ()) 105 | 106 | date->ReDate.startOfISOWeek 107 | ``` 108 | 109 | ### differenceInCalendarISOWeeks 110 | 111 | Get the number of calendar ISO weeks between the given dates. 112 | 113 | ```js 114 | let differenceInCalendarISOWeeks: (Js.Date.t, Js.Date.t) => int 115 | ``` 116 | 117 | ```js 118 | let fstDate = Js.Date.makeWithYMDHMS(~year=2014., ~month=6., ~date=21., ~hours=23., ~minutes=59., ~seconds=59., ()) 119 | let sndDate = Js.Date.makeWithYMDHMS(~year=2014., ~month=6., ~date=6., ~hours=0., ~minutes=0., ~seconds=0., ()) 120 | 121 | fstDate->ReDate.differenceInCalendarISOWeeks(sndDate) 122 | ``` 123 | -------------------------------------------------------------------------------- /docs/api/minute.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: minute 3 | title: Minute 4 | --- 5 | 6 | ### addMinutes 7 | 8 | Add the specified number of minutes to the given date. 9 | 10 | ```js 11 | let addMinutes: (Js.Date.t, float) => Js.Date.t 12 | ``` 13 | 14 | ```js 15 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=30., ()) 16 | 17 | date->ReDate.addMinutes(1) 18 | ``` 19 | 20 | ### subMinutes 21 | 22 | Subtract the specified number of minutes from the given date. 23 | 24 | ```js 25 | let subMinutes: (Js.Date.t, float) => Js.Date.t 26 | ``` 27 | 28 | ```js 29 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=30., ()) 30 | 31 | date->ReDate.subMinutes(1) 32 | ``` 33 | 34 | ### getMinutes 35 | 36 | Get the minutes of the given date. 37 | 38 | ```js 39 | let getMinutes: Js.Date.t => float 40 | ``` 41 | 42 | ```js 43 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=30., ()); 44 | 45 | date->ReDate.getMinutes 46 | ``` 47 | 48 | ### setMinutes 49 | 50 | Set the minutes to the given date. 51 | 52 | ```js 53 | let setMinutes: (Js.Date.t, float) => Js.Date.t 54 | ``` 55 | 56 | ```js 57 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=0., ()); 58 | 59 | date->ReDate.setMinutes(30.) 60 | ``` 61 | 62 | ### differenceInMinutes 63 | 64 | Get the number of minutes between the given dates. 65 | 66 | ```js 67 | let differenceInMinutes: (Js.Date.t, Js.Date.t) => float 68 | ``` 69 | 70 | ```js 71 | let fstDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=40., ~seconds=15., ()) 72 | let sndDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=0., ()) 73 | 74 | fstDate->ReDate.differenceInMinutes(sndDate) 75 | ``` 76 | 77 | ### startOfMinute 78 | 79 | Return the start of a minute for the given date. 80 | 81 | ```js 82 | let startOfMinute: Js.Date.t => Js.Date.t 83 | ``` 84 | 85 | ```js 86 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=8., ~date=10., ~hours=8., ~minutes=20., ~seconds=35., ()) 87 | 88 | date->ReDate.startOfMinute 89 | ``` 90 | 91 | ### endOfMinute 92 | 93 | Return the end of a minute for the given date. 94 | 95 | ```js 96 | let endOfMinute: Js.Date.t => Js.Date.t 97 | ``` 98 | 99 | ```js 100 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=8., ~date=10., ~hours=8., ~minutes=20., ~seconds=35., ()) 101 | 102 | date->ReDate.endOfMinute 103 | ``` 104 | 105 | ### isSameMinute 106 | 107 | Are the given dates in the same minute? 108 | 109 | ```js 110 | let isSameMinute: (Js.Date.t, Js.Date.t) => bool 111 | ``` 112 | 113 | ```js 114 | let fstDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=8., ~date=10., ~hours=19., ~minutes=6., ~seconds=10., ()) 115 | let sndDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=8., ~date=10., ~hours=19., ~minutes=6., ~seconds=35., ()) 116 | 117 | fstDate->ReDate.isSameMinute(sndDate) 118 | ``` 119 | 120 | ### roundToNearestMinute 121 | 122 | Rounds the given date to the nearest minute. 123 | 124 | ```js 125 | let roundToNearestMinute: (~nearestTo: float=?, Js.Date.t) => Js.Date.t 126 | ``` 127 | 128 | ```js 129 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=8., ~date=10., ~hours=19., ~minutes=6., ~seconds=31., ()) 130 | 131 | date->ReDate.roundToNearestMinute 132 | ``` 133 | 134 | ```js 135 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=8., ~date=10., ~hours=19., ~minutes=12., ~seconds=10., ()) 136 | let roundToNearest15Minute = ReDate.roundToNearestMinute(~nearestTo=15.) 137 | 138 | date->roundToNearest15Minute 139 | ``` 140 | -------------------------------------------------------------------------------- /docs/api/month.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: month 3 | title: Month 4 | --- 5 | 6 | ### addMonths 7 | 8 | Add the specified number of months to the given date. 9 | 10 | ```js 11 | let addMonths: (Js.Date.t, float) => Js.Date.t 12 | ``` 13 | 14 | ```js 15 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 16 | 17 | date->ReDate.addMonths(1.) 18 | ``` 19 | 20 | ### subMonths 21 | 22 | Subtract the specified number of months from the given date. 23 | 24 | ```js 25 | let subMonths: (Js.Date.t, float) => Js.Date.t 26 | ``` 27 | 28 | ```js 29 | let date = Js.Date.makeWithYMD(~year=2018., ~month=1., ~date=1., ()) 30 | 31 | date->ReDate.subMonths(1.) 32 | ``` 33 | 34 | ### getMonth 35 | 36 | Get the month of the given date. 37 | 38 | ```js 39 | let getMonth: Js.Date.t => float 40 | ``` 41 | 42 | ```js 43 | let date = Js.Date.makeWithYMD(~year=2019., ~month=4., ~date=1., ()) 44 | 45 | date->ReDate.getMonth 46 | ``` 47 | 48 | ### setMonth 49 | 50 | Set the month to the given date. 51 | 52 | ```js 53 | let setMonth: (Js.Date.t, float) => Js.Date.t 54 | ``` 55 | 56 | ```js 57 | let date = Js.Date.makeWithYMD(~year=2019., ~month=4., ~date=1., ()) 58 | 59 | date->ReDate.setMonth(5.) 60 | ``` 61 | 62 | ### differenceInCalendarMonths 63 | 64 | Get the number of calendar months between the given dates. 65 | 66 | ```js 67 | let differenceInCalendarMonths: (Js.Date.t, Js.Date.t) => float 68 | ``` 69 | 70 | ```js 71 | let fstDate = Js.Date.makeWithYMD(~year=2019., ~month=5., ~date=1., ()) 72 | let sndDate = Js.Date.makeWithYMD(~year=2018., ~month=1., ~date=1., ()) 73 | 74 | fstDate->ReDate.differenceInCalendarMonths(sndDate) 75 | ``` 76 | 77 | ### differenceInMonths 78 | 79 | Get the number of full months between the given dates. 80 | 81 | ```js 82 | let differenceInMonths: (Js.Date.t, Js.Date.t) => float 83 | ``` 84 | 85 | ```js 86 | let fstDate = Js.Date.makeWithYMD(~year=2018., ~month=7., ~date=1., ()) 87 | let sndDate = Js.Date.makeWithYMD(~year=2018., ~month=6., ~date=31., ()) 88 | 89 | fstDate->ReDate.differenceInMonths(sndDate) 90 | ``` 91 | 92 | ### startOfMonth 93 | 94 | Return the start of a month for the given date. 95 | 96 | ```js 97 | let startOfMonth: Js.Date.t => Js.Date.t 98 | ``` 99 | 100 | ```js 101 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=24., ~hours=16., ~minutes=50., ~seconds=12., ()) 102 | 103 | date->ReDate.startOfMonth 104 | ``` 105 | 106 | ### endOfMonth 107 | 108 | Return the end of a month for the given date. 109 | 110 | ```js 111 | let endOfMonth: Js.Date.t => Js.Date.t 112 | ``` 113 | 114 | ```js 115 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=24., ~hours=16., ~minutes=50., ~seconds=12., ()) 116 | 117 | date->ReDate.endOfMonth 118 | ``` 119 | 120 | ### isFirstDayOfMonth 121 | 122 | Is the given date the first day of a month? 123 | 124 | ```js 125 | let isFirstDayOfMonth: Js.Date.t => bool 126 | ``` 127 | 128 | ```js 129 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 130 | 131 | date->ReDate.isFirstDayOfMonth 132 | ``` 133 | 134 | ### isLastDayOfMonth 135 | 136 | Is the given date the last day of a month? 137 | 138 | ```js 139 | let isLastDayOfMonth: Js.Date.t => bool 140 | ``` 141 | 142 | ```js 143 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=31., ()) 144 | 145 | date->ReDate.isLastDayOfMonth 146 | ``` 147 | 148 | ### isSameMonth 149 | 150 | Are the given dates in the same month? 151 | 152 | ```js 153 | let isSameMonth: (Js.Date.t, Js.Date.t) => bool 154 | ``` 155 | 156 | ```js 157 | let fstDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 158 | let sndDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=24., ()) 159 | 160 | fstDate->ReDate.isSameMonth(sndDate) 161 | ``` 162 | 163 | ### lastDayOfMonth 164 | 165 | Return the last day of a month for the given date. 166 | 167 | ```js 168 | let lastDayOfMonth: Js.Date.t => Js.Date.t 169 | ``` 170 | 171 | ```js 172 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=12., ()) 173 | 174 | date->ReDate.lastDayOfMonth 175 | ``` 176 | 177 | ### getDaysInMonth 178 | 179 | Get the number of days in a month of the given date. 180 | 181 | ```js 182 | let getDaysInMonth: Js.Date.t => float 183 | ``` 184 | 185 | ```js 186 | let date = Js.Date.makeWithYMD(~year=2018., ~month=10., ~date=10., ()) 187 | 188 | date->ReDate.getDaysInMonth 189 | ``` 190 | -------------------------------------------------------------------------------- /docs/api/second.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: second 3 | title: Second 4 | --- 5 | 6 | ### addSeconds 7 | 8 | Add the specified number of seconds to the given date. 9 | 10 | ```js 11 | let addSeconds: (Js.Date.t, float) => Js.Date.t 12 | ``` 13 | 14 | ```js 15 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=0., ()); 16 | 17 | date->ReDate.addSeconds(1.); 18 | ``` 19 | 20 | ### subSeconds 21 | 22 | Subtract the specified number of seconds from the given date. 23 | 24 | ```js 25 | let subSeconds: (Js.Date.t, float) => Js.Date.t 26 | ``` 27 | 28 | ```js 29 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=0., ()); 30 | 31 | date->ReDate.subSeconds(1.); 32 | ``` 33 | 34 | ### getSeconds 35 | 36 | Get the seconds of the given date. 37 | 38 | ```js 39 | let getSeconds: Js.Date.t => float 40 | ``` 41 | 42 | ```js 43 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=30., ()); 44 | 45 | date->ReDate.getSeconds 46 | ``` 47 | 48 | ### setSeconds 49 | 50 | Set the seconds to the given date. 51 | 52 | ```js 53 | let setSeconds: (Js.Date.t, float) => Js.Date.t 54 | ``` 55 | 56 | ```js 57 | let date = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=0., ()); 58 | 59 | date->ReDate.setSeconds(30.) 60 | ``` 61 | 62 | ### differenceInSeconds 63 | 64 | Get the number of seconds between the given dates. 65 | 66 | ```js 67 | let differenceInSeconds: (Js.Date.t, Js.Date.t) => float 68 | ``` 69 | 70 | ```js 71 | let fstDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=40., ~seconds=15., ()); 72 | let sndDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=19., ~minutes=30., ~seconds=0., ()); 73 | 74 | fstDate->ReDate.differenceInSeconds(sndDate); 75 | ``` 76 | 77 | ### startOfSecond 78 | 79 | Return the start of a second for the given date. 80 | 81 | ```js 82 | let startOfSecond: Js.Date.t => Js.Date.t 83 | ``` 84 | 85 | ```js 86 | let date = 87 | Js.Date.setMilliseconds( 88 | Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=16., ~minutes=50., ~seconds=10., ()), 89 | 423., 90 | ) 91 | ->fromFloat; 92 | 93 | date->ReDate.startOfSecond; 94 | ``` 95 | 96 | ### endOfSecond 97 | 98 | Return the end of a second for the given date. 99 | 100 | ```js 101 | let endOfSecond: Js.Date.t => Js.Date.t 102 | ``` 103 | 104 | ```js 105 | let date = 106 | Js.Date.setMilliseconds( 107 | Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=16., ~minutes=50., ~seconds=10., ()), 108 | 423., 109 | ) 110 | ->fromFloat; 111 | 112 | date->ReDate.endOfSecond; 113 | ``` 114 | 115 | ### isSameSecond 116 | 117 | Are the given dates in the same second? 118 | 119 | ```js 120 | let isSameSecond: (Js.Date.t, Js.Date.t) => bool 121 | ``` 122 | 123 | ```js 124 | let fstDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=23., ~minutes=59., ~seconds=59., ()); 125 | let sndDate = Js.Date.makeWithYMDHMS(~year=2018., ~month=0., ~date=1., ~hours=23., ~minutes=59., ~seconds=58., ()); 126 | 127 | fstDate->ReDate.isSameSecond(sndDate) 128 | ``` 129 | -------------------------------------------------------------------------------- /docs/api/week-numbering.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: week-numbering 3 | title: Week Numbering 4 | --- 5 | 6 | ```js 7 | type day = 8 | | Sunday 9 | | Monday 10 | | Tuesday 11 | | Wednesday 12 | | Thursday 13 | | Friday 14 | | Saturday 15 | ``` 16 | 17 | ### getWeekYear 18 | 19 | Get the local week-numbering year of the given date. 20 | 21 | ```js 22 | let getWeekYear: (~weekStartsOn: day=?, Js.Date.t) => float 23 | ``` 24 | 25 | ```js 26 | let date = Js.Date.makeWithYMD(~year=2018., ~month=4., ~date=10., ()) 27 | 28 | date->ReDate.getWeekYear 29 | ``` 30 | 31 | ```js 32 | let date = Js.Date.makeWithYMD(~year=2018., ~month=10., ~date=14., ()) 33 | let getWeekYear = ReDate.getWeekYear(~weekStartsOn=Monday) 34 | 35 | date->getWeekYear 36 | ``` 37 | 38 | ### startOfWeekYear 39 | 40 | Return the start of a local week-numbering year. 41 | 42 | ```js 43 | let startOfWeekYear: (~weekStartsOn: day=?, Js.Date.t) => Js.Date.t 44 | ``` 45 | 46 | ```js 47 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=12., ()) 48 | 49 | date->ReDate.startOfWeekYear 50 | ``` 51 | 52 | ```js 53 | let date = Js.Date.makeWithYMD(~year=2018., ~month=10., ~date=14., ()) 54 | let startOfWeekYear = ReDate.startOfWeekYear(~weekStartsOn=Monday) 55 | 56 | date->startOfWeekYear 57 | ``` 58 | -------------------------------------------------------------------------------- /docs/api/weekday.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: weekday 3 | title: Weekday 4 | --- 5 | 6 | ```js 7 | type day = 8 | | Sunday 9 | | Monday 10 | | Tuesday 11 | | Wednesday 12 | | Thursday 13 | | Friday 14 | | Saturday 15 | ``` 16 | 17 | ### getDay 18 | 19 | Get the day of the week of the given date. 20 | 21 | ```js 22 | let getDay: Js.Date.t => day 23 | ``` 24 | 25 | ```js 26 | let date = Js.Date.makeWithYMD(~year=2021., ~month=11., ~date=10., ()) 27 | 28 | date->ReDate.getDay 29 | ``` 30 | 31 | ### isSunday 32 | 33 | Is the given date Sunday? 34 | 35 | ```js 36 | let isSunday: Js.Date.t => bool 37 | ``` 38 | 39 | ```js 40 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=7., ()) 41 | 42 | date->ReDate.isSunday 43 | ``` 44 | 45 | ### isMonday 46 | 47 | Is the given date Monday? 48 | 49 | ```js 50 | let isMonday: Js.Date.t => bool 51 | ``` 52 | 53 | ```js 54 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=8., ()) 55 | 56 | date->ReDate.isMonday 57 | ``` 58 | 59 | ### isTuesday 60 | 61 | Is the given date Tuesday? 62 | 63 | ```js 64 | let isTuesday: Js.Date.t => bool 65 | ``` 66 | 67 | ```js 68 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=9., ()) 69 | 70 | date->ReDate.isTuesday 71 | ``` 72 | 73 | ### isWednesday 74 | 75 | Is the given date Wednesday? 76 | 77 | ```js 78 | let isWednesday: Js.Date.t => bool 79 | ``` 80 | 81 | ```js 82 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=10., ()) 83 | 84 | date->ReDate.isWednesday 85 | ``` 86 | 87 | ### isThursday 88 | 89 | Is the given date Thursday? 90 | 91 | ```js 92 | let isThursday: Js.Date.t => bool 93 | ``` 94 | 95 | ```js 96 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=11., ()) 97 | 98 | date->ReDate.isThursday 99 | ``` 100 | 101 | ### isFriday 102 | 103 | Is the given date Friday? 104 | 105 | ```js 106 | let isFriday: Js.Date.t => bool 107 | ``` 108 | 109 | ```js 110 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=12., ()) 111 | 112 | date->ReDate.isFriday 113 | ``` 114 | 115 | ### isSaturday 116 | 117 | Is the given date Saturday? 118 | 119 | ```js 120 | let isSaturday: Js.Date.t => bool 121 | ``` 122 | 123 | ```js 124 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=13., ()) 125 | 126 | date->ReDate.isSaturday 127 | ``` 128 | 129 | ### isWeekend 130 | 131 | Does the given date fall on a weekend? 132 | 133 | ```js 134 | let isWeekend: Js.Date.t => bool 135 | ``` 136 | 137 | ```js 138 | let date = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=13., ()) 139 | 140 | date->ReDate.isWeekend 141 | ``` 142 | 143 | ### isWeekDay 144 | 145 | Is the day of the week of the given date same as the provided day? 146 | 147 | ```js 148 | let isWeekDay: (Js.Date.t, day) => bool 149 | ``` 150 | 151 | ```js 152 | let date = Js.Date.makeWithYMD(~year=2021., ~month=11., ~date=10., ()) 153 | 154 | date->ReDate.isWeekDay(ReDate.Friday) 155 | ``` 156 | -------------------------------------------------------------------------------- /docs/api/year.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: year 3 | title: Year 4 | --- 5 | 6 | ### addYears 7 | 8 | Add the specified number of years to the given date. 9 | 10 | ```js 11 | let addYears: (Js.Date.t, float) => Js.Date.t 12 | ``` 13 | 14 | ```js 15 | let date = Js.Date.makeWithYMD(~year=2018., ~month=4., ~date=1., ()) 16 | 17 | date->ReDate.addYears(1.) 18 | ``` 19 | 20 | ### subYears 21 | 22 | Subtract the specified number of years from the given date. 23 | 24 | ```js 25 | let subYears: (Js.Date.t, float) => Js.Date.t 26 | ``` 27 | 28 | ```js 29 | let date = Js.Date.makeWithYMD(~year=2019., ~month=4., ~date=1., ()) 30 | 31 | date->ReDate.subYears(1.) 32 | ``` 33 | 34 | ### getYear 35 | 36 | Get the year of the given date. 37 | 38 | ```js 39 | let getYear: Js.Date.t => float 40 | ``` 41 | 42 | ```js 43 | let date = Js.Date.makeWithYMD(~year=2019., ~month=4., ~date=1., ()) 44 | 45 | date->ReDate.getYear 46 | ``` 47 | 48 | ### setYear 49 | 50 | Set the year to the given date. 51 | 52 | ```js 53 | let setYear: (Js.Date.t, float) => Js.Date.t 54 | ``` 55 | 56 | ```js 57 | let date = Js.Date.makeWithYMD(~year=2019., ~month=4., ~date=1., ()) 58 | 59 | date->ReDate.setYear(2021.) 60 | ``` 61 | 62 | ### startOfYear 63 | 64 | Return the start of a year for the given date. 65 | 66 | ```js 67 | let startOfYear: Js.Date.t => Js.Date.t 68 | ``` 69 | 70 | ```js 71 | let date = Js.Date.makeWithYMD(~year=2018., ~month=5., ~date=1., ()) 72 | 73 | date->ReDate.startOfYear 74 | ``` 75 | 76 | ### endOfYear 77 | 78 | Return the end of a year for the given date. 79 | 80 | ```js 81 | let endOfYear: Js.Date.t => Js.Date.t 82 | ``` 83 | 84 | ```js 85 | let date = Js.Date.makeWithYMD(~year=2018., ~month=8., ~date=10., ()) 86 | 87 | date->ReDate.endOfYear 88 | ``` 89 | 90 | ### isSameYear 91 | 92 | Are the given dates in the same year? 93 | 94 | ```js 95 | let isSameYear: (Js.Date.t, Js.Date.t) => bool 96 | ``` 97 | 98 | ```js 99 | let fstDate = Js.Date.makeWithYMD(~year=2018., ~month=8., ~date=10., ()) 100 | let sndDate = Js.Date.makeWithYMD(~year=2018., ~month=6., ~date=20., ()) 101 | 102 | fstDate->ReDate.isSameYear(sndDate) 103 | ``` 104 | 105 | ### isLeapYear 106 | 107 | Is the given date in the leap year? 108 | 109 | ```js 110 | let isLeapYear: Js.Date.t => bool 111 | ``` 112 | 113 | ```js 114 | let date = Js.Date.makeWithYMD(~year=2020., ~month=8., ~date=10., ()) 115 | 116 | date->ReDate.isLeapYear 117 | ``` 118 | 119 | ### lastMonthOfYear 120 | 121 | Return the last month of a year for the given date. 122 | 123 | ```js 124 | let lastMonthOfYear: Js.Date.t => Js.Date.t 125 | ``` 126 | 127 | ```js 128 | let date = Js.Date.makeWithYMD(~year=2018., ~month=8., ~date=10., ()) 129 | 130 | date->ReDate.lastMonthOfYear 131 | ``` 132 | 133 | ### lastDayOfYear 134 | 135 | Return the last day of a year for the given date. 136 | 137 | ```js 138 | let lastDayOfYear: Js.Date.t => Js.Date.t 139 | ``` 140 | 141 | ```js 142 | let date = Js.Date.makeWithYMD(~year=2018., ~month=8., ~date=10., ()) 143 | 144 | date->ReDate.lastDayOfYear 145 | ``` 146 | 147 | ### getDaysInYear 148 | 149 | Get the number of days in a year of the given date. 150 | 151 | ```js 152 | let getDaysInYear: Js.Date.t => float 153 | ``` 154 | 155 | ```js 156 | let date = Js.Date.makeWithYMD(~year=2018., ~month=10., ~date=10., ()) 157 | 158 | date->ReDate.getDaysInYear 159 | ``` 160 | 161 | ### differenceInCalendarYears 162 | 163 | Get the number of calendar years between the given dates. 164 | 165 | ```js 166 | let differenceInCalendarYears: (Js.Date.t, Js.Date.t) => float 167 | ``` 168 | 169 | ```js 170 | let fstDate = Js.Date.makeWithYMD(~year=2020., ~month=5., ~date=1., ()) 171 | let sndDate = Js.Date.makeWithYMD(~year=2018., ~month=1., ~date=1., ()) 172 | 173 | fstDate->ReDate.differenceInCalendarYears(sndDate) 174 | ``` 175 | 176 | ### differenceInYears 177 | 178 | Get the number of full years between the given dates. 179 | 180 | ```js 181 | let differenceInYears: (Js.Date.t, Js.Date.t) => float 182 | ``` 183 | 184 | ```js 185 | let fstDate = Js.Date.makeWithYMD(~year=2018., ~month=0., ~date=1., ()) 186 | let sndDate = Js.Date.makeWithYMD(~year=2016., ~month=0., ~date=1., ()) 187 | 188 | fstDate->ReDate.differenceInYears(sndDate) 189 | ``` 190 | -------------------------------------------------------------------------------- /docs/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 3 | }; 4 | -------------------------------------------------------------------------------- /docs/docs/changelog.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: changelog 3 | title: Changelog 4 | --- 5 | 6 | ### `v2.1.0` 7 | 8 | - ✨ added [`getDay`](/api/weekday#getday) 9 | - ✨ added [`isWeekDay`](/api/weekday#isweekday) 10 | 11 | ### `v2.0.0` 12 | 13 | Use a pipe-first (`->`) operator instead of deprecated pipe-forward (`|>`). 14 | 15 | Learn more: https://rescript-lang.org/docs/manual/v8.0.0/pipe#triangle-pipe-deprecated 16 | 17 | ### `v1.0.0` 18 | 19 | Initial ReScript implementation. 20 | -------------------------------------------------------------------------------- /docs/docs/installation.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: installation 3 | title: Installation 4 | slug: / 5 | --- 6 | 7 | Use either `npm` or `yarn` to install the package: 8 | 9 | ```shell 10 | yarn add @mobily/rescript-date 11 | ``` 12 | 13 | ```shell 14 | npm install @mobily/rescript-date --save 15 | ``` 16 | 17 | ### ReScript Config 18 | 19 | Add `@mobily/rescript-date` to `bs-dependencies` in your `bsconfig.json`: 20 | 21 | ```json 22 | { 23 | "bs-dependencies": [ 24 | "@mobily/rescript-date" 25 | ] 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /docs/docs/status.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: status 3 | title: Status 4 | --- 5 | 6 | ### Common 7 | 8 | - [x] `isEqual` 9 | - [x] `isBefore` 10 | - [x] `isAfter` 11 | - [x] `isFuture` 12 | - [x] `isPast` 13 | - [x] `compareAsc` 14 | - [x] `compareDesc` 15 | - [x] `max` 16 | - [x] `min` 17 | - [x] `closestTo` 18 | - [ ] `closestIndexTo` 19 | - [x] `isValid` 20 | 21 | ### Conversion 22 | 23 | - [ ] `daysToWeeks` 24 | - [ ] `hoursToMilliseconds` 25 | - [ ] `hoursToMinutes` 26 | - [ ] `hoursToSeconds` 27 | - [ ] `millisecondsToHours` 28 | - [ ] `millisecondsToMinutes` 29 | - [ ] `millisecondsToSeconds` 30 | - [ ] `minutesToHours` 31 | - [ ] `minutesToMilliseconds` 32 | - [ ] `minutesToSeconds` 33 | - [ ] `monthsToQuarters` 34 | - [ ] `monthsToYears` 35 | - [ ] `quartersToMonths` 36 | - [ ] `quartersToYears` 37 | - [ ] `secondsToHours` 38 | - [ ] `secondsToMilliseconds` 39 | - [ ] `secondsToMinutes` 40 | - [ ] `weeksToDays` 41 | - [ ] `yearsToMonths` 42 | - [ ] `yearsToQuarters` 43 | 44 | ### Interval 45 | 46 | - [x] `isWithinInterval` 47 | - [x] `areIntervalsOverlapping` 48 | - [x] `getOverlappingDaysInIntervals` 49 | - [x] `eachDayOfInterval` 50 | - [ ] `eachHourOfInterval` 51 | - [ ] `eachMinuteOfInterval` 52 | - [ ] `eachMonthOfInterval` 53 | - [ ] `eachQuarterOfInterval` 54 | - [ ] `eachWeekOfInterval` 55 | - [ ] `eachWeekendOfInterval` 56 | - [ ] `eachYearOfInterval` 57 | 58 | ### Millisecond 59 | 60 | - [ ] `addMilliseconds` 61 | - [ ] `differenceInMilliseconds` 62 | - [ ] `getMilliseconds` 63 | - [ ] `milliseconds` 64 | - [ ] `setMilliseconds` 65 | - [ ] `subMilliseconds` 66 | 67 | ### Second 68 | 69 | - [x] `addSeconds` 70 | - [x] `subSeconds` 71 | - [x] `differenceInSeconds` 72 | - [x] `startOfSecond` 73 | - [x] `endOfSecond` 74 | - [x] `isSameSecond` 75 | - [ ] `isThisSecond` 76 | - [x] `getSeconds` 77 | - [x] `setSeconds` 78 | 79 | ### Minute 80 | 81 | - [x] `addMinutes` 82 | - [x] `subMinutes` 83 | - [x] `differenceInMinutes` 84 | - [x] `startOfMinute` 85 | - [x] `endOfMinute` 86 | - [x] `isSameMinute` 87 | - [ ] `isThisMinute` 88 | - [x] `roundToNearestMinute` 89 | - [x] `getMinutes` 90 | - [x] `setMinutes` 91 | 92 | ### Hour 93 | 94 | - [x] `addHours` 95 | - [x] `subHours` 96 | - [x] `differenceInHours` 97 | - [x] `startOfHour` 98 | - [x] `endOfHour` 99 | - [x] `isSameHour` 100 | - [ ] `isThisHour` 101 | - [x] `getHours` 102 | - [x] `setHours` 103 | 104 | ### Day 105 | 106 | - [x] `addBusinessDays` 107 | - [x] `addDays` 108 | - [x] `subDays` 109 | - [x] `differenceInBusinessDays` 110 | - [x] `differenceInDays` 111 | - [x] `differenceInCalendarDays` 112 | - [x] `startOfDay` 113 | - [x] `endOfDay` 114 | - [ ] `endOfToday` 115 | - [ ] `endOfTomorrow` 116 | - [ ] `endOfYesterday` 117 | - [x] `getDayOfYear` 118 | - [ ] `setDayOfYear` 119 | - [x] `isSameDay` 120 | - [x] `isToday` 121 | - [x] `isTomorrow` 122 | - [x] `isYesterday` 123 | - [x] `getDate` 124 | - [x] `setDate` 125 | 126 | ### Week 127 | 128 | - [x] `addWeeks` 129 | - [x] `subWeeks` 130 | - [x] `differenceInWeeks` 131 | - [x] `differenceInCalendarWeeks` 132 | - [x] `startOfWeek` 133 | - [x] `endOfWeek` 134 | - [x] `isSameWeek` 135 | - [ ] `isThisWeek` 136 | - [x] `lastDayOfWeek` 137 | - [x] `getWeek` 138 | - [x] `getWeekOfMonth` 139 | - [x] `getWeeksInMonth` 140 | - [ ] `setWeek` 141 | 142 | ### Week numbering 143 | 144 | - [x] `getWeekYear` 145 | - [ ] `setWeekYear` 146 | - [x] `startOfWeekYear` 147 | 148 | ### Weekday 149 | 150 | - [x] `getDay` 151 | - [ ] `getISODay` 152 | - [x] `isMonday` 153 | - [x] `isTuesday` 154 | - [x] `isWednesday` 155 | - [x] `isThursday` 156 | - [x] `isFriday` 157 | - [x] `isSaturday` 158 | - [x] `isSunday` 159 | - [x] `isWeekend` 160 | - [ ] `setDay` 161 | - [ ] `setISODay` 162 | 163 | ### Month 164 | 165 | - [x] `addMonths` 166 | - [x] `subMonths` 167 | - [x] `differenceInMonths` 168 | - [x] `differenceInCalendarMonths` 169 | - [x] `startOfMonth` 170 | - [x] `endOfMonth` 171 | - [x] `getDaysInMonth` 172 | - [x] `isFirstDayOfMonth` 173 | - [x] `isLastDayOfMonth` 174 | - [x] `isSameMonth` 175 | - [ ] `isThisMonth` 176 | - [x] `lastDayOfMonth` 177 | - [x] `getMonth` 178 | - [x] `setMonth` 179 | - [ ] `eachWeekendOfMonth` 180 | 181 | ### Quarter 182 | 183 | - [ ] `addQuarters` 184 | - [ ] `differenceInCalendarQuarters` 185 | - [ ] `differenceInQuarters` 186 | - [ ] `endOfQuarter` 187 | - [ ] `isSameQuarter` 188 | - [ ] `isThisQuarter` 189 | - [ ] `lastDayOfQuarter` 190 | - [ ] `startOfQuarter` 191 | - [ ] `setQuarter` 192 | - [ ] `subQuarters` 193 | 194 | ### Year 195 | 196 | - [x] `addYears` 197 | - [x] `subYears` 198 | - [x] `differenceInYears` 199 | - [x] `differenceInCalendarYears` 200 | - [x] `startOfYear` 201 | - [x] `endOfYear` 202 | - [x] `getDaysInYear` 203 | - [x] `isLeapYear` 204 | - [x] `isSameYear` 205 | - [x] `lastMonthOfYear` 206 | - [x] `lastDayOfYear` 207 | - [x] `getYear` 208 | - [x] `setYear` 209 | - [ ] `eachWeekendOfYear` 210 | 211 | ### Decade 212 | 213 | - [ ] `getDecade` 214 | - [ ] `startOfDecade` 215 | - [ ] `endOfDecade` 216 | - [ ] `lastDayOfDecade` 217 | 218 | ### ISO week 219 | 220 | - [x] `endOfISOWeek` 221 | - [x] `getISOWeek` 222 | - [x] `isSameISOWeek` 223 | - [x] `isThisISOWeek` 224 | - [x] `lastDayOfISOWeek` 225 | - [x] `setISOWeek` 226 | - [x] `startOfISOWeek` 227 | - [x] `differenceInCalendarISOWeeks` 228 | 229 | ### ISO week numbering 230 | 231 | - [ ] `addISOWeekYears` 232 | - [ ] `differenceInCalendarISOWeekYears` 233 | - [ ] `differenceInISOWeekYears` 234 | - [ ] `endOfISOWeekYear` 235 | - [ ] `getISOWeeksInYear` 236 | - [x] `getISOWeekYear` 237 | - [ ] `isSameISOWeekYear` 238 | - [ ] `isThisISOWeekYear` 239 | - [ ] `lastDayOfISOWeekYear` 240 | - [ ] `setISOWeekYear` 241 | - [x] `startOfISOWeekYear` 242 | - [ ] `subISOWeekYears` 243 | -------------------------------------------------------------------------------- /docs/docusaurus.config.js: -------------------------------------------------------------------------------- 1 | const root = require('../package.json') 2 | 3 | module.exports = { 4 | title: 'rescript-date', 5 | tagline: 'Date manipulation in ReScript.', 6 | url: 'https://mobily.github.io', 7 | baseUrl: '/rescript-date/', 8 | onBrokenLinks: 'throw', 9 | onBrokenMarkdownLinks: 'warn', 10 | favicon: 'img/favicon.ico', 11 | organizationName: 'mobily', 12 | projectName: 'rescript-date', 13 | scripts: [ 14 | { 15 | src: 'https://cdn.splitbee.io/sb.js', 16 | async: true, 17 | }, 18 | ], 19 | themeConfig: { 20 | image: 'img/hero-logo.png', 21 | prism: { 22 | theme: require('prism-react-renderer/themes/github'), 23 | }, 24 | navbar: { 25 | title: `v${root.version}`, 26 | logo: { 27 | alt: 'rescript-date', 28 | src: 'img/rescript-date-logo.png', 29 | }, 30 | items: [ 31 | { 32 | to: 'docs', 33 | activeBasePath: 'docs', 34 | label: 'Docs', 35 | position: 'left', 36 | }, 37 | { 38 | to: 'api/common', 39 | activeBasePath: 'api', 40 | label: 'API', 41 | position: 'left', 42 | }, 43 | { 44 | href: 'https://www.buymeacoffee.com/utSC0k7', 45 | label: 'Buy me a coffee ❤️', 46 | position: 'right', 47 | }, 48 | { 49 | href: 'https://github.com/mobily/rescript-date', 50 | position: 'right', 51 | className: 'header-github-link', 52 | }, 53 | ], 54 | }, 55 | footer: { 56 | style: 'light', 57 | links: [ 58 | { 59 | title: 'Github', 60 | items: [ 61 | { 62 | label: 'Pull Requests', 63 | href: 'https://github.com/mobily/rescript-date/pulls', 64 | }, 65 | { 66 | label: 'Issues', 67 | href: 'https://github.com/mobily/rescript-date/issues', 68 | }, 69 | ], 70 | }, 71 | { 72 | title: 'Contact', 73 | items: [ 74 | { 75 | label: 'Twitter', 76 | href: 'https://twitter.com/__marcin_', 77 | }, 78 | { 79 | label: 'Github', 80 | href: 'https://github.com/mobily', 81 | }, 82 | { 83 | label: 'Dev.to', 84 | href: 'https://dev.to/mobily', 85 | }, 86 | ], 87 | }, 88 | ], 89 | copyright: `Built with Docusaurus ❤️`, 90 | }, 91 | colorMode: { 92 | defaultMode: 'light', 93 | disableSwitch: true, 94 | respectPrefersColorScheme: false, 95 | }, 96 | }, 97 | plugins: [ 98 | [ 99 | require.resolve('@easyops-cn/docusaurus-search-local'), 100 | { 101 | hashed: true, 102 | docsRouteBasePath: ['/docs', '/api', '/benchmarks'], 103 | docsDir: ['docs', 'api', 'benchmarks'], 104 | }, 105 | ], 106 | [ 107 | '@docusaurus/plugin-content-docs', 108 | { 109 | id: 'api', 110 | path: 'api', 111 | routeBasePath: 'api', 112 | sidebarPath: require.resolve('./sidebars.api.js'), 113 | }, 114 | ], 115 | ], 116 | presets: [ 117 | [ 118 | '@docusaurus/preset-classic', 119 | { 120 | docs: { 121 | sidebarPath: require.resolve('./sidebars.js'), 122 | path: 'docs', 123 | routeBasePath: 'docs', 124 | editUrl: 'https://github.com/mobily/rescript-date/edit/master/docs/', 125 | }, 126 | theme: { 127 | customCss: require.resolve('./src/css/custom.css'), 128 | }, 129 | }, 130 | ], 131 | ], 132 | }; 133 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rescript-date-docs", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docusaurus": "docusaurus", 7 | "dev": "docusaurus start", 8 | "build": "docusaurus build", 9 | "swizzle": "docusaurus swizzle", 10 | "deploy": "docusaurus deploy", 11 | "serve": "docusaurus serve", 12 | "clear": "docusaurus clear" 13 | }, 14 | "dependencies": { 15 | "@docusaurus/core": "^0.0.0-4235", 16 | "@docusaurus/preset-classic": "^0.0.0-4235", 17 | "@easyops-cn/docusaurus-search-local": "^0.20.0", 18 | "@mdx-js/react": "^1.6.21", 19 | "@svgr/webpack": "^5.5.0", 20 | "clsx": "^1.1.1", 21 | "file-loader": "^6.2.0", 22 | "prism-react-renderer": "^1.2.1", 23 | "react": "^17.0.1", 24 | "react-dom": "^17.0.1", 25 | "url-loader": "^4.1.1" 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.5%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /docs/sidebars.api.js: -------------------------------------------------------------------------------- 1 | const makeSidebar = names => 2 | names.map(name => { 3 | return { 4 | type: 'doc', 5 | id: name, 6 | className: `sidebar-api sidebar-api-${name}`, 7 | } 8 | }) 9 | 10 | module.exports = { 11 | sidebar: makeSidebar([ 12 | 'common', 13 | 'interval', 14 | 'second', 15 | 'minute', 16 | 'hour', 17 | 'day', 18 | 'week', 19 | 'week-numbering', 20 | 'weekday', 21 | 'month', 22 | 'year', 23 | 'iso-week', 24 | 'iso-week-numbering', 25 | ]), 26 | } 27 | -------------------------------------------------------------------------------- /docs/sidebars.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | sidebar: [ 3 | { 4 | type: 'doc', 5 | id: 'installation', 6 | }, 7 | { 8 | type: 'doc', 9 | id: 'status', 10 | }, 11 | { 12 | type: 'doc', 13 | id: 'changelog', 14 | }, 15 | { 16 | type: 'link', 17 | label: 'Go to API', 18 | href: '/api/common', 19 | className: 'sidebar-api-button', 20 | }, 21 | ], 22 | }; 23 | -------------------------------------------------------------------------------- /docs/src/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import clsx from 'clsx' 3 | import Layout from '@theme/Layout' 4 | import Link from '@docusaurus/Link' 5 | import useDocusaurusContext from '@docusaurus/useDocusaurusContext' 6 | import useBaseUrl from '@docusaurus/useBaseUrl' 7 | import styles from './styles.module.css' 8 | 9 | const Home = () => { 10 | const context = useDocusaurusContext() 11 | const { siteConfig = {} } = context 12 | 13 | React.useEffect(() => { 14 | document.querySelector('.navbar__brand').style = 'display: none;' 15 | }, []) 16 | 17 | return ( 18 | 19 |
20 |
21 | ReDate 22 |
23 |

{siteConfig.title}

24 |

{siteConfig.tagline}

25 |
26 | 30 | Get started 31 | 32 | 36 | Go to API 37 | 38 |
39 |
40 |
41 |
42 |
43 | ) 44 | } 45 | 46 | export default Home 47 | -------------------------------------------------------------------------------- /docs/src/pages/styles.module.css: -------------------------------------------------------------------------------- 1 | /* stylelint-disable docusaurus/copyright-header */ 2 | /** 3 | * CSS files with the .module.css suffix will be treated as CSS modules 4 | * and scoped locally. 5 | */ 6 | 7 | .hero { 8 | min-height: calc(100vh - 79px); 9 | justify-content: flex-start; 10 | background-color: #FFFFFF; 11 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25' viewBox='0 0 1600 800'%3E%3Cg fill-opacity='0.04'%3E%3Cpath fill='%23ffccd5' d='M486 705.8c-109.3-21.8-223.4-32.2-335.3-19.4C99.5 692.1 49 703 0 719.8V800h843.8c-115.9-33.2-230.8-68.1-347.6-92.2C492.8 707.1 489.4 706.5 486 705.8z'/%3E%3Cpath fill='%23ff99ac' d='M1600 0H0v719.8c49-16.8 99.5-27.8 150.7-33.5c111.9-12.7 226-2.4 335.3 19.4c3.4 0.7 6.8 1.4 10.2 2c116.8 24 231.7 59 347.6 92.2H1600V0z'/%3E%3Cpath fill='%23ff6682' d='M478.4 581c3.2 0.8 6.4 1.7 9.5 2.5c196.2 52.5 388.7 133.5 593.5 176.6c174.2 36.6 349.5 29.2 518.6-10.2V0H0v574.9c52.3-17.6 106.5-27.7 161.1-30.9C268.4 537.4 375.7 554.2 478.4 581z'/%3E%3Cpath fill='%23ff3359' d='M0 0v429.4c55.6-18.4 113.5-27.3 171.4-27.7c102.8-0.8 203.2 22.7 299.3 54.5c3 1 5.9 2 8.9 3c183.6 62 365.7 146.1 562.4 192.1c186.7 43.7 376.3 34.4 557.9-12.6V0H0z'/%3E%3Cpath fill='%23FF002F' d='M181.8 259.4c98.2 6 191.9 35.2 281.3 72.1c2.8 1.1 5.5 2.3 8.3 3.4c171 71.6 342.7 158.5 531.3 207.7c198.8 51.8 403.4 40.8 597.3-14.8V0H0v283.2C59 263.6 120.6 255.7 181.8 259.4z'/%3E%3Cpath fill='%23ff002f' d='M1600 0H0v136.3c62.3-20.9 127.7-27.5 192.2-19.2c93.6 12.1 180.5 47.7 263.3 89.6c2.6 1.3 5.1 2.6 7.7 3.9c158.4 81.1 319.7 170.9 500.3 223.2c210.5 61 430.8 49 636.6-16.6V0z'/%3E%3Cpath fill='%23ff002f' d='M454.9 86.3C600.7 177 751.6 269.3 924.1 325c208.6 67.4 431.3 60.8 637.9-5.3c12.8-4.1 25.4-8.4 38.1-12.9V0H288.1c56 21.3 108.7 50.6 159.7 82C450.2 83.4 452.5 84.9 454.9 86.3z'/%3E%3Cpath fill='%23ff002f' d='M1600 0H498c118.1 85.8 243.5 164.5 386.8 216.2c191.8 69.2 400 74.7 595 21.1c40.8-11.2 81.1-25.2 120.3-41.7V0z'/%3E%3Cpath fill='%23ff002f' d='M1397.5 154.8c47.2-10.6 93.6-25.3 138.6-43.8c21.7-8.9 43-18.8 63.9-29.5V0H643.4c62.9 41.7 129.7 78.2 202.1 107.4C1020.4 178.1 1214.2 196.1 1397.5 154.8z'/%3E%3Cpath fill='%23FF002F' d='M1315.3 72.4c75.3-12.6 148.9-37.1 216.8-72.4h-723C966.8 71 1144.7 101 1315.3 72.4z'/%3E%3C/g%3E%3C/svg%3E"); 12 | background-attachment: fixed; 13 | background-size: cover; 14 | background-attachment: fixed; 15 | background-size: cover; 16 | } 17 | 18 | .heroBanner { 19 | display: flex; 20 | flex-direction: row; 21 | padding-left: 10vw; 22 | max-width: 70vw; 23 | } 24 | 25 | .h1 { 26 | font-size: 6rem; 27 | color: var(--ifm-color-gray-900); 28 | } 29 | 30 | @media screen and (max-width: 992px) { 31 | .h1 { 32 | font-size: 4rem; 33 | } 34 | } 35 | 36 | @media screen and (max-width: 768px) { 37 | .h1 { 38 | font-size: 3rem; 39 | } 40 | } 41 | 42 | .underscore { 43 | color: var(--ifm-color-primary); 44 | letter-spacing: -20px; 45 | position: relative; 46 | bottom: 17px; 47 | } 48 | 49 | .summary { 50 | color: var(--ifm-color-gray-900); 51 | font-size: 2.2rem; 52 | line-height: 3rem; 53 | margin-bottom: 40px; 54 | } 55 | 56 | @media screen and (max-width: 992px) { 57 | .summary { 58 | font-size: 1.6rem; 59 | line-height: 2rem; 60 | } 61 | } 62 | 63 | @media screen and (max-width: 768px) { 64 | .summary { 65 | font-size: 1.2rem; 66 | line-height: 1.6rem; 67 | } 68 | } 69 | 70 | @media screen and (max-width: 966px) { 71 | .heroBanner { 72 | padding: 2rem; 73 | } 74 | } 75 | 76 | .title { 77 | display: flex; 78 | flex-direction: row; 79 | align-items: center; 80 | } 81 | 82 | .button { 83 | height: 56px; 84 | display: flex; 85 | align-items: center; 86 | justify-content: center; 87 | padding: 0 40px; 88 | font-size: 1rem; 89 | text-transform: uppercase; 90 | letter-spacing: 3px; 91 | } 92 | 93 | .buttonOutline { 94 | border: 4px solid var(--ifm-color-gray-900); 95 | color: var(--ifm-color-gray-900); 96 | border-radius: 4px; 97 | } 98 | 99 | .buttonOutline:hover { 100 | border-color: var(--ifm-color-primary); 101 | color: var(--ifm-color-primary); 102 | } 103 | 104 | .buttonFull { 105 | border: none; 106 | background-color: var(--ifm-color-gray-900); 107 | color: var(--ifm-color-white); 108 | border-radius: 4px; 109 | margin-left: 20px; 110 | } 111 | 112 | @media screen and (max-width: 992px) { 113 | .buttonFull { 114 | margin-left: 0; 115 | margin-top: 10px; 116 | } 117 | } 118 | 119 | .buttonFull:hover { 120 | background-color: var(--ifm-color-primary); 121 | } 122 | 123 | .buttons { 124 | display: flex; 125 | } 126 | 127 | @media screen and (max-width: 992px) { 128 | .buttons { 129 | flex-direction: column; 130 | } 131 | } 132 | 133 | .titleImage { 134 | height: 120px; 135 | margin-right: 20px; 136 | } 137 | 138 | @media screen and (max-width: 992px) { 139 | .titleImage { 140 | height: 80px; 141 | } 142 | } 143 | 144 | @media screen and (max-width: 768px) { 145 | .titleImage { 146 | height: 60px; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /docs/static/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobily/rescript-date/514f8672026d81155fa45ac8eadb16a25d76f59d/docs/static/.nojekyll -------------------------------------------------------------------------------- /docs/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobily/rescript-date/514f8672026d81155fa45ac8eadb16a25d76f59d/docs/static/img/favicon.ico -------------------------------------------------------------------------------- /docs/static/img/hero-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobily/rescript-date/514f8672026d81155fa45ac8eadb16a25d76f59d/docs/static/img/hero-logo.png -------------------------------------------------------------------------------- /docs/static/img/rescript-date-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobily/rescript-date/514f8672026d81155fa45ac8eadb16a25d76f59d/docs/static/img/rescript-date-logo.png -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | verbose: true, 3 | moduleFileExtensions: ['js'], 4 | rootDir: __dirname, 5 | testMatch: ['/__tests__/*_test.bs.js'], 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mobily/rescript-date", 3 | "description": "📆 Date manipulation in ReScript.", 4 | "version": "2.1.0", 5 | "scripts": { 6 | "test": "yarn jest --coverage", 7 | "re:clean": "yarn rescript clean", 8 | "re:build": "yarn rescript build", 9 | "re:dev": "yarn rescript build -w", 10 | "generate:contributors": "yarn all-contributors generate" 11 | }, 12 | "license": "MIT", 13 | "keywords": [ 14 | "rescript", 15 | "date", 16 | "time", 17 | "datetime" 18 | ], 19 | "files": [ 20 | "src/!(*.bs.js)", 21 | "*.md", 22 | "bsconfig.json", 23 | "package.json" 24 | ], 25 | "author": "Marcin Dziewulski ", 26 | "homepage": "https://github.com/mobily/rescript-date#readme", 27 | "bugs": "https://github.com/mobily/rescript-date/issues", 28 | "repository": { 29 | "type": "git", 30 | "url": "https://github.com/mobily/rescript-date.git" 31 | }, 32 | "devDependencies": { 33 | "@glennsl/bs-jest": "^0.7.0", 34 | "all-contributors-cli": "^6.20.0", 35 | "coveralls": "^3.1.1", 36 | "rescript": "^9.1.4" 37 | }, 38 | "publishConfig": { 39 | "access": "public" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/ReDate.res: -------------------------------------------------------------------------------- 1 | include ReDate_common 2 | include ReDate_interval 3 | include ReDate_second 4 | include ReDate_minute 5 | include ReDate_hour 6 | include ReDate_day 7 | include ReDate_week 8 | include ReDate_week_numbering 9 | include ReDate_weekday 10 | include ReDate_month 11 | include ReDate_year 12 | include ReDate_iso_week 13 | include ReDate_iso_week_numbering 14 | include ReDate_types 15 | -------------------------------------------------------------------------------- /src/ReDate_common.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | 3 | let isEqual = (fst, snd) => Js.Date.getTime(fst) == Js.Date.getTime(snd) 4 | let isAfter = (fst, snd) => Js.Date.getTime(fst) > Js.Date.getTime(snd) 5 | let isBefore = (fst, snd) => Js.Date.getTime(fst) < Js.Date.getTime(snd) 6 | let isFuture = date => isAfter(date, Js.Date.make()) 7 | let isPast = date => isBefore(date, Js.Date.make()) 8 | 9 | let compareAsc = (fst, snd) => { 10 | switch Js.Date.getTime(fst) -. Js.Date.getTime(snd) { 11 | | ts if ts < 0. => -1 12 | | ts if ts > 0. => 1 13 | | _ => 0 14 | } 15 | } 16 | 17 | let compareDesc = (fst, snd) => { 18 | switch Js.Date.getTime(fst) -. Js.Date.getTime(snd) { 19 | | ts if ts < 0. => 1 20 | | ts if ts > 0. => -1 21 | | _ => 0 22 | } 23 | } 24 | 25 | let min = dates => { 26 | let date = Belt.Array.reduce(dates, None, (acc, date) => { 27 | switch Js.Date.getTime(date) { 28 | | timestamp if acc == None || timestamp < Belt.Option.getExn(acc) => Some(timestamp) 29 | | _ => acc 30 | } 31 | }) 32 | 33 | date->Belt.Option.getExn->Js.Date.fromFloat 34 | } 35 | 36 | let max = dates => { 37 | let date = Belt.Array.reduce(dates, None, (acc, date) => { 38 | switch Js.Date.getTime(date) { 39 | | ts if acc == None || ts > Belt.Option.getExn(acc) => Some(ts) 40 | | _ => acc 41 | } 42 | }) 43 | 44 | date->Belt.Option.getExn->Js.Date.fromFloat 45 | } 46 | 47 | let isValid = (~year, ~month, ~date, ~hours=0., ~minutes=0., ~seconds=0., ()) => { 48 | let lastDayOfMonth = 49 | Js.Date.makeWithYM(~year, ~month, ())->makeLastDayOfMonthDate->Js.Date.getDate 50 | 51 | year <= 199999. && 52 | year >= -199999. && 53 | month <= 11. && 54 | month >= 0. && 55 | date >= 1. && 56 | date <= lastDayOfMonth && 57 | hours >= 0. && 58 | hours <= 23. && 59 | minutes >= 0. && 60 | minutes <= 59. && 61 | seconds >= 0. && 62 | seconds <= 59. 63 | } 64 | -------------------------------------------------------------------------------- /src/ReDate_day.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | 3 | let addDays = (date, days) => { 4 | let day = Js.Date.getDate(date) +. days 5 | let date = Js.Date.setDate(makeDate(date), day) 6 | 7 | Js.Date.fromFloat(date) 8 | } 9 | 10 | let rec addBusinessDays = (date, days) => { 11 | let next = days < 0. ? Float.succ : Float.pred 12 | let offset = days < 0. ? -1. : 1. 13 | let date = addDays(date, offset) 14 | 15 | switch date { 16 | | date if ReDate_weekday.isWeekend(date) => addBusinessDays(date, days) 17 | | _ if days == 0. => addDays(date, -.offset) 18 | | _ => addBusinessDays(date, next(days)) 19 | } 20 | } 21 | 22 | let subDays = (date, days) => addDays(date, -.days) 23 | 24 | let getDate = Js.Date.getDate 25 | 26 | let setDate = (date, day) => { 27 | let date = Js.Date.setDate(makeDate(date), day) 28 | Js.Date.fromFloat(date) 29 | } 30 | 31 | let startOfDay = makeStartOfDayDate 32 | 33 | let endOfDay = makeEndOfDayDate 34 | 35 | let differenceInCalendarDays = (fst, snd) => { 36 | let fst = startOfDay(fst) 37 | let snd = startOfDay(snd) 38 | let fstTime = Js.Date.getTime(fst) -. getTimezoneOffsetInMilliseconds(fst) 39 | let sndTime = Js.Date.getTime(snd) -. getTimezoneOffsetInMilliseconds(snd) 40 | let diff = (fstTime -. sndTime) /. Milliseconds.day 41 | 42 | Js.Math.round(diff) 43 | } 44 | 45 | let differenceInDays = (fst, snd) => { 46 | let diff = (Js.Date.getTime(fst) -. Js.Date.getTime(snd)) /. Milliseconds.day 47 | diff > 0. ? Js.Math.floor_float(diff) : Js.Math.ceil_float(diff) 48 | } 49 | 50 | let differenceInBusinessDays = (fst, snd) => { 51 | let diff = differenceInCalendarDays(fst, snd) 52 | let date = diff < 0. ? fst : snd 53 | let result = ref(0.) 54 | 55 | let maxDiff = diff->int_of_float->Js.Math.abs_int->pred 56 | 57 | for index in 0 to maxDiff { 58 | let day = addDays(date, float_of_int(index)) 59 | result.contents = ReDate_weekday.isWeekend(day) ? result.contents : Float.succ(result.contents) 60 | } 61 | 62 | diff < 0. ? -.result.contents : result.contents 63 | } 64 | 65 | let getDayOfYear = date => { 66 | let diff = differenceInCalendarDays(date, ReDate_year.startOfYear(date)) 67 | Float.succ(diff) 68 | } 69 | 70 | let isSameDay = (fst, snd) => ReDate_common.isEqual(startOfDay(fst), startOfDay(snd)) 71 | 72 | let isToday = date => isSameDay(Js.Date.make(), date) 73 | 74 | let isTomorrow = date => { 75 | let today = Js.Date.make() 76 | isSameDay(addDays(today, 1.), date) 77 | } 78 | 79 | let isYesterday = date => { 80 | let today = Js.Date.make() 81 | isSameDay(subDays(today, 1.), date) 82 | } 83 | -------------------------------------------------------------------------------- /src/ReDate_hour.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | 3 | let addHours = (date, hours) => { 4 | let hours = Js.Date.getHours(date) +. hours 5 | let date = Js.Date.setHours(makeDate(date), hours) 6 | 7 | Js.Date.fromFloat(date) 8 | } 9 | 10 | let subHours = (date, hours) => addHours(date, -.hours) 11 | 12 | let getHours = Js.Date.getHours 13 | 14 | let setHours = (date, hours) => { 15 | let date = Js.Date.setHours(makeDate(date), hours) 16 | Js.Date.fromFloat(date) 17 | } 18 | 19 | let differenceInHours = (fst, snd) => { 20 | let diff = (Js.Date.getTime(fst) -. Js.Date.getTime(snd)) /. Milliseconds.hour 21 | diff > 0. ? Js.Math.floor_float(diff) : Js.Math.ceil_float(diff) 22 | } 23 | 24 | let startOfHour = date => { 25 | let date = Js.Date.setMinutesSMs(makeDate(date), ~minutes=0., ~seconds=0., ~milliseconds=0., ()) 26 | Js.Date.fromFloat(date) 27 | } 28 | 29 | let endOfHour = date => { 30 | let date = Js.Date.setMinutesSMs( 31 | makeDate(date), 32 | ~minutes=59., 33 | ~seconds=59., 34 | ~milliseconds=999., 35 | (), 36 | ) 37 | Js.Date.fromFloat(date) 38 | } 39 | 40 | let isSameHour = (fst, snd) => ReDate_common.isEqual(startOfHour(fst), startOfHour(snd)) 41 | -------------------------------------------------------------------------------- /src/ReDate_interval.res: -------------------------------------------------------------------------------- 1 | open ReDate_types 2 | open ReDate_utils 3 | 4 | let isWithinInterval = (date, interval) => { 5 | let timestamp = Js.Date.getTime(date) 6 | timestamp >= Js.Date.getTime(interval.start) && timestamp <= Js.Date.getTime(interval.end_) 7 | } 8 | 9 | let areIntervalsOverlapping = (left, right) => 10 | Js.Date.getTime(left.start) < Js.Date.getTime(right.end_) && 11 | Js.Date.getTime(right.start) < Js.Date.getTime(left.end_) 12 | 13 | let getOverlappingDaysInIntervals = (left, right) => { 14 | switch ( 15 | Js.Date.getTime(left.start), 16 | Js.Date.getTime(left.end_), 17 | Js.Date.getTime(right.start), 18 | Js.Date.getTime(right.end_), 19 | ) { 20 | | (leftStart, leftEnd, rightStart, rightEnd) if leftStart < rightEnd && rightStart < leftEnd => 21 | let overlapStartTime = rightStart < leftStart ? leftStart : rightStart 22 | let overlapEndTime = rightEnd > leftEnd ? leftEnd : rightEnd 23 | let overlap = (overlapEndTime -. overlapStartTime) /. Milliseconds.day 24 | 25 | overlap->Js.Math.ceil_float 26 | | _ => 0. 27 | } 28 | } 29 | 30 | let eachDayOfInterval = interval => { 31 | let intervalDays = ReDate_day.differenceInCalendarDays(interval.end_, interval.start) 32 | 33 | Belt.Array.makeBy(intervalDays->int_of_float->succ, index => 34 | interval.start->makeStartOfDayDate->ReDate_day.addDays(float_of_int(index)) 35 | ) 36 | } 37 | -------------------------------------------------------------------------------- /src/ReDate_iso_week.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | open ReDate_types 3 | 4 | let endOfISOWeek = ReDate_week.endOfWeek(~weekStartsOn=Monday) 5 | 6 | let isSameISOWeek = ReDate_week.isSameWeek(~weekStartsOn=Monday) 7 | 8 | let isThisISOWeek = date => isSameISOWeek(Js.Date.make(), date) 9 | 10 | let lastDayOfISOWeek = ReDate_week.lastDayOfWeek(~weekStartsOn=Monday) 11 | 12 | let startOfISOWeek = ReDate_week.startOfWeek(~weekStartsOn=Monday) 13 | 14 | let differenceInCalendarISOWeeks = (fst, snd) => { 15 | let fst = startOfISOWeek(fst) 16 | let snd = startOfISOWeek(snd) 17 | let fstTimestamp = Js.Date.getTime(fst) -. getTimezoneOffsetInMilliseconds(fst) 18 | let sndTimestamp = Js.Date.getTime(snd) -. getTimezoneOffsetInMilliseconds(snd) 19 | let diff = (fstTimestamp -. sndTimestamp) /. Milliseconds.week 20 | 21 | Js.Math.round(diff) 22 | } 23 | 24 | let getISOWeek = date => { 25 | let diff = 26 | Js.Date.getTime(startOfISOWeek(date)) -. 27 | Js.Date.getTime(ReDate_iso_week_numbering.startOfISOWeekYear(date)) 28 | 29 | Js.Math.round(diff /. Milliseconds.week) +. 1. 30 | } 31 | 32 | let setISOWeek = (date, week) => { 33 | let diff = getISOWeek(date) -. week 34 | let day = Js.Date.getDate(date) 35 | let date = date->Js.Date.getTime->Js.Date.fromFloat 36 | 37 | Js.Date.setDate(makeDate(date), day -. diff *. 7.)->Js.Date.fromFloat 38 | } 39 | -------------------------------------------------------------------------------- /src/ReDate_iso_week_numbering.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | 3 | let getISOWeekYear = date => { 4 | let year = Js.Date.getFullYear(date) 5 | let startOfISOWeek = ReDate_week.startOfWeek(~weekStartsOn=Monday) 6 | 7 | let fourthOfJanuaryOfNextYear = 8 | Js.Date.setFullYearMD(Js.Date.fromFloat(0.), ~year=year +. 1., ~month=0., ~date=4., ()) 9 | ->Js.Date.fromFloat 10 | ->makeStartOfDayDate 11 | let startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear) 12 | 13 | let fourthOfJanuaryOfThisYear = 14 | Js.Date.setFullYear( 15 | fourthOfJanuaryOfNextYear->Js.Date.getTime->Js.Date.fromFloat, 16 | year, 17 | )->Js.Date.fromFloat 18 | let startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear) 19 | 20 | if Js.Date.getTime(date) >= Js.Date.getTime(startOfNextYear) { 21 | year +. 1. 22 | } else if Js.Date.getTime(date) >= Js.Date.getTime(startOfThisYear) { 23 | year 24 | } else { 25 | year -. 1. 26 | } 27 | } 28 | 29 | let startOfISOWeekYear = date => { 30 | let year = getISOWeekYear(date) 31 | 32 | let fourthOfJanuary = Js.Date.fromFloat(0.) 33 | let fourthOfJanuary = 34 | Js.Date.setFullYearMD(fourthOfJanuary, ~year, ~month=0., ~date=4., ()) 35 | ->Js.Date.fromFloat 36 | ->makeStartOfDayDate 37 | 38 | ReDate_week.startOfWeek(~weekStartsOn=Monday, fourthOfJanuary) 39 | } 40 | -------------------------------------------------------------------------------- /src/ReDate_minute.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | 3 | let addMinutes = (date, minutes) => { 4 | let minutes = Js.Date.getMinutes(date) +. minutes 5 | let date = Js.Date.setMinutes(makeDate(date), minutes) 6 | 7 | Js.Date.fromFloat(date) 8 | } 9 | 10 | let subMinutes = (date, minutes) => addMinutes(date, -.minutes) 11 | 12 | let differenceInMinutes = (fst, snd) => { 13 | let diff = (Js.Date.getTime(fst) -. Js.Date.getTime(snd)) /. Milliseconds.minute 14 | diff > 0. ? Js.Math.floor_float(diff) : Js.Math.ceil_float(diff) 15 | } 16 | 17 | let getMinutes = Js.Date.getMinutes 18 | 19 | let setMinutes = (date, minutes) => { 20 | let date = Js.Date.setMinutes(makeDate(date), minutes) 21 | Js.Date.fromFloat(date) 22 | } 23 | 24 | let startOfMinute = date => { 25 | let date = Js.Date.setSecondsMs(makeDate(date), ~seconds=0., ~milliseconds=0., ()) 26 | Js.Date.fromFloat(date) 27 | } 28 | 29 | let endOfMinute = date => { 30 | let date = Js.Date.setSecondsMs(makeDate(date), ~seconds=59., ~milliseconds=999., ()) 31 | Js.Date.fromFloat(date) 32 | } 33 | 34 | let isSameMinute = (fst, snd) => ReDate_common.isEqual(startOfMinute(fst), startOfMinute(snd)) 35 | 36 | let roundToNearestMinute = (~nearestTo=1., date) => { 37 | let closestTo = Js.Math.round(Js.Date.getSeconds(date) /. 60.) 38 | let closestMinute = Js.Date.getMinutes(date) +. closestTo 39 | let nearestRoundedMinute = 40 | nearestTo != 1. 41 | ? Js.Math.round(Js.Date.getMinutes(date) /. nearestTo) *. nearestTo 42 | : closestMinute 43 | 44 | Js.Date.setMinutes(makeDate(date), nearestRoundedMinute)->Js.Date.fromFloat->startOfMinute 45 | } 46 | -------------------------------------------------------------------------------- /src/ReDate_month.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | 3 | let getDaysInMonth = date => { 4 | let lastDayOfMonth = makeLastDayOfMonthDate(date) 5 | Js.Date.getDate(lastDayOfMonth) 6 | } 7 | 8 | let addMonths = (date, months) => { 9 | let year = Js.Date.getFullYear(date) 10 | let month = Js.Date.getMonth(date) +. months 11 | let daysInMonth = getDaysInMonth(date) 12 | let date = Js.Math.min_float(daysInMonth, Js.Date.getDate(date)) 13 | 14 | Js.Date.makeWithYMD(~year, ~month, ~date, ()) 15 | } 16 | 17 | let subMonths = (date, months) => addMonths(date, -.months) 18 | 19 | let getMonth = Js.Date.getMonth 20 | 21 | let setMonth = (date, month) => { 22 | let year = Js.Date.getFullYear(date) 23 | let day = Js.Date.getDate(date) 24 | let date = Js.Date.makeWithYMD(~year, ~month, ~date=day, ()) 25 | let daysInMonth = getDaysInMonth(date) 26 | 27 | Js.Date.makeWithYMD(~year, ~month, ~date=Js.Math.min_float(day, daysInMonth), ()) 28 | } 29 | 30 | let differenceInCalendarMonths = (fst, snd) => { 31 | let fstYear = Js.Date.getFullYear(fst) 32 | let fstMonth = Js.Date.getMonth(fst) 33 | let sndYear = Js.Date.getFullYear(snd) 34 | let sndMonth = Js.Date.getMonth(snd) 35 | 36 | (fstYear -. sndYear) *. 12. +. (fstMonth -. sndMonth) 37 | } 38 | 39 | let differenceInMonths = (fst, snd) => { 40 | let diff = 41 | Js.Date.getMonth(fst) -. 42 | Js.Date.getMonth(snd) +. 43 | 12. *. (Js.Date.getFullYear(fst) -. Js.Date.getFullYear(snd)) 44 | let anchor = addMonths(snd, diff) 45 | let anchorTime = Js.Date.getTime(anchor) 46 | let fstTime = Js.Date.getTime(fst) 47 | let adjust = if fstTime -. anchorTime < 0. { 48 | (fstTime -. anchorTime) /. (anchorTime -. addMonths(snd, Float.pred(diff))->Js.Date.getTime) 49 | } else { 50 | (fstTime -. anchorTime) /. (addMonths(snd, Float.succ(diff))->Js.Date.getTime -. anchorTime) 51 | } 52 | 53 | Js.Math.round(adjust) +. diff 54 | } 55 | 56 | let startOfMonth = date => 57 | Js.Date.setDate(makeDate(date), 1.)->Js.Date.fromFloat->makeStartOfDayDate 58 | 59 | let endOfMonth = date => date->makeLastDayOfMonthDate->makeEndOfDayDate 60 | 61 | let isFirstDayOfMonth = date => Js.Date.getDate(date) == 1. 62 | 63 | let isLastDayOfMonth = date => ReDate_common.isEqual(makeEndOfDayDate(date), endOfMonth(date)) 64 | 65 | let isSameMonth = (fst, snd) => ReDate_common.isEqual(startOfMonth(fst), startOfMonth(snd)) 66 | 67 | let lastDayOfMonth = date => date->makeLastDayOfMonthDate->makeStartOfDayDate 68 | -------------------------------------------------------------------------------- /src/ReDate_second.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | open ReDate_types 3 | 4 | let addSeconds = (date, seconds) => { 5 | let seconds = Js.Date.getSeconds(date) +. seconds 6 | let date = Js.Date.setSeconds(makeDate(date), seconds) 7 | 8 | Js.Date.fromFloat(date) 9 | } 10 | 11 | let subSeconds = (date, seconds) => addSeconds(date, -.seconds) 12 | 13 | let setSeconds = (date, seconds) => { 14 | let date = Js.Date.setSeconds(makeDate(date), seconds) 15 | Js.Date.fromFloat(date) 16 | } 17 | 18 | let getSeconds = Js.Date.getSeconds 19 | 20 | let differenceInSeconds = (fst, snd) => { 21 | let diff = (Js.Date.getTime(fst) -. Js.Date.getTime(snd)) /. Milliseconds.second 22 | diff > 0. ? Js.Math.floor_float(diff) : Js.Math.ceil_float(diff) 23 | } 24 | 25 | let startOfSecond = date => { 26 | let date = Js.Date.setMilliseconds(makeDate(date), 0.) 27 | Js.Date.fromFloat(date) 28 | } 29 | 30 | let endOfSecond = date => { 31 | let date = Js.Date.setMilliseconds(makeDate(date), 999.) 32 | Js.Date.fromFloat(date) 33 | } 34 | 35 | let isSameSecond = (fst, snd) => ReDate_common.isEqual(startOfSecond(fst), startOfSecond(snd)) 36 | 37 | let closestTo = (date, dates) => { 38 | let result = dates->Belt.Array.reduce({date: None, distance: None}, (acc, compareDate) => { 39 | let distance = Js.Math.abs_float(Js.Date.getTime(date) -. Js.Date.getTime(compareDate)) 40 | let result = {date: Some(compareDate), distance: Some(distance)} 41 | 42 | Belt.Option.mapWithDefault(acc.distance, result, minDistance => 43 | distance < minDistance ? result : acc 44 | ) 45 | }) 46 | result.date 47 | } 48 | -------------------------------------------------------------------------------- /src/ReDate_types.res: -------------------------------------------------------------------------------- 1 | type interval = { 2 | start: Js.Date.t, 3 | end_: Js.Date.t, 4 | } 5 | 6 | type offset = 7 | | Start(Js.Date.t) 8 | | End(Js.Date.t) 9 | 10 | type day = 11 | | Sunday 12 | | Monday 13 | | Tuesday 14 | | Wednesday 15 | | Thursday 16 | | Friday 17 | | Saturday 18 | 19 | type closestTo = { 20 | distance: option, 21 | date: option, 22 | } 23 | -------------------------------------------------------------------------------- /src/ReDate_utils.res: -------------------------------------------------------------------------------- 1 | open ReDate_types 2 | 3 | external toDayMagic: int => ReDate_types.day = "%identity" 4 | 5 | module Milliseconds = { 6 | let second = 1000. 7 | let minute = 60. *. second 8 | let hour = 60. *. minute 9 | let day = 24. *. hour 10 | let week = 7. *. day 11 | } 12 | 13 | module Float = { 14 | let succ = value => value +. 1. 15 | let pred = value => value -. 1. 16 | } 17 | 18 | let getWeekDayNum = day => { 19 | switch day { 20 | | Sunday => 0. 21 | | Monday => 1. 22 | | Tuesday => 2. 23 | | Wednesday => 3. 24 | | Thursday => 4. 25 | | Friday => 5. 26 | | Saturday => 6. 27 | } 28 | } 29 | 30 | let makeDate = date => date->Js.Date.getTime->Js.Date.fromFloat 31 | 32 | let makeLastDayOfMonthDate = date => 33 | Js.Date.makeWithYMD( 34 | ~year=Js.Date.getFullYear(date), 35 | ~month=Js.Date.getMonth(date) +. 1., 36 | ~date=0., 37 | (), 38 | ) 39 | 40 | let makeStartOfDayDate = date => { 41 | let date = Js.Date.setHoursMSMs( 42 | makeDate(date), 43 | ~hours=0., 44 | ~minutes=0., 45 | ~seconds=0., 46 | ~milliseconds=0., 47 | (), 48 | ) 49 | 50 | Js.Date.fromFloat(date) 51 | } 52 | 53 | let makeEndOfDayDate = date => { 54 | let date = Js.Date.setHoursMSMs( 55 | makeDate(date), 56 | ~hours=23., 57 | ~minutes=59., 58 | ~seconds=59., 59 | ~milliseconds=999., 60 | (), 61 | ) 62 | 63 | Js.Date.fromFloat(date) 64 | } 65 | 66 | let makeStartOfYearDate = year => { 67 | let date = Js.Date.makeWithYMD(~year, ~month=0., ~date=1., ()) 68 | makeStartOfDayDate(date) 69 | } 70 | 71 | let getTimezoneOffsetInMilliseconds = date => { 72 | let offset = 73 | Js.Date.getTimezoneOffset(date) *. Milliseconds.minute +. 74 | Js.Date.setSecondsMs(makeDate(date), ~seconds=0., ~milliseconds=0., ()) 75 | let fst = int_of_float(offset) 76 | let snd = int_of_float(Milliseconds.minute) 77 | 78 | float_of_int(mod(fst, snd)) 79 | } 80 | 81 | // HACK: ⬇️ avoid dependency cycle 82 | let is = (day, date) => Js.Date.getDay(date) == getWeekDayNum(day) 83 | 84 | let startOfWeek = (~weekStartsOn=Sunday, date) => { 85 | let startWeekDay = getWeekDayNum(weekStartsOn) 86 | let day = Js.Date.getDay(date) 87 | let diff = (day < startWeekDay ? 7. : 0.) +. day -. startWeekDay 88 | 89 | Js.Date.setDate(makeDate(date), Js.Date.getDate(date) -. diff) 90 | ->Js.Date.fromFloat 91 | ->makeStartOfDayDate 92 | } 93 | -------------------------------------------------------------------------------- /src/ReDate_week.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | open ReDate_types 3 | 4 | let addWeeks = (date, weeks) => ReDate_day.addDays(date, weeks *. 7.) 5 | 6 | let subWeeks = (date, weeks) => addWeeks(date, -.weeks) 7 | 8 | let differenceInWeeks = (fst, snd) => { 9 | let diff = (Js.Date.getTime(fst) -. Js.Date.getTime(snd)) /. Milliseconds.week 10 | diff > 0. ? Js.Math.floor_float(diff) : Js.Math.ceil_float(diff) 11 | } 12 | 13 | let startOfWeek = ReDate_utils.startOfWeek 14 | 15 | let endOfWeek = (~weekStartsOn=Sunday, date) => { 16 | let startWeekDay = getWeekDayNum(weekStartsOn) 17 | let day = Js.Date.getDay(date) 18 | let diff = (day < startWeekDay ? -7. : 0.) +. 6. -. (day -. startWeekDay) 19 | 20 | Js.Date.setDate(makeDate(date), Js.Date.getDate(date) +. diff) 21 | ->Js.Date.fromFloat 22 | ->makeEndOfDayDate 23 | } 24 | 25 | let differenceInCalendarWeeks = (~weekStartsOn=Sunday, fst, snd) => { 26 | let startOfWeek = startOfWeek(~weekStartsOn) 27 | let fst = startOfWeek(fst) 28 | let snd = startOfWeek(snd) 29 | let fstTime = Js.Date.getTime(fst) -. getTimezoneOffsetInMilliseconds(fst) 30 | let sndTime = Js.Date.getTime(snd) -. getTimezoneOffsetInMilliseconds(snd) 31 | let diff = (fstTime -. sndTime) /. Milliseconds.week 32 | 33 | Js.Math.round(diff) 34 | } 35 | 36 | let isSameWeek = (~weekStartsOn=Sunday, fst, snd) => { 37 | let startOfWeek = startOfWeek(~weekStartsOn) 38 | ReDate_common.isEqual(startOfWeek(fst), startOfWeek(snd)) 39 | } 40 | 41 | let lastDayOfWeek = (~weekStartsOn=Sunday, date) => 42 | makeStartOfDayDate(endOfWeek(~weekStartsOn, date)) 43 | 44 | let getWeekOfMonth = (~weekStartsOn=Sunday, date) => { 45 | let firstMonthDay = Js.Date.getDay(ReDate_month.startOfMonth(date)) 46 | let startWeekDay = getWeekDayNum(weekStartsOn) 47 | let diff = 48 | firstMonthDay < startWeekDay 49 | ? 7. -. startWeekDay +. firstMonthDay 50 | : firstMonthDay -. startWeekDay 51 | let result = (Js.Date.getDate(date) +. diff) /. 7. 52 | 53 | Js.Math.ceil_float(result) 54 | } 55 | 56 | let getWeeksInMonth = (~weekStartsOn=Sunday, date) => { 57 | let differenceInCalendarWeeks = differenceInCalendarWeeks(~weekStartsOn) 58 | date 59 | ->ReDate_month.lastDayOfMonth 60 | ->differenceInCalendarWeeks(ReDate_month.startOfMonth(date)) 61 | ->Float.succ 62 | } 63 | 64 | let getWeek = (~weekStartsOn=Sunday, date) => { 65 | let diff = { 66 | let fst = ReDate_week_numbering.startOfWeekYear(~weekStartsOn, date) 67 | let snd = startOfWeek(~weekStartsOn, date) 68 | Js.Date.getTime(snd) -. Js.Date.getTime(fst) 69 | } 70 | 71 | Js.Math.round(diff /. Milliseconds.week) +. 1. 72 | } 73 | -------------------------------------------------------------------------------- /src/ReDate_week_numbering.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | open ReDate_types 3 | 4 | let getWeekYear = (~weekStartsOn=Sunday, date) => { 5 | let year = Js.Date.getFullYear(date) 6 | let nextYear = year +. 1. 7 | let current = year->makeStartOfYearDate->startOfWeek(~weekStartsOn) 8 | let next = nextYear->makeStartOfYearDate->startOfWeek(~weekStartsOn) 9 | 10 | if Js.Date.getTime(date) >= Js.Date.getTime(next) { 11 | nextYear 12 | } else if Js.Date.getTime(date) >= Js.Date.getTime(current) { 13 | year 14 | } else { 15 | year -. 1. 16 | } 17 | } 18 | 19 | let startOfWeekYear = (~weekStartsOn=Sunday, date) => { 20 | let year = getWeekYear(~weekStartsOn, date) 21 | year->makeStartOfYearDate->startOfWeek(~weekStartsOn) 22 | } 23 | -------------------------------------------------------------------------------- /src/ReDate_weekday.res: -------------------------------------------------------------------------------- 1 | open ReDate_types 2 | open ReDate_utils 3 | 4 | let getDay = date => date->Js.Date.getDay->int_of_float->toDayMagic 5 | let isSunday = is(Sunday) 6 | let isMonday = is(Monday) 7 | let isTuesday = is(Tuesday) 8 | let isWednesday = is(Wednesday) 9 | let isThursday = is(Thursday) 10 | let isFriday = is(Friday) 11 | let isSaturday = is(Saturday) 12 | let isWeekend = date => is(Saturday, date) || is(Sunday, date) 13 | let isWeekDay = (date, weekday) => is(weekday, date) 14 | -------------------------------------------------------------------------------- /src/ReDate_year.res: -------------------------------------------------------------------------------- 1 | open ReDate_utils 2 | 3 | let addYears = (date, years) => ReDate_month.addMonths(date, 12. *. years) 4 | 5 | let subYears = (date, years) => addYears(date, -.years) 6 | 7 | let getYear = Js.Date.getFullYear 8 | 9 | let setYear = (date, year) => { 10 | let date = Js.Date.setFullYear(makeDate(date), year) 11 | Js.Date.fromFloat(date) 12 | } 13 | 14 | let startOfYear = date => 15 | Js.Date.makeWithYMDHMS( 16 | ~year=Js.Date.getFullYear(date), 17 | ~month=0., 18 | ~date=1., 19 | ~hours=0., 20 | ~minutes=0., 21 | ~seconds=0., 22 | (), 23 | ) 24 | 25 | let isSameYear = (fst, snd) => ReDate_common.isEqual(startOfYear(fst), startOfYear(snd)) 26 | 27 | let isLeapYear = date => { 28 | let year = date->Js.Date.getFullYear->int_of_float 29 | mod(year, 400) == 0 || (mod(year, 4) == 0 && mod(year, 100) != 0) 30 | } 31 | 32 | let endOfYear = date => { 33 | let year = Js.Date.getFullYear(date) 34 | let date = Js.Date.makeWithYMD(~year, ~month=11., ~date=31., ()) 35 | 36 | makeEndOfDayDate(date) 37 | } 38 | 39 | let lastMonthOfYear = date => { 40 | let year = Js.Date.getFullYear(date) 41 | let date = Js.Date.makeWithYMD(~year, ~month=11., ~date=1., ()) 42 | 43 | makeStartOfDayDate(date) 44 | } 45 | 46 | let lastDayOfYear = date => date->lastMonthOfYear->ReDate_month.lastDayOfMonth 47 | 48 | let getDaysInYear = date => isLeapYear(date) ? 366 : 365 49 | 50 | let differenceInCalendarYears = (fst, snd) => { 51 | let fstYear = Js.Date.getFullYear(fst) 52 | let sndYear = Js.Date.getFullYear(snd) 53 | 54 | fstYear -. sndYear 55 | } 56 | 57 | let differenceInYears = (fst, snd) => { 58 | let diff = ReDate_month.differenceInMonths(fst, snd) /. 12. 59 | diff > 0. ? Js.Math.floor_float(diff) : Js.Math.ceil_float(diff) 60 | } 61 | --------------------------------------------------------------------------------