12345678910111213141516 |
- def truncate_half_year(datetime):
- '''
- Truncates the datetime to the first day of the half year for this date.
- :params datetime: an initialized datetime object
- :return: `datetime` with the month set to the first month of this half year
- :rtype: :py:mod:`datetime` datetime object
- '''
- datetime = truncate(datetime, 'month')
- month = datetime.month
- if 1 <= month <= 6:
- return datetime.replace(month=1)
- elif 7 <= month <= 12:
- return datetime.replace(month=7)
|