Skip to content

Instantly share code, notes, and snippets.

@maraca
Created July 20, 2011 01:40
Show Gist options
  • Save maraca/1094164 to your computer and use it in GitHub Desktop.
Save maraca/1094164 to your computer and use it in GitHub Desktop.
Algo to parse periods of time.
#!/usr/bin/python2.6
import datetime
dates = [
datetime.date(2011, 01, 01),
datetime.date(2011, 01, 11),
datetime.date(2011, 01, 15),
datetime.date(2011, 01, 25),
datetime.date(2011, 01, 30),
datetime.date(2011, 02, 10),
datetime.date(2011, 02, 15),
datetime.date(2011, 02, 20),
datetime.date(2011, 02, 28),
datetime.date(2011, 03, 10),
datetime.date(2011, 03, 15),
datetime.date(2011, 03, 18),
datetime.date(2011, 03, 18),
datetime.date(2011, 03, 18),
]
current_date = dates[0]
period_num = 0
for date in dates:
delta = date - current_date
if delta.days >= 21:
print 'Period of 21 days reached (%d days)' % delta.days
current_date = date
period_num += 1
print '## Period %d ##' % period_num
print ''
else:
print 'Delta: %d . Moving to next period' % delta.days
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment