[Zope] ZopeTime questions (DTML mainly)
Samu Mielonen
ex@uiah.fi
Fri, 15 Oct 1999 12:36:52 +0300
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?).
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).
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?
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
(?)
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).
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?
Again, any help is appreciated. The previous comments were
right on spot. Much thanks to Michel Pelletier for taking time
to answer my questions.
Best regards,
Samu Mielonen
PS Kudos to the Zope Quick Reference team. I've found the 0.8 version
to be invaluable and I've only used it for a day :)
--
"Our reflections on the order of society, as well as nature, are still
dominated by the Newtonian image of massive power, exerted by sovereign
agency through the operation of central force..." -Stephen Toulmin,
"Cosmopolis"