Dick Moores | 5 May 10:36

mxDateTime problem

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
2008-05-11 00:00:00.00.

>>> from mx import DateTime as DT
>>> print DT.now()
2008-05-05 00:51:34.00
>>> dstr = "5/8/2008"
>>> print DT.Parser.DateFromString(dstr, ('us',))
2008-05-08 00:00:00.00
>>>
(Continue reading)

Charlie Clark | 5 May 10:51
Favicon

Re: mxDateTime problem

Am 05.05.2008, 10:37 Uhr, schrieb Dick Moores <rdmoores@...>:

Dick,

it would be nice to have the problem stated clearly at the top of the  
e-mail.

> 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
> 2008-05-11 00:00:00.00.
>
>>>> from mx import DateTime as DT
>>>> print DT.now()
> 2008-05-05 00:51:34.00
(Continue reading)

M.-A. Lemburg | 5 May 10:53
Favicon

Re: mxDateTime problem

On 2008-05-05 10:37, Dick Moores wrote:
> 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 "". 

If you change your getDate() to use DateTime.today() the
problem should go away.

The mxDateTime parsers default to 00:00:00 for the time
part if no time part is found. DateTime.today() does the
same - it returns the current date at midnight.

> 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
(Continue reading)


Gmane