Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LocalDate.daysBetween #1

Open
mlms13 opened this issue Aug 8, 2019 · 1 comment
Open

Add LocalDate.daysBetween #1

mlms13 opened this issue Aug 8, 2019 · 1 comment

Comments

@mlms13
Copy link
Member

mlms13 commented Aug 8, 2019

daysBetween(a, b) should return an int number of days. Adding that number of days to a should yield b, e.g.

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.

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));
};
@mlms13
Copy link
Member Author

mlms13 commented Aug 9, 2019

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.

@mlms13 mlms13 changed the title Add YMD.daysBetween Add LocalDate.daysBetween Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant