How *not* to calculate a future date

This mail was in my Inbox today and I was puzzled at first:

When I tried to start Zope it returned an error:

DateError: Invalid date: (2022, 2, 29)

Apparently it only happend on a leap year and exactly on the 29th of
February. Checking the old code base (Python 2.4, Plone 3) revealed this:


DateTime.DateTime(
     DateTime.DateTime().year() + 10,
    DateTime.DateTime().month(),
    DateTime.DateTime().day())

*Doh!*. Python provides a timedelta (Python 2.4 Library reference) module which would be better for calculating future dates.

Update: Apparently others writing similar mistakes 😉 Microsoft’s Azure cloud down and out for 8 hours (via fefe)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s