[Zope3-dev] Re: datetimeutil.py for the rest of us
Tres Seaver
tseaver at zope.com
Wed Jun 2 18:02:08 EDT 2004
Terry Hancock wrote:
> On Sunday 30 May 2004 01:51 pm, Martijn Faassen wrote:
>
>>Stuart Bishop wrote:
>>
>>> - If an ambiguous datetime format is parsed, it assumes US format.
>>> I feel that this case should instead raise an exception.
>>> If US programmers insist on being able to write broken code,
>>> seperate US specific methods could be made available in
>>> datetimeutils.py or a seperate US centric module.
>>
>>I strongly agree that the datetime parser should *not* try to make sense
>>of wrong data. If the format says mm-dd-yy and the date doesn't fit in
>>it as it's dd-mm-yy, it should fail, and verse versa. I'm not the only
>>one who has run into bugs (outside of Zope, mind) because people insist
>>of doing it the Perl way and guess at it, instead of doing it the Python
>>way and refusing to guess.
>
>
> Well, if you're going to assume a format, it seems more appropriate to
> assume *metric* order rather than either European or American. The metric
> standard says the numbers should be in decreasing order of significance,
> just like written decimal numbers. Thus: YYYY-MM/DD.
The slash is what screws it up. Try 'YYYY-MM-DD' and see if that works
for you::
zopectl> debug
Starting debugger (the name "app" is bound to the top-level Zope object)
>>> from DateTime.DateTime import DateTime
>>> d = DateTime( '2000-01/02' )
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/home/tseaver/projects/Zope-CVS/Zope-2.7-branch/lib/python/DateTime/DateTime.py",
line 724, in __init__
yr,mo,dy,hr,mn,sc,tz=self._parse_iso8601(arg)
File
"/home/tseaver/projects/Zope-CVS/Zope-2.7-branch/lib/python/DateTime/DateTime.py",
line 1690, in _parse_iso8601
raise SyntaxError, (
DateTime.DateTime.SyntaxError: Not an ISO 8601 compliant date string:
"2000-01/02"
>>> d = DateTime( '2000-01-02' )
>>> d
DateTime('2000/01/02')
>>> d.year
<bound method DateTime.year of DateTime('2000/01/02')>
>>> d.year()
2000
>>> d.month()
1
>>> d.day()
2
> I always record dates that way. DateTime doesn't read them right, though.
> (If "right" is the right word). Generally it seems to me that the app
> programmer has to specifically ask for year, month, and day separately if
> they want to get correct results.
The-lovely-thing-about-standards'ly,
Tres.
--
===============================================================
Tres Seaver tseaver at zope.com
Zope Corporation "Zope Dealers" http://www.zope.com
More information about the Zope3-dev
mailing list