This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients ajaksu2, belopolsky, ezio.melotti, mixit
Date 2010-04-12.14:35:31
SpamBayes Score 0.00010947436
Marked as misclassified No
Message-id <1271082934.89.0.495719114642.issue8026@psf.upfronthosting.co.za>
In-reply-to
Content
This is not a bug.  The issue boils down to the following:

>>> from datetime import *
>>> d = datetime(2010, 1, 1)
>>> d, d.strftime("%G")
(datetime.datetime(2010, 1, 1, 0, 0), '2009')

and OP expects '2010' instead.  Python behavior is correct as can be verified using GNU date utility:

$ date --date=20100101 +%G
2009

The confusion comes from the fact that %G is formatted as the ISO 8601 year.  This year is the one that contains the greater part of the week (Monday as the first day of the week).


Here is another illustration:
>>> d = date(2009,12,31)
>>> for i in range(7):
...    (d+timedelta(i)).strftime("%F %a %G %V")
... 
'2009-12-31 Thu 2009 53'
'2010-01-01 Fri 2009 53'
'2010-01-02 Sat 2009 53'
'2010-01-03 Sun 2009 53'
'2010-01-04 Mon 2010 01'
'2010-01-05 Tue 2010 01'
'2010-01-06 Wed 2010 01'

Note that week 1 of 2010 started on Monday, 2010-01-04.

OP is advised to change %G to %Y in his code.
History
Date User Action Args
2010-04-12 14:35:35belopolskysetrecipients: + belopolsky, ajaksu2, ezio.melotti, mixit
2010-04-12 14:35:34belopolskysetmessageid: <1271082934.89.0.495719114642.issue8026@psf.upfronthosting.co.za>
2010-04-12 14:35:32belopolskylinkissue8026 messages
2010-04-12 14:35:31belopolskycreate