Re: DateConverter and ISO format dates

Jorge Godoy <[email protected]>
Newsgroups gmane.comp.python.formencode
Organization G2C Tech Consultoria Ltda.
Message-ID <[email protected]>
JosephSheedy <[email protected]> writes:

> I'm interested in using DateConverter to validate incoming dates.  I'm
> receiving them in ISO format: YYYY-mm-dd.
>
> dc = validators.DateConverter()
> dc.to_python('2000-01-01')
>     Invalid: Please enter the date in the form mm/dd/yyyy
>
>  I saw some discussion about this on the TurboGears mailing list from
> October 2005, but can't find anything about using ISO format in the
> FormEncode archives or in the docs.  Has any progress been made on
> this?

dc = validators.DateConverter(month_style='yyyy/mm/dd')
dc.to_python('2000-01-01')


This should work, but...


>>> dc = validators.DateConverter(month_style='yyyy-mm-dd')
>>> dc.to_python('2000-01-21')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/godoy/desenvolvimento/python/TurboGears/1.0/thirdparty/formencode/formencode/api.py", line 316, in to_python
    value = tp(value, state)
  File "/home/godoy/desenvolvimento/python/TurboGears/1.0/thirdparty/formencode/formencode/validators.py", line 1565, in _to_python
    return self.convert_day(value, state)
  File "/home/godoy/desenvolvimento/python/TurboGears/1.0/thirdparty/formencode/formencode/validators.py", line 1575, in convert_day
    value, state)
formencode.api.Invalid: Please enter the date in the form yyyy-mm-dd
>>> 

It looks like a FormEncode bug to me since other formats work as expected:

>>> dc = validators.DateConverter(month_style='dd-mm-yyyy')
>>> dc.to_python('01-01-2000')
datetime.date(2000, 1, 1)
>>> dc.to_python('01-13-2000')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/godoy/desenvolvimento/python/TurboGears/1.0/thirdparty/formencode/formencode/api.py", line 316, in to_python
    value = tp(value, state)
  File "/home/godoy/desenvolvimento/python/TurboGears/1.0/thirdparty/formencode/formencode/validators.py", line 1565, in _to_python
    return self.convert_day(value, state)
  File "/home/godoy/desenvolvimento/python/TurboGears/1.0/thirdparty/formencode/formencode/validators.py", line 1587, in convert_day
    value, state)
formencode.api.Invalid: Please enter a month from 1 to 12
>>> dc.to_python('01-13-2000')



Tests made with:

URL: http://svn.colorstudy.com/FormEncode/tags/0.5.1/formencode
Repository Root: http://svn.colorstudy.com
Repository UUID: 95a46c32-92d2-0310-94a5-8d71aeb3d4b3
Revision: 2030
Node Kind: directory
Schedule: normal
Last Changed Author: test
Last Changed Rev: 1723
Last Changed Date: 2006-04-21 12:22:27 -0300 (Fri, 21 Apr 2006)


-- 
Jorge Godoy      <[email protected]>


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.