This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
open Jest; | ||
|
||
open Js.Date; | ||
|
||
describe("differenceInBusinessDays", () => { | ||
open ExpectJs; | ||
|
||
test("returns 0 if the given dates are the same", () => { | ||
let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()); | ||
let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=1., ()); | ||
|
||
fstDate | ||
|> ReDate.differenceInBusinessDays(sndDate) | ||
|> expect | ||
|> toEqual(0); | ||
}); | ||
|
||
test( | ||
"returns the number of business days between the given dates, excluding weekends", | ||
() => { | ||
let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=10., ()); | ||
let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()); | ||
|
||
fstDate | ||
|> ReDate.differenceInBusinessDays(sndDate) | ||
|> expect | ||
|> toEqual(6); | ||
}, | ||
); | ||
|
||
test( | ||
"returns a negative number if the time value of the first date is smaller", | ||
() => { | ||
let fstDate = makeWithYMD(~year=2018., ~month=0., ~date=2., ()); | ||
let sndDate = makeWithYMD(~year=2018., ~month=0., ~date=10., ()); | ||
|
||
fstDate | ||
|> ReDate.differenceInBusinessDays(sndDate) | ||
|> expect | ||
|> toEqual(-6); | ||
}); | ||
|
||
test("returns a correct number when the first date falls on a weekend", () => { | ||
let fstDate = makeWithYMD(~year=2019., ~month=6., ~date=20., ()); | ||
let sndDate = makeWithYMD(~year=2019., ~month=6., ~date=18., ()); | ||
|
||
fstDate | ||
|> ReDate.differenceInBusinessDays(sndDate) | ||
|> expect | ||
|> toEqual(2); | ||
}); | ||
|
||
test("returns a correct number when the second date falls on a weekend", () => { | ||
let fstDate = makeWithYMD(~year=2019., ~month=6., ~date=23., ()); | ||
let sndDate = makeWithYMD(~year=2019., ~month=6., ~date=20., ()); | ||
|
||
fstDate | ||
|> ReDate.differenceInBusinessDays(sndDate) | ||
|> expect | ||
|> toEqual(1); | ||
}); | ||
|
||
test("returns a correct number when both dates fall on a weekend", () => { | ||
let fstDate = makeWithYMD(~year=2019., ~month=6., ~date=28., ()); | ||
let sndDate = makeWithYMD(~year=2019., ~month=6., ~date=20., ()); | ||
|
||
fstDate | ||
|> ReDate.differenceInBusinessDays(sndDate) | ||
|> expect | ||
|> toEqual(5); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters