lib/time.js
function timeSynchronization(serverTime, requestDuration) {
    var logger = getLogger('time.timeSynchronization');
    var localTime = Math.floor(new Date().getTime() / 1000);
    var response = requestDuration / 2;
    if (logger.isDebugEnabled()) {
        logger.debug('ServerTime %ss - LocalTime %ss - Response in %sms',
            serverTime, localTime, response);
    }
    if (lastResponse > response) {
        lastResponse = response;
        response = Math.floor(response / 1000);
        timeOffset = ((serverTime + response) - localTime);
        if (logger.isDebugEnabled()) {
            logger.debug('time-synchronization: (ServerTime %ss + server-response %ss) - LocalTime %ss = timeOffset %ss',
                serverTime, response, localTime, timeOffset);
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug('NO time-synchronization: the server-response (%s) took more time than the previous one (%s)',
                response, lastResponse);
        }
    }
}
function timeSynchronization(serverTime, requestDuration) {
    var logger = getLogger('time.timeSynchronization');
    var localTime = Math.floor(new Date().getTime() / 1000);
    var response = requestDuration / 2;
    if (logger.isDebugEnabled()) {
        logger.debug('ServerTime %ss - LocalTime %ss - Response in %sms',
            serverTime, localTime, response);
    }
    if (lastResponse > response) {
        lastResponse = response;
        response = Math.floor(response / 1000);
        timeOffset = ((serverTime + response) - localTime);
        if (logger.isDebugEnabled()) {
            logger.debug('time-synchronization: (ServerTime %ss + server-response %ss) - LocalTime %ss = timeOffset %ss',
                serverTime, response, localTime, timeOffset);
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug('NO time-synchronization: the server-response (%s) took more time than the previous one (%s)',
                response, lastResponse);
        }
    }
}
function timeSynchronization ( serverTime , requestDuration ) { var logger = getLogger ( 'time.timeSynchronization' ) ; var localTime = Math . floor ( new Date ( ) . getTime ( ) / 1000 ) ; var response = requestDuration / 2 ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( 'ServerTime %ss - LocalTime %ss - Response in %sms' , serverTime , localTime , response ) ; } if ( lastResponse > response ) { lastResponse = response ; response = Math . floor ( response / 1000 ) ; timeOffset = ( ( serverTime + response ) - localTime ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( 'time-synchronization: (ServerTime %ss + server-response %ss) - LocalTime %ss = timeOffset %ss' , serverTime , response , localTime , timeOffset ) ; } } else { if ( logger . isDebugEnabled ( ) ) { logger . debug ( 'NO time-synchronization: the server-response (%s) took more time than the previous one (%s)' , response , lastResponse ) ; } } }
Synchronize the local time with the server time
Synchronize the local time with the server time