utils.py 338 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
from datetime import datetime, timedelta

def tofirstdayinisoweek(year, week):
    # from http://stackoverflow.com/questions/5882405/get-date-from-iso-week-number-in-python
    ret = datetime.strptime('%04d-%02d-1' % (year, week), '%Y-%W-%w')
    if datetime(year, 1, 4).isoweekday() > 4:
        ret -= timedelta(days=7)
    return ret