Functions for performing date-based calculations.
Summary
Functions
Calculates the date after adding a specified number of business days.
Age in whole months.
Calculates the number of business days between two dates.
Calculates age based on birth date.
Calculates the number of days between two dates.
Number of days in a given month.
Fiscal year containing the date, given the month the fiscal year starts in.
Determines if a date is a business day.
Whether a year is a leap year in the proleptic Gregorian calendar.
Last day of the date's month.
First day of the date's month.
Calculates the next business day after the given date.
Calculates payment due date based on invoice date and terms.
Calendar quarter of a date, 1 to 4.
Last day of the date's calendar quarter.
First day of the date's calendar quarter.
ISO-8601 week number.
Functions
Calculates the date after adding a specified number of business days.
Age in whole months.
Examples
iex> NumberF.DateCalculations.age_in_months(~D[2020-01-15], ~D[2024-08-22])
55
Calculates the number of business days between two dates.
Calculates age based on birth date.
Calculates the number of days between two dates.
Number of days in a given month.
Examples
iex> NumberF.DateCalculations.days_in_month(2024, 2)
29
iex> NumberF.DateCalculations.days_in_month(2023, 2)
28
Fiscal year containing the date, given the month the fiscal year starts in.
The year returned is the one the fiscal year ends in, which is the common convention: with an April start, 2024-08-22 falls in FY2025.
Examples
iex> NumberF.DateCalculations.fiscal_year(~D[2024-08-22], 4)
2025
iex> NumberF.DateCalculations.fiscal_year(~D[2024-02-10], 4)
2024
Determines if a date is a business day.
Whether a year is a leap year in the proleptic Gregorian calendar.
Examples
iex> NumberF.DateCalculations.leap_year?(2024)
true
iex> NumberF.DateCalculations.leap_year?(1900)
false
Last day of the date's month.
Examples
iex> NumberF.DateCalculations.month_end(~D[2024-02-10])
~D[2024-02-29]
First day of the date's month.
Examples
iex> NumberF.DateCalculations.month_start(~D[2024-08-22])
~D[2024-08-01]
Calculates the next business day after the given date.
Calculates payment due date based on invoice date and terms.
Calendar quarter of a date, 1 to 4.
Examples
iex> NumberF.DateCalculations.quarter(~D[2024-08-22])
3
Last day of the date's calendar quarter.
Examples
iex> NumberF.DateCalculations.quarter_end(~D[2024-08-22])
~D[2024-09-30]
First day of the date's calendar quarter.
Examples
iex> NumberF.DateCalculations.quarter_start(~D[2024-08-22])
~D[2024-07-01]
ISO-8601 week number.
Edge cases
ISO weeks belong to the year containing their Thursday, so the first days of January can fall in week 52 or 53 of the previous year.
Examples
iex> NumberF.DateCalculations.week_number(~D[2024-08-22])
34