Reputation: 946
I am writing a script to grab files from a directory based on the week number in the filenames. I need to grab files with week N and week N+1 in the filenames.
I have the basics down, but am now struggling to figure out the rollover for new years (the file format uses the isocalendar standard). Isocalendars can have either 52 or 53 weeks in them, so I need a way to figure out if the year I'm in is a 52 or 53 week year so that I can then compare to the results of datetime.now().isocalendar()[1]
and see if I need to set N+1
to 1.
Is there a built in python function for this?
Upvotes: 0
Views: 348
Reputation: 37364
Why not just use (datetime.now() + timedelta(days=7)).isocalendar()[1]
rather than calculating it from the current week number at all?
Upvotes: 1