undated.utils
The utils module functionality mirrors that of the ud.YMD
class.
However these functions have been stripped down to improve performance.
Use only when dates are valid integers in the Ymd
format.
- undated.utils.add_days(iymd: int, days: int) int
Adds a number of days to a date in in Ymd format
- Parameters
iymd – the date in Ymd format
days – the number of days to add
- Returns
the new date in Ymd format
- undated.utils.add_months(iymd: int, months: int) int
Adds given months to a date. Use negative months to subtract months
- Parameters
iymd – the date in Ymd format
months – the number of months
- Returns
the new date
- undated.utils.add_weekdays(iymd: int, weekdays: int) int
Adds a number of weekdays, monday to friday, to a date in in Ymd format
- Parameters
iymd – the date in Ymd format
weekdays – the number of days to add
- Returns
the new date in Ymd format
- undated.utils.day_of_week(iymd: int) int
Calculates the number for day of the week. Sunday = 0, Monday = 1…
- Parameters
iymd – date in Ymd format
- Returns
the day number 0 to 6
- undated.utils.days_between(from_iymd: int, to_iymd: int) int
Calculates the days between two dates
- Parameters
from_iymd – the from date in Ymd format
to_iymd – the to date in Ymd format
- Returns
the days between the dates
- undated.utils.first_day(iym: int) int
Converts a year month integer to a year month day integer, as at the first day of the month Simple formula, exists for completion.
- Parameters
iym – The year month in Ym format
- Returns
The year month day in Ymd format
- undated.utils.is_leap_year(year: int) int
Is the year a leap year
- Parameters
year – the year
- Returns
1 for leap year, 0 not a leap year
- undated.utils.is_valid(iymd: int) bool
Checks the date is valid. Year expected to be between 1583 and 9999
- Parameters
iymd – the date in Ymd format
- Returns
is the date is a valid date or not
- undated.utils.is_weekday(iymd: int) bool
Calculates if the date is a weekday, Monday - Friday
- Parameters
iymd – the date in Ymd format
- Returns
True when it is a weekday
- undated.utils.last_day(iym: int) int
Converts a year month integer to a year month day integer, as at the last day of the month
- Parameters
iym – The year month in Ym format
- Returns
The year month day in Ymd format
- undated.utils.months_between(from_iymd: Union[int, YMD], to_iymd: Union[int, YMD]) int
Calculates the complete months between two dates
- Parameters
from_iymd – the from date in Ymd or Ym format
to_iymd – the from date in Ymd or Ym format
- Returns
the complete months between the dates
- undated.utils.quarter(iymd: int, to_str: bool = True) Union[int, str]
Calculates the quarter from a year, returning the quarter end month, or quarter number
- Parameters
iymd – the date in Ymd or Ym format
to_str – true returns 2021Q3, otherwise 202103 format
- Returns
str 2021Q1, 2021Q2, 2021Q3, 2021Q4; or int 202103, 202106, 202109, 202112
- undated.utils.weekdays_between(from_iymd: int, to_iymd: int, inclusive: bool = False) int
Calculates the complete months between two dates
- Parameters
from_iymd – the from date in Ymd format
to_iymd – the from date in Ymd format
inclusive – whether to include the to date as a completed day
- Returns
the complete months between the dates