Open mlms13 opened 5 years ago
daysBetween(a, b) should return an int number of days. Adding that number of days to a should yield b, e.g.
daysBetween(a, b)
int
a
b
LocalDate.( daysBetween(a, b) |> addDays(_, a) |> eq(b) //true );
If the first value is less than the second value, the returned result should be positive (e.g. daysBetween(yesterday, today) == 1.
daysBetween(yesterday, today) == 1
Among other things, this could be useful for determining how far into a year a given date is (as a percentage):
let percentOfYear = ymd => { let beginningOfYear = LocalDate.(ymd |> setMonth(Jan) |> setDay(1)); let between = LocalDate.daysBetween(beginningOfYear, ymd); Int.toFloat(between) /. Int.toFloat(LocalDate.daysInYear(ymd)); };
That daysBetween(beginningOfYear, ymd) stuff should be extracted out into its own function, once we have this. Calculating the "day of year" for a LocalDate seems useful.
daysBetween(beginningOfYear, ymd)
LocalDate
daysBetween(a, b)
should return anint
number of days. Adding that number of days toa
should yieldb
, e.g.If the first value is less than the second value, the returned result should be positive (e.g.
daysBetween(yesterday, today) == 1
.Among other things, this could be useful for determining how far into a year a given date is (as a percentage):