Confused about manipulating dates in DTML
I have some objects that represent dates in ISO 8601 format, e.g., "2000-04-21". Within my DocumentTemplate I'd like to present those dates to users in a little nicer format. With the attribute "start" containing the date I tried: <dtml-var "_.DateTime(start).Date()"> This yields a TypeError during rendering: ... File /usr/lib/python1.5/site-packages/DocumentTemplate/DT_In.py, line 691, in renderwob (Object: entries) File /usr/lib/python1.5/site-packages/DocumentTemplate/DT_Util.py, line 321, in eval (Object: _.DateTime(start).Date()) File <string>, line 0, in ? TypeError: illegal argument type for built-in operation I then tried: <dtml-var "_.DateTime(start)"> but got the same error. Table 2 in the DTML manual states: DateTime(): Create a DateTime object from zero or more arguments. See Appendix A, Date-time data on page 41. Unfortunately, Appendix A only has this to say about creating DateTime objects: From DTML, the special variable _ provides a method for constructing date-time values from strings and numeric data. but gives no details about how to call the DateTime constructor. It seems to only list the attributes understood by DateTime objects. It gives no clues (that I can see) about how to actually create DateTime objects from strings. On the assumption that Zope's DateTime stuff is just a wrapper around Marc-Andre Lemburg's mxDateTime I tried: <dtml-var "_.DateTimeFrom(start)"> thinking that constructor might just not have been documented. Calling it yielded an AttributeError for DateTimeFrom however. What's a poor fella to do? Thx, -- Skip Montanaro | http://www.mojam.com/ skip@mojam.com | http://www.musi-cal.com/
Hello, from your tracebacks it seems that what your passing in is not a string to date time. i tried both of the methods you list below passing in the string explicitly and they work fine. you might have another variable named start in your namespace. you might want to try a dtml-var start and see what it gets. if start is in the request, try passing it in explicitly with dtml-var "_.DateTime(REQUEST.start)" the source is always the best resource. zope's date time module is a dc thing. it has pretty decent source documentation on the formats it will accept. its in /lib/DateTime/DateTime.py also regarding formating DateTime objects you might want to check the ZQR at the ZDP and also the HowTo (search on date). Cheers Kapil Skip Montanaro wrote:
I have some objects that represent dates in ISO 8601 format, e.g., "2000-04-21". Within my DocumentTemplate I'd like to present those dates to users in a little nicer format. With the attribute "start" containing the date I tried:
<dtml-var "_.DateTime(start).Date()">
This yields a TypeError during rendering:
... File /usr/lib/python1.5/site-packages/DocumentTemplate/DT_In.py, line 691, in renderwob (Object: entries) File /usr/lib/python1.5/site-packages/DocumentTemplate/DT_Util.py, line 321, in eval (Object: _.DateTime(start).Date()) File <string>, line 0, in ? TypeError: illegal argument type for built-in operation
I then tried:
<dtml-var "_.DateTime(start)">
but got the same error.
!!!!!!!!snip-snap!!!!!!!!!!!
participants (2)
-
Kapil Thangavelu -
Skip Montanaro