[egenix-users] mxDateTime problem
rdmoores at gmail.com
Mon May 5 02:37:16 CEST 2008
Use this file for temporary saving. E.g. for drafting an email.
Please see my daysDelta24.py at <http://py77.python.pastebin.com/f5d8a35d>
"Compute the difference in days (and weeks and days) between 2 dates.
E.g., The difference between 07/04/1776 and 09/11/2001 is 82248 days
Or 11749 weeks and 5 days"
The user is instructed to "Enter date as month/day/year, or enter
nothing for today", for both dates. If for one date he chooses to
enter nothing in order to make that date today's date, the script
fails--the computed difference between the dates will be short by 1.
Thus, if the dates are 5/5/2008 (today's date entered by entering
nothing) and 5/8/2008, the computed difference will be 2. If instead,
both of these dates had been entered "manually", the computed
difference will be 3. (See outputs #3 and #4, lines 107-126)
I believe the error is caused by getDate() returning DT.now() when the
user enters "". DT.now() is, for example, 2008-05-05 00:51:34.00 (my
local time at time of writing), not 2008-05-05 00:00:00.00, whereas
the other date entered, for example 5/8/2008, will be returned as
>>> from mx import DateTime as DT
>>> print DT.now()
>>> dstr = "5/8/2008"
>>> print DT.Parser.DateFromString(dstr, ('us',))
In line 48 (2008-08-11 00:00:00.00 - 2008-05-05 00:51:34.00).days will
be computed as 2 days, not 3.
I've used mxDateTime instead of the Python module datetime because
datetime can't handle dates earlier than the year 1900.
Can anyone tell me how to correct this problem?
More information about the egenix-users