Skip to content

Instantly share code, notes, and snippets.

@Fale
Created November 7, 2014 17:10
Show Gist options
  • Save Fale/1b0a311252826e3bd672 to your computer and use it in GitHub Desktop.
Save Fale/1b0a311252826e3bd672 to your computer and use it in GitHub Desktop.
import datetime
def daterange(s, e):
start = 12 * s['year'] + s['month'] - 1
end = 12 * e['year'] + e['month']
months = []
for a in range(start,end):
months.append({'year': a//12, 'month': a % 12+1})
return months
def getDay(ym, week, day):
shift = 1
weeklyShift = (week - 1) * 7 + day
firstDay = datetime.date(ym['year'], ym['month'], shift)
if firstDay.weekday() is not 0:
shift = 8 - firstDay.weekday()
return shift + weeklyShift
yms = daterange({'year': 2014, 'month': 11},{'year': 2015, 'month': 12})
for ym in yms:
f = getDay(ym, 1, 0)
s = getDay(ym, 3, 4)
print(str(ym['year']) + '-' + str(ym['month']) + ': ' + str(f) + ', ' + str(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment