How to add months to a date (datetime object)?
John Yeung
gallium.arsenide at gmail.com
Mon Mar 16 01:33:39 CET 2009
On Mar 15, 6:25 pm, John Machin <sjmac... at lexicon.net> wrote:
> A couple of issues here:
>
> (1) The number of days in a month is not a constant, so "a
> mathematician's sense of logic" is quite irrelevant.
It's relevant in the sense that some commenters on this thread seem to
want to apply some semblance of mathematical logic to the problem.
Also, I referred to *date* math as not always being mathematically
logical, not *month* math (which some might argue is inherently not
subject to mathematical logic; perhaps this is your position, I can't
quite tell if that's the intent of your statement).
> (2) The various *different* LPDMs are quite well established
> and each of them can be reduced to non-ambiguous rules provided
> that the reducer is patient and persistent and avoids terms
> like "ugly", "illogical", "ludicrous" ... early stages of the
> reduction process can produce things like "31 January plus 1
> month -> 3 March (2 March in a leap year)" :-)
I don't know if by "different LPDMs" you mean that "day math" is one
LPDM and "month math" is another, not quite compatible LPDM; or if you
mean there are several well-established meanings for the same verbal
expressions such as "add three months to Feb 28". If the former, then
I agree in principle, though with different terminology. If the
latter, I disagree, based on my experience.
I've done a lot of the reduction work you are talking about, and the
same verbal phrases tend to map to the same specific rules in the
end. Of course, that may not be everyone's experience, but it is
mine. It is also evidently the experience of dateutil's author and
the developers of all of the date routines and calendar programs I
have personally tried (which, granted, isn't all that many, but
includes extremely popular ones).
John
More information about the Python-list
mailing list