mxDateTime function DateFromString gives wrong year

rzed rzantow at ntelos.net
Fri Mar 26 09:03:53 EST 2004


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. 
>>>
>>>The original posting had the same problem with 'October
>>>29/2000'. This isn't corrected either, it still converts to
>>>2004-10-29. 
>> 
>> 
>> I'm not convinced that's a bug.  The slash is not a valid
>> separator for DateFromString once it finds a named month, so
>> the parse terminates there. It sees "October 29" and assumes
>> the current year.  Replace the slash with a comma and it will
>> work fine. 
> 
> 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: 
> 
> "The module knows about quite a few different date and time
> formats and will try very hard to come up with a reasonable
> output given a valid input." 
> 
> For the example "October 29/2000" replacing the slash with ', '
> does work. For my "Nov 2003" inserting a comma doesn't help.
> 

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.

-- 
rzed




More information about the Python-list mailing list