Changing Python's Date/Time Input Format
Hi All. I've got a minor issue with a form which takes a date and returns the string date. I'm wanting the input format to be able to accept any of dd-mm-yy, dd mon year, dd/mm/yyyy. Currently, it works for dd mon year, but it handles other input as mm/dd/yy. (which is kind-of un-natural for those using this form) how should I modify this python script... today=DateTime(input) return today.strftime("%d %B %Y") ... to alert Zope that the incoming string will be always in the order of dd mm yyyy? This is the traceback when the first tuple is not a valid month. <!-- Traceback (innermost last): File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 223, in publish_module File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 187, in publish File D:\Zope\2-3-3\lib\python\Zope\__init__.py, line 221, in zpublisher_exception_hook (Object: Traversable) File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 171, in publish File D:\Zope\2-3-3\lib\python\ZPublisher\mapply.py, line 160, in mapply (Object: template) File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 112, in call_object (Object: template) File D:\Zope\2-3-3\lib\python\OFS\DTMLMethod.py, line 189, in __call__ (Object: template) File D:\Zope\2-3-3\lib\python\DocumentTemplate\DT_String.py, line 540, in __call__ (Object: template) File D:\Zope\2-3-3\lib\python\DocumentTemplate\DT_Util.py, line 339, in eval (Object: stringdate(purc_date)) (Info: stringdate) File <string>, line 0, in ? File D:\Zope\Products\PythonMethod\PythonMethod.py, line 168, in __call__ (Object: stringdate) (Info: (('21/12/2003',), {}, None)) File <string>, line 2, in stringdate File D:\Zope\2-3-3\lib\python\DateTime\DateTime.py, line 708, in __init__ File D:\Zope\2-3-3\lib\python\DateTime\DateTime.py, line 1050, in _parse Invalid Date Components: 21/12/2003 --> Cheers, Julian Clark
Instead of fighting windmills you should change your input form so that it minimizes user error. I would put selection widgets for day-of-month, month and maybe even year into that form instead of allowing people to type in some free-form date. jens On Nov 20, 2003, at 22:42, Julian Clark wrote:
Hi All. I've got a minor issue with a form which takes a date and returns the string date. I'm wanting the input format to be able to accept any of dd-mm-yy, dd mon year, dd/mm/yyyy. Currently, it works for dd mon year, but it handles other input as mm/dd/yy. (which is kind-of un-natural for those using this form)
how should I modify this python script...
today=DateTime(input) return today.strftime("%d %B %Y")
... to alert Zope that the incoming string will be always in the order of dd mm yyyy?
This is the traceback when the first tuple is not a valid month.
<!--
Traceback (innermost last): File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 223, in publish_module File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 187, in publish File D:\Zope\2-3-3\lib\python\Zope\__init__.py, line 221, in zpublisher_exception_hook (Object: Traversable) File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 171, in publish File D:\Zope\2-3-3\lib\python\ZPublisher\mapply.py, line 160, in mapply (Object: template) File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 112, in call_object (Object: template) File D:\Zope\2-3-3\lib\python\OFS\DTMLMethod.py, line 189, in __call__ (Object: template) File D:\Zope\2-3-3\lib\python\DocumentTemplate\DT_String.py, line 540, in __call__ (Object: template) File D:\Zope\2-3-3\lib\python\DocumentTemplate\DT_Util.py, line 339, in eval (Object: stringdate(purc_date)) (Info: stringdate) File <string>, line 0, in ? File D:\Zope\Products\PythonMethod\PythonMethod.py, line 168, in __call__ (Object: stringdate) (Info: (('21/12/2003',), {}, None)) File <string>, line 2, in stringdate File D:\Zope\2-3-3\lib\python\DateTime\DateTime.py, line 708, in __init__ File D:\Zope\2-3-3\lib\python\DateTime\DateTime.py, line 1050, in _parse Invalid Date Components: 21/12/2003 -->
Cheers,
Julian Clark
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
This is implemented in Zope 2.7. Check doc/CHANGES.txt for details. -aj --On Freitag, 21. November 2003 11:42 Uhr +0800 Julian Clark <Julian.Clarke@b-online.com.au> wrote:
Hi All. I've got a minor issue with a form which takes a date and returns the string date. I'm wanting the input format to be able to accept any of dd-mm-yy, dd mon year, dd/mm/yyyy. Currently, it works for dd mon year, but it handles other input as mm/dd/yy. (which is kind-of un-natural for those using this form)
how should I modify this python script...
today=DateTime(input) return today.strftime("%d %B %Y")
... to alert Zope that the incoming string will be always in the order of dd mm yyyy?
This is the traceback when the first tuple is not a valid month.
<!--
Traceback (innermost last): File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 223, in publish_module File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 187, in publish File D:\Zope\2-3-3\lib\python\Zope\__init__.py, line 221, in zpublisher_exception_hook (Object: Traversable) File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 171, in publish File D:\Zope\2-3-3\lib\python\ZPublisher\mapply.py, line 160, in mapply (Object: template) File D:\Zope\2-3-3\lib\python\ZPublisher\Publish.py, line 112, in call_object (Object: template) File D:\Zope\2-3-3\lib\python\OFS\DTMLMethod.py, line 189, in __call__ (Object: template) File D:\Zope\2-3-3\lib\python\DocumentTemplate\DT_String.py, line 540, in __call__ (Object: template) File D:\Zope\2-3-3\lib\python\DocumentTemplate\DT_Util.py, line 339, in eval (Object: stringdate(purc_date)) (Info: stringdate) File <string>, line 0, in ? File D:\Zope\Products\PythonMethod\PythonMethod.py, line 168, in __call__ (Object: stringdate) (Info: (('21/12/2003',), {}, None)) File <string>, line 2, in stringdate File D:\Zope\2-3-3\lib\python\DateTime\DateTime.py, line 708, in __init__ File D:\Zope\2-3-3\lib\python\DateTime\DateTime.py, line 1050, in _parse Invalid Date Components: 21/12/2003 -->
Cheers,
Julian Clark
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
participants (3)
-
Andreas Jung -
Jens Vagelpohl -
Julian Clark