undated

The main module for manipulating dates that are not datetime datatypes. Consisting of a main class object, YMD, for managing a date as an integer and several functions for further functionality, such as adding or calculating differences. All of these are hopefully self explanitory.

class undated.YMD(year_or_iymd: Optional[Union[int, tuple]], month: Optional[int] = None, day: Optional[int] = None, trusted: bool = False)

Class of date parts, year, month, day

Parameters
  • year_or_iymd – the year, date in Ymd format or tuple of date parts

  • month – the month number, 1 = Jan, defaults to 1

  • day – the day. If not supplied, the 1st is assumed

  • trusted – True, if dates can be trusted to be correct, the validation stage is skipped

add_days(days: int) YMD

Adds the specified number of days to the date. Another option would be to use the addition operator `ymd2 = ymd1 + 2`

Parameters

days – The number of days to add. Use negative days to subtract days.

Returns

YMD class object

add_months(months: int, period: bool = False) YMD

Adds the specified number of months to the date

Parameters
  • months – The number of months to add, use negative months to subtract

  • period – Set to True when looking for a period end date. So… With period False, Jan 1st + 12 months, would be 1st Jan the following year. With period set to True, it would be 31st Dec the same year.

Returns

YMD class object

add_weekdays(weekdays: int) YMD

Adds the specified number of weekdays, Monday to Friday, to the date

Parameters

weekdays – The number of weekdays to add. Use negative days to subtract.

Returns

YMD class object

add_years(years: int, period: bool = False) YMD

Adds a specified number of years to the date

Parameters
  • years – The number of years to add. Use negative years to subtract

  • period – Set to True when looking for a period end date. So… With period False, Jan 1st + 1 year, would be 1st Jan the following year. With period set to True, it would be 31st Dec the same year.

Returns

YMD class object

day: Optional[int]

The day element of the date, as a 1 or 2 digit integer

day_of_week() Optional[int]

The number for the day of the week. Sunday == 0, Monday == 1…

Returns

The day number 0 to 6

is_leap_year() bool

Is the date falling within a leap year

Returns

True when the date falls in a leap year

is_weekday() bool

Is the date falling on a weekday, IE between Monday and Friday

Returns

True when it is a weekday

iymd: Optional[int]

The date as an 8 digit integer, in year, month, day format

month: Optional[int]

The month element of the date, as a 1 or 2 digit integer. January==1, December==12

status: int = None

The status of the class. Refers to the package constants VALID, INVALID and TRUSTED

year: Optional[int]

The year element of the date, as a 4 digit integer

undated.add_days(ymd: YMD, days: int) YMD

Adds a number of days to a date in in Ymd format

Parameters
  • ymd – YMD class object

  • days – int, the number of days to add

Returns

YMD class object

undated.add_months(ymd: YMD, months: int, period: bool = False) YMD

Adds given months to a date. Use negative months to subtract months

Parameters
  • ymd – YMD class object

  • months – int, the number of months

  • period – bool, takes the previous day. EG: For last day of a period

Returns

YMD class object

undated.add_weekdays(ymd: YMD, weekdays: int) YMD

Adds a number of weekdays, monday to friday, to a date in in Ymd format

Parameters
  • ymd – YMD class object

  • weekdays – int, the number of days to add

Returns

YMD class object

undated.days_between(from_ymd: YMD, to_ymd: YMD) Optional[int]

Calculates the days between two dates

Parameters
  • from_ymd – YMD, the from date YMD class object

  • to_ymd – YMD, the to date YMD class object

Returns

int, the days between the dates

undated.months_between(from_ymd: YMD, to_ymd: YMD) Optional[int]

Calculates the complete months between two dates

Parameters
  • from_ymd – YMD class object

  • to_ymd – YMD class object

Returns

int, the complete months between the dates

undated.quarter(ymd: YMD, to_str: bool = True) Optional[Union[int, str]]

Calculates the quarter from a year, returning the quarter end month, or quarter number

Parameters
  • ymd – YMD class object

  • to_str – bool, true returns 2021Q3, otherwise 202103 format

Returns

str 2021Q1, 2021Q2, 2021Q3, 2021Q4; or int 202103, 202106, 202109, 202112

undated.weekdays_between(from_ymd: YMD, to_ymd: YMD, inclusive: bool = False) Optional[int]

Calculates the number of weekdays between two dates

Parameters
  • from_ymd – YMD class object

  • to_ymd – YMD class object

  • inclusive – bool, whether to include the to date as a completed day

Returns

int, the number of days between the dates