mxDateTime function DateFromString gives wrong year

Sibylle Koczian Sibylle.Koczian at Bibliothek.Uni-Augsburg.de
Mon Mar 29 04:27:27 EST 2004


rzed schrieb:
> Sibylle Koczian <Sibylle.Koczian at Bibliothek.Uni-Augsburg.de> wrote
> in news:c412g7$2d20ui$1 at uni-berlin.de: 
> 
> 
>>Tim Roberts schrieb:
>>
>>>Sibylle Koczian <Sibylle.Koczian at Bibliothek.Uni-Augsburg.de>
>>>wrote: 
>>>
>>>
>>>
>>>>This is very nearly a repetition of a post by Peter Hansen from
>>>>2002-07-07 which never got an answer:
>>>>
>>>>
>>>>
>>>>>>>x = mx.DateTime.Parser.DateFromString('Nov 2003')
>>>>>>>x
>>>>
>>>><DateTime object for '2004-11-20 00:00:00.00' at a61ba0>
>>>>
>>>>Using mx.DateTime Version 2.0.5 for Python 2.3 and ActivePython
>>>>2.3.2. 
>>>>
>>This case is a citation from the original post from 2002. My
>>actual problem is with "Nov 2003" which is converted to a date
>>in November 2004. And I think what P. Hansen cited from the
>>mx.DateTime documentation in his original posting is equally
>>valid here: 
>>
> But the answer is likely to be similar, isn't it? After parsing Nov 
> 20 (expecting a particular day), the next character is not a valid 
> separator, so the parsing stops and the current year is inserted. 
> What date are you expecting, given only a month and year? Or are you 
> expecting November 20, 2003? Asking the parser to distinguish which 
> of two interpretations of "2003" you mean seems a little demanding.
> 
I never thought about the "20" being interpreted as the day (possibly 
made my experiments on the 20. of some month and thought the current day 
was taken as well as the current year), because the day isn't given and 
I don't need it in the application. And of course "November 20" is no 
familiar date form in german speaking countries. Your explanation makes 
sense, though. On the other hand, 2003 is a 4 digit number which might 
reasonably be expected to be taken as a year.

I just tried to parse some formats for month and year, without a day. I 
would accept every day in the month as correct. The only one I could 
find which parsed correctly (taking 1 as default day) was '2003-11'.

As the dates for my application are _consistently_ given as "<month 
name> <4 digit year>" and Python 2.3 contains time.strptime on Windows, 
my problem is solved anyway.

Thank you,
Koczian

-- 
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg

Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : Sibylle.Koczian at Bibliothek.Uni-Augsburg.DE




More information about the Python-list mailing list