Try the following in python 2.6:
newyear_2012 = datetime.date.fromtimestamp(1325419200)
newyear.year # returns 2012
newyear.isocalendar() # return (2011, 52, 7)
What’s the deal here? Is this a bug? I couldn’t find it documented, but maybe I didn’t look in the right place.
If I convert that unix timestamp here, it tells me: Sun, 01 Jan 2012 12:00:00 GMT
Update:
The answers below explain how this is not a python error but rather due to the ISO specification. If you want to get the week number that won’t ever put the first few days of the year in week #52, you can try the following:
week_no = int(time.strftime("%U", datetime_object.timetuple()))
I’m not sure what standard that’s corresponds to, but it behaves more intuitively from my perspective (in my application week numbers within a year should be ascending with time).
From https://www.staff.science.uu.nl/~gent0113/calendar/isocalendar_text2.htm
the first week of the ISO calendar year is the earliest week that contains at least four days of the month of January…(assumed to start on Monday)
That makes ISO 2012 begin on Jan 2. Your timestamp is Sun, 01 Jan 2012 12:00:00 GMT