[Zope] ZopeTime questions (DTML mainly)
Martijn Pieters
mj@antraciet.nl
Fri, 15 Oct 1999 13:42:35 +0200
At 11:36 15/10/99 , Samu Mielonen wrote:
>Hello,
>
>I'm trying to figure out the ZopeTime object (or is it a method?)
>and how to use it.
>
>I've tried to render Finnish date and time, which is of format:
>
> dd.mm.yyyy, hh:mm:ss
>
>so for example:
>
> 15.10.1999m, 21:04:05
>
>means 15th of October, 1999 at four past nine pm (and 5 seconds)
>
>Rendering this visible with <dtml-var ZopeTime fmt=...> seems
>straightforward enough (here, without seconds):
>
> <dtml-var release fmt="%d.%m.%Y, %H:%M">
>
>but the problem is that %H (and %d, %m %Y too because of this?)
>are not from the current time zone (but from GMT?).
Yes, they are in GMT. This is the way default C libraries define it, and
therefore of little use to us..
>This means that if I use the above code at 11 o'clock a.m.
>Finnish time, I get result that says time is 9 o'clock a.m.
>
>More than that, if I want a render the time of an object
>that had a release date (of Finnish time) at 01:59 am
>on the 1st of November 1999, the above code would show a release
>time of 11:59 pm 31st of October 1999 (?)
>
>However, if I use the format:
>
> <dtml-var ZopeTime fmt="h_24">
>
>I get hours in 24-hour format in current time Zone (i.e.
>correct Finnish time).
>
>Rendering the time this way would require me to type:
>
> <dtml-var release fmt=day>.<dtml-var release fmt=month>.<dtml-var
> release
>fmt=year>,
> <dtml-var release fmt=h_24>:<dtml-var release fmt=%M>
>
>am I correct? It seems to work ok, although I haven't checked whether the
>"day"
>changes according to GMT or current time zone (if it changes according to
>GMT
>hours, then I'm in trouble. Same for "month" and "year").
>
>However, a few of questions puzzle me:
>
>1) Are day, month, year and h_24 synchronized whereas %d,%m,%Y,%H
>are synchronised differently? (i.e. one should not mix them in order
>to avoid funny date/times).
No. Try and display 01/10/1999 00:00 and you'l see it will display a
different date. Dates play along in the timezone game as well.
>2)
>Why are the formats different? I couldnt find reason/documentation as
>to why one reports hours in current timezone and other in GMT. Or have
>I misunderstood something completelly?
The documentation can be found in the Python library reference. See the
time module, and specifically the strftime method. It is used to support
the fmt="%h:%m" like formats.
>3)
>Are the two options (using one dtml-var ZopeTime vs using multiple ones)
>equal in the load they put on Zope? I would assume that a simple dtml-var
>call would be less of a load, no?
>
>This may not sound like an important issue, but if the latter approach
>puts a five-fold increase on zope and I have to call that dtml method
>giving Finnish time, say 100 times on a page, well it might have an impact
>(?)
It adds a little overhead, but nothing noticable.
>4) Can I somehow add the time zone difference to the time with simple add
>operation? i.e. can I use the <dtml-var release fmt="%d.%m.%Y, klo %H:%M">
>format and somehow just tell that: "add +2 hours" to that time?
>
>I'm assuming there isn't an add operation for timestamp data types in dtml?
>If there is one, is it clever enough to understand that when hours are
>overflowed, it has to tick one more day and deduct appropriately
>from hours (the same for month and years of course)?
>
>How would I accomplish this (my apologies if a lot of my
>questions are about my inability to grok the syntax properly).
I stopped trying to use the format. I use a different aproach:
<dtml-with ZopeTime>
<dtml-var "'%02i/%02i/%i %s' % (day, month, year, Time)">
</dtml-with>
>5)
>If I want to make a simple time comparison between release date property
>of an object and current time, how do I do it (e.g. if I only want to
>compare, say that the dates are same - not caring about years, months or
>hours and seconds). If my current object has a property release which
>has been set to ZopeTime at the time of creation:
>
>I've tried making an equality check between (i.e. the below
>pseudo code in gazillion variations):
>
> ZopeTime fmt=day = release fmt=day
>
>but "fmt" mucks up the syntax somehow (I don't know how to write
>the comparison when fmt=day is present). Without the fmt attribute:
>
> <dtml-if "ZopeTime=release">
>
>worked fine (I think). So, how do I compare just parts (say days) of
>two timestamp properties? Do I need to create an external method?
The DateTime module has several comparison methods to do this. Remember
that ZopeTime is a method as well. Here are some examples:
ZopeTime().equalTo(release)
ZopeTime().greaterThen(release)
release.isPast()
These methods can be found in the source of the DateTime module, and there
is also a HTML page with some documentation in the lib/python/DateTime
subdir of your Zope install.
--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------