Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Quick Python question



On 10/08/2009 11:37 AM, Dan Ritter wrote:
> Why isn't February 29th important?
>
> And what happens on leapyears, anyway?
>
> Is the spec "do something more-or-less a year from now" or "do
> something 365 days from now" or "do something on the next
> anniversary of this date, treat February 29th as either Feb 28
> or Mar 1"?
>
> (Christopher's example is a right thing to do, and certainly
> uses the right method -- the question is whether the logic
> matches what you want to do.)
>
>  =20
February 29th is important, but not for the current thing I am working
on. My C++ date time routines work fine for feb 29, and whenever the day
is the last day of the month, but in the case of this specific project
Feb 29th is not important). Using timedelta(365) is:
>>> d =3D date(2007, 2, 25)
>>> d +=3D datetime.timedelta(365)
>>> d
datetime.date(2008, 2, 25)
>>> d +=3D datetime.timedelta(365)
>>> d
datetime.date(2009, 2, 24)
                                        ^^^

This works correctly
>>> d =3D date(d.year + 1, d.month, d.day)
>>> d
datetime.date(2008, 2, 25)
>>> d =3D date(d.year + 1, d.month, d.day)
>>> d
datetime.date(2009, 2, 25)

The bottom line is that leap year is important. I can probably use the
mxDate stuff, but it means my code may not work with some Financial
Engineer somewhere else in the world unless I can convince the company
to license it to ship with our product as we make our product to be
independent of any installed libraries, etc.

--=20
Jerry Feldman <gaf-mNDKBlG2WHs at public.gmane.org>
Boston Linux and Unix
PGP key id: 537C5846
PGP Key fingerprint: 3D1B 8377 A3C0 A5F2 ECBB  CA3B 4607 4319 537C 5846








BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org