I don't think I was clear enough with the cause so I'll try to explain it
better
first off here is the code in question
<div id="system_clock_container">Zenoss server time:
<span id="system_clock">Now o'clock</span>
<script tal:content="string: var start_time = '${here/server_time}';">
var x;
</script>
<script>
var timedelta = new Date().getTime() - isoTimestamp(start_time).getTime();
var isIE//@cc_on=1;
if (isIE) timedelta -= 25000;
function updateTime(){
var servernow = new Date(new Date().getTime() + timedelta);
$('system_clock').innerHTML = toISOTime(servernow);
callLater(1, updateTime);
}
addLoadEvent(updateTime);
</script>
</div>
I will walk thru and show you the flaws.
Lets say my server time is set to UTC it's clock says January 17 2008 13:30:00
UTC thats 7:30:00 CST
Lets say my Workstation is set to CST it's January 17 2008 7:30:00
ok when the page loads it gets the server time
<script tal:content="string: var start_time = '${here/server_time}';">
$ZENHOME/Products/ZenModel/skins/zenmodel/templates.pt calls ${here/server_time}
which calls the server_time() method in
$ZENHOME/Products/ZenModel/ZentinelPortal.py
def server_time(self):
return Time.isoDateTime()
which calls the isoDateTime() method in $ZENHOME/Products/ZenUtils/Time.py
def isoDateTime(gmtSecondsSince1970 = None):
value = _maybenow(gmtSecondsSince1970)
secs = value % 60
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(value))
which calls the _maybenow() method in $ZENHOME/Products/ZenUtils/Time.py
def _maybenow(gmtSecondsSince1970):
if gmtSecondsSince1970 is None:
return time.time()
return int(gmtSecondsSince1970)
which calls the time() method in Python's standard library
Time.time()
So if you work backwards
Time.time() returns 1200576600.000000
_maybenow returns 1200576600.000000
isoDateTime() returns '2008-01-17 13:30:00'
now this is where the issue comes into play say the server is set to CST and
you work backwards
Time.time() returns 1200576600.000000
_maybenow returns 1200576600.000000
isoDateTime() returns '2008-01-17 7:30:00'
to test this you can do the following
#change your system to CST
rm -f localtime
ln -s /usr/share/zoneinfo/CST6CDT localtime
#go to a python shell and run
import time
value = time.time()
secs = value % 60
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(value))
#now change your system to UST
rm -f localtime
ln -s /usr/share/zoneinfo/UTC localtime
#go to a python shell again and run
import time
value = time.time()
secs = value % 60
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(value))
as you can see the times have no timezeone
'2008-01-17 13:30:00'
'2008-01-17 7:30:00'
now going into the javascript you have
'2008-01-17 13:30:00' or '2008-01-17 7:30:00'
var start_time = '2008-01-17 13:30:00';
//fake this line
//var timedelta = new Date().getTime() - isoTimestamp(start_time).getTime();
var timedelta = 1200576600000 - 1200598200000
//fake this line
//var servernow = new Date(new Date().getTime() + timedelta);
var servernow = 1200576600000 + timedelta;
//$('system_clock').innerHTML = toISOTime(servernow);
//fake this line
document.write(Thu Jan 17 2008 01:30:00 GMT-0600 (CST));
var start_time = '2008-01-17 7:30:00';
//fake this line
//var timedelta = new Date().getTime() - isoTimestamp(start_time).getTime();
var timedelta = 1200576600000 - 1200576600000
//fake this line
//var servernow = new Date(new Date().getTime() + timedelta);
var servernow = 1200576600000 + timedelta;
//$('system_clock').innerHTML = toISOTime(servernow);
//fake this line
document.write(servernow);
document.write(Thu Jan 17 2008 07:30:00 GMT-0600 (CST)));
as you can see The Times are wrong based on the there is no timezone in the
python function isoDateTime()
The other issue about the time being off is because of the offset between your
workstation time and the server time.
such as if you local clock was set to 7:25 cst and your server was set to 7:30
cst
zenoss would display Thu Jan 17 2008 07:20:00 GMT-0600 (CST)
Hope this explains everything the only way to get the true time is to take out
the local workstation time and get the time from just the server somehow.
Thanks,
Pete
-------------------- m2f --------------------
Read this topic online here:
http://community.zenoss.com/forums/viewtopic.php?p=15453#15453
-------------------- m2f --------------------
_______________________________________________
zenoss-users mailing list
[email protected]
http://lists.zenoss.org/mailman/listinfo/zenoss-users