12345678910111213141516171819 |
- def truncate_quarter(datetime):
- '''
- Truncates the datetime to the first day of the quarter for this date.
- :params datetime: an initialized datetime object
- :return: `datetime` with the month set to the first month of this quarter
- :rtype: :py:mod:`datetime` datetime object
- '''
- datetime = truncate(datetime, 'month')
- month = datetime.month
- if 1 <= month <= 3:
- return datetime.replace(month=1)
- elif 4 <= month <= 6:
- return datetime.replace(month=4)
- elif 7 <= month <= 9:
- return datetime.replace(month=7)
- elif 10 <= month <= 12:
- return datetime.replace(month=10)
|