NumberF.DateCalculations (NumberF v0.3.0)

Copy Markdown View Source

Functions for performing date-based calculations.

Summary

Functions

Calculates the date after adding a specified number of business days.

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

add_business_days(date, num_days)

Calculates the date after adding a specified number of business days.

age_in_months(birth_date, as_of \\ Date.utc_today())

Age in whole months.

Examples

iex> NumberF.DateCalculations.age_in_months(~D[2020-01-15], ~D[2024-08-22])
55

business_days_between(date1, date2)

Calculates the number of business days between two dates.

calculate_age(birth_date)

Calculates age based on birth date.

days_between(date1, date2)

Calculates the number of days between two dates.

days_in_month(year, month)

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(date, start_month \\ 4)

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

is_business_day?(date)

Determines if a date is a business day.

leap_year?(year)

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

month_end(date)

Last day of the date's month.

Examples

iex> NumberF.DateCalculations.month_end(~D[2024-02-10])
~D[2024-02-29]

month_start(date)

First day of the date's month.

Examples

iex> NumberF.DateCalculations.month_start(~D[2024-08-22])
~D[2024-08-01]

next_business_day(date)

Calculates the next business day after the given date.

payment_due_date(invoice_date, terms_days)

Calculates payment due date based on invoice date and terms.

quarter(date)

Calendar quarter of a date, 1 to 4.

Examples

iex> NumberF.DateCalculations.quarter(~D[2024-08-22])
3

quarter_end(date)

Last day of the date's calendar quarter.

Examples

iex> NumberF.DateCalculations.quarter_end(~D[2024-08-22])
~D[2024-09-30]

quarter_start(date)

First day of the date's calendar quarter.

Examples

iex> NumberF.DateCalculations.quarter_start(~D[2024-08-22])
~D[2024-07-01]

week_number(date)

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