Skip to content

Add LocalDate.daysBetween #1

@mlms13

Description

@mlms13

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));
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions