[Zope] another one IS split date

hans hans@beehive.de
Tue, 26 Feb 2002 12:27:31 +0000


>I'm trying to reformat a date that I'm getting from our Sybase server.
I
>get it in yyyy/mm/dd format and I'm trying to change it to mm/dd/yyyy
>format. I've created a DTML method called fixDate that looks like this:

>
><dtml-call expr="REQUEST.set('date', _.str(date))">
><dtml-let newDate="date.split('/')" month="newDate[1]" day="newDate[2]"

>year="newDate[0]">
><dtml-var month>/<dtml-var day>/<dtml-var year>
></dtml-let>
>
>It works if I call http://www.ourdomain.com/fixDate?date=2002/12/25,
but
>if I try to use it from a DTML document I get:
>
>Error Type: NameError
>Error Value: global name 'REQUEST' is not defined
>
>If I take out the first line then I get:
>
>Error Type: AttributeError
>Error Value: split
>
>which is what prompted me to put it in to begin with. Any ideas?

1: date has no split method, string module has. use like _.string.split(
YourString)
2: calling DTML Methods w parameters is beautiful explained in
http://zdp.zope.org/projects/zsnippet/snippets/DTMLTags/CallingDTMLMethods

or read http://www.zope.org/Members/michel/ZB, appendix A&B
3: still too amitious. better use inline
<dtml-let newDate=" _.str(date)"
      year="newDate[:3]"  month="newDate[5:6] day="newDate[-2:]"
year="newDate[0]">
<dtml-var month>/<dtml-var day>/<dtml-var year>
</dtml-let>

cheers
--
--------------------------------------------------------------
hans augustin  (software developer)           hans@beehive.de
beehive elektronische medien GmbH       http://www.beehive.de
phone: +49 30 847-82 0                  fax: +49 30 847-82 299