Implementation of Server time display on Client machine

As per a client’s requirement we had to display the time on the header of the application screen. Thus we implemented the javascript code to diplay the time on the application. But when the transaction was being done from that machine, the transaction time differed from the time that was displayed on the screen.

This happened because the transaction time was the time of server and the time displayed was the client machine time. The client then gave us the requirement that he wanted the server time to be displayed on the header so that the user gets to know at what time the server is running on.

While displaying the server time on client machine we faced a problem as it cannot be done by using only javascirpt. This happens because java script runs on client-side. In order to display server-side time on a client machine, we implemented a python-javascript combination on openerp application (displayed on the header of the screen) as a Timer.

Following is the javascript code for incrementing time from server at client side:

Note: We have used python for transmitting server time sas json dictionary and passed it to below mentioned url(‘url’: “/web/servertime/get_time”) in javascript

openerp.web_server_time = function (openerp) {

openerp.web.Header = openerp.web.Header.extend({
do_update: function(){
var self = this;
openerp.connection.rpc_json({‘url’: “/web/servertime/get_time”}, {}).done(function(res){
var d = new Date();

console.log(“dddddddddd”, d,res.result);
d.setSeconds(d.getSeconds() + 1);
}, 1000);

var month = new Array();
month[0] = “Jan”;
month[1] = “Feb”;
month[2] = “Mar”;
month[3] = “Apr”;
month[4] = “May”;
month[5] = “June”;
month[6] = “July”;
month[7] = “Aug”;
month[8] = “Sep”;
month[9] = “Oct”;
month[10] = “Nov”;
month[11] = “Dec”;

function checkTime(i) {
if (i<10) {i = “0” + i.toString();};
return i;
startTime = function(){
$(“.header_corner_left”).text(checkTime (d.getFullYear()) + “-” + month[d.getMonth()] + “-” + checkTime (d.getDate()) +” “+checkTime (d.getHours()) + “:” + checkTime(d.getMinutes()) + “:” + checkTime (d.getSeconds()));

Join us here!

One response to “Implementation of Server time display on Client machine”

  1. Ajay Bajaj says:

    Thanks for such info

    I looking this from long time

    Can you post how to configure 2 machine with different OS like Windows 8 and Ubantu in Odoo.

You must be logged in to post a comment.