1

I'd like to get the date of the beginning of the week, given a calendar week:

>>> calendarweek_to_date(2017, 52, 1)
datetime.date(2017, 12, 25)

Currently I'm finding the weekday by using isocalendar()[2] then create a weekday and then subtract a timedelta with the appropriate days.

weekday = date_object.isocalendar()[2]  # Monday := 1 .. Sunday := 7
weekday -= 1  # Monday := 0 .. Sunday := 6
offset = timedelta(days=weekday)
last_monday = date_object - offset

However I'm appalled by my current solution and believe there must be a better way.

Sebastian Wozny
  • 16,943
  • 7
  • 52
  • 69

0 Answers0