Date Utilities
Module: ppc_robot_lib.utils.date
- add_months(dt, months, keep_last_day=False)[source]
Add the given number of months to the given date or datetime. If the resulting month has less days than the input month, last day of the month will be used.
If you set
keep_last_day=True
, the resulting month has more days, and the input date was the last day of the month, the last day of the resulting month will be used.Examples:
>>> from datetime import date >>> add_months(date(2020, 1, 31), months=1) date(2020, 2, 28) >>> add_months(date(2020, 1, 31), months=2) date(2020, 3, 31) >>> add_months(date(2020, 2, 28), months=1, keep_last_day=False) date(2020, 3, 28) >>> add_months(date(2020, 2, 28), months=1, keep_last_day=True) date(2020, 3, 31)
- get_month_in_date_range(dt, date_range_start, date_range_end, keep_last_day=True)[source]
Helper function for determining current month in a date range.
- Parameters:
- Return type:
- Returns:
Info about the current month.
- get_previous_period(start_date, end_date)[source]
Takes date range and creates a new date range with the exact number of days which precedes it. E.g. For 2019-01-10 - 2019-01-18, this function will return 2019-01-01 - 2019-01-09