Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Merge e3e9f1c into f53e86f
Browse files Browse the repository at this point in the history
  • Loading branch information
Facundo Pedrazzini authored and Facundo Pedrazzini committed Jun 2, 2014
2 parents f53e86f + e3e9f1c commit cf218da
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions angular-moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,19 @@
* @description
* Defaults to false.
*/
withoutSuffix: false
withoutSuffix: false,

/**
* @ngdoc property
* @name angularMoment.config.amTimeAgoConfig#serverTime
* @propertyOf angularMoment.config:amTimeAgoConfig
* @returns {numeric} Date in milliseconds.
*
* @description
* When you need to use the time of your server.
* Defaults to null. Local time will be used.
*/
serverTime: null
})

/**
Expand All @@ -106,8 +118,23 @@
var currentValue;
var currentFormat = angularMomentConfig.format;
var withoutSuffix = amTimeAgoConfig.withoutSuffix;
var preprocess = angularMomentConfig.preprocess;
var localDate = new Date().getTime();

var preprocess = angularMomentConfig.preprocess;

function getNow() {
var now;
if (amTimeAgoConfig.serverTime) {
var localNow = new Date().getTime();
var nowMillis = localNow - localDate + amTimeAgoConfig.serverTime;
now = moment(nowMillis);
}
else {
now = moment();
}
return now;
}

function cancelTimer() {
if (activeTimeout) {
$window.clearTimeout(activeTimeout);
Expand All @@ -116,8 +143,8 @@
}

function updateTime(momentInstance) {
element.text(momentInstance.fromNow(withoutSuffix));
var howOld = moment().diff(momentInstance, 'minute');
element.text(momentInstance.from(getNow(), withoutSuffix));
var howOld = getNow().diff(momentInstance, 'minute');
var secondsUntilUpdate = 3600;
if (howOld < 1) {
secondsUntilUpdate = 1;
Expand Down

0 comments on commit cf218da

Please sign in to comment.