I'm having the following issue: I have a function which iterates over a list of dates which are all workdays. For each auf these dates I need to get the week number. So this might look currently like:
last_day = datetime.date(2016, 2, 1)
current_workday = datetime.now().date()
datelist = []
while current_workday < last_day:
datelist.append(current_workday)
current_workday = workdays.workday(current_workday, 1) //get the next workday
for day in datelist:
week = datetime.date(day).isocalendar()[1]
print week
However my boss isn't lucky anymore with what happens between the years. The "problem" is pointed at the end of this page http://www.staff.science.uu.nl/~gent0113/calendar/isocalendar.htm (go to page long and short ISO years)
"An ISO calendar year is long if and only if the corresponding Gregorian year begins on a Thursday when it is a common year or begins on a Wednesday when it is a leap year."
This does not seem to work always as the author further mentions:
"This rule has worked fine since 1977 but failed in 2004 (a leap year that began on a Thursday) as the following diagram shows." (please refer to the diagram on page Long and short ISO years since I am not allowed to post images yet)
My issue is somehow the other way around. I do not seem to have enough reputation points to show it to you, but in my Excel output file I get a CW 0 only on January 1st.
He don't want to have those week 0. Do someone have an idea how to calculate with another week format than the one from the isocalendar? Or am I just doing something wrong?