-
-
Save elliot42/6a1e5e63074528b1d4d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def period_interval(date, period, n0, n1): | |
"""Return a 2-tuple of [start_date, end_date], | |
date: base date from which to calculate forwards/backwards | |
period: timedelta | |
n0: int, starting period number | |
n1: int, ending period number""" | |
return [date + (period * n0), | |
date + (period * n1)] | |
date = datetime.datetime(2015, 11, 18) | |
period = datetime.timedelta(days=14) | |
interval = period_interval(date, period, -1, 0) | |
print(date) | |
print(period) | |
print(interval) | |
# dev01:~$ python timeexample.py | |
# 2015-11-18 00:00:00 | |
# 14 days, 0:00:00 | |
# [datetime.datetime(2015, 11, 4, 0, 0), datetime.datetime(2015, 11, 18, 0, 0)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment