[Python-Dev] Python-Dev Digest, Vol 69, Issue 143 (original) (raw)

skip at pobox.com skip at pobox.com
Fri Apr 17 05:14:33 CEST 2009


Tennessee> If its' the 31st of Jan, then +1 monthdelta will be 28 Feb
Tennessee> and another +1 will be 28 March whereas 31st Jan +2
Tennessee> monthdeltas will be 31 March.

Other possible arithmetics:

* 31 Jan 2008 + monthdelta(2) might be
    31 Jan 2008 + 31 days (# days in Jan) + 29 days (# days in Feb)

* 31 Jan 2008 + monthdelta(2) might be
    31 Jan 2008 + 29 days (# days in Feb) + 31 days (# days in Mar)

* Treat the day of the month of the base datetime as an offset from the
  end of the month.  29 Jan 2007 would thus have an EOM offset of -2.
  Adding monthdelta(2) would advance you into March with the resulting
  day being two from the end of the month, or 29 Mar 2007.  OTOH, adding
  monthdelta(1) you'd wind up on 26 Feb 2007.

* Consider the day of the month in the base datetime as an offset from
  the start of the month if it is closer to the start or as an offset
  from the end of the month if it is closer to the end.  12 Mar 2009 -
  monthdelta(2) would land you at 12 Jan 2009 whereas 17 Mar 2009 -
  monthdelta(1) would land you at 12 Feb 2009.

My mind spins at all the possibilities. I suspect we've seen at least ten different monthdelta rules just in this thread. I don't know how much sense they all make, but we can probably keep dreaming up new ones until the cows come home. Except for completely wacko sets of rules you can probably find uses for most of them. Bake, baby, bake.

pillsbury-doughboy-ly, y'rs,

Skip



More information about the Python-Dev mailing list