angular-moment icon indicating copy to clipboard operation
angular-moment copied to clipboard

Support for real time server time updates in amTimeAgo

Open MarkKerby opened this issue 10 years ago • 3 comments

getNow() does not support a server time that is updated in real time inside the amTimeAgo directive. This causes the time since text to be incorrect as amTimeAgoConfig.serverTime drifts from localDate.

The below code implements a fix for a dynamic server time however consideration will have to be made for users relying on the current behaviour.

function getNow() {
    var now;
    if (amTimeAgoConfig.serverTime) {
        now = amTimeAgoConfig.serverTime;
    }
    else {
        now = moment();
    }
    return now;
}

MarkKerby avatar Jul 15 '15 13:07 MarkKerby

@MarkKerby what is the use case for that? I can't think of a case where the local time of a machine will significantly drift in comparison with the server time?

urish avatar Sep 15 '15 11:09 urish

The nature of our application means we don’t want to rely too much on the user’s system clock. So we let it perform the seconds ticking but we resynchronize it at regular intervals. This prevents, for example a user who sets their clock backwards from being shown e.g. “In 10 minutes” for something that has already happened.

We appreciate that would be an unusual thing to do but we need to avoid showing incorrect information in all cases that we can.

MarkKerby avatar Sep 18 '15 15:09 MarkKerby

how can I use this config? am-server-time="{{serverTime}}" didn't work

yoavprat avatar Nov 09 '15 14:11 yoavprat