Created
June 22, 2014 13:36
-
-
Save bpceee/611e2a4757fc06fc1bc9 to your computer and use it in GitHub Desktop.
date iteration
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
#!/usr/bin/env python | |
# coding=utf-8 | |
from datetime import datetime, timedelta | |
def daterange(start, stop, step_minutes=1): | |
current = start | |
step = timedelta(minutes=step_minutes) | |
if step_minutes > 0: | |
while current < stop: | |
yield current | |
current += step | |
elif step_minutes < 0: | |
while current > stop: | |
yield current | |
current += step | |
else: | |
raise ValueError("daterange() step_days argument must not be zero") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment