0

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?

Calanas
  • 1
  • 1
  • Welcome to StackOverflow. It would really be helpful to include "the problem" here in your post. I couldn't see anything "at the end" of the page you linked to. Have a look under [how to ask a good question](https://stackoverflow.com/help/how-to-ask) for some guidance. – FriendFX Sep 18 '15 at 06:36
  • Hey. Thanks for the info, i will just update my question. – Calanas Sep 18 '15 at 06:41
  • Why do you not just say, week 0 corresponds to the rest of week 53? – wenzul Sep 18 '15 at 07:17
  • I have talked to my boss regarding this idea and he seems to be confident with this solution. – Calanas Sep 18 '15 at 09:08

0 Answers0