From e50cb4750317fad3927ee78c65cdd289c6a725a3 Mon Sep 17 00:00:00 2001 From: ali yeganeh Date: Tue, 17 Nov 2020 21:42:32 +0330 Subject: [PATCH 1/3] replace currentTime with startTime change system clock on client side was effecting on time counter duration --- jquery.simple.timer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jquery.simple.timer.js b/jquery.simple.timer.js index 3802497..e5f9647 100644 --- a/jquery.simple.timer.js +++ b/jquery.simple.timer.js @@ -191,6 +191,7 @@ this.setFinalValue(this.formatTimeLeft(timeLeft), element); intervalId = setInterval((function() { + this.forwardCurrentTime(); timeLeft = endTime - this.currentTime(); // When timer has been idle and only resumed past timeout, // then we immediatelly complete the timer. @@ -210,6 +211,9 @@ element.find('.jst-hours').text('00:'); }; + Timer.prototype.forwardCurrentTime = function () { + startTime += 1000; + }; Timer.prototype.currentTime = function() { return Math.round((new Date()).getTime() / 1000); }; @@ -259,8 +263,9 @@ element.find('.' + this._options.classNameHours).text(finalValues.pop() + ':'); }; - +var startTime; $.fn.startTimer = function(options) { + startTime= new Date().getTime(); this.TimerObject = Timer; Timer.start(options, this); return this; From 04aa7793f030caf98027d3e4a5aa8c3aaae5d8ff Mon Sep 17 00:00:00 2001 From: ali yeganeh Date: Tue, 17 Nov 2020 21:44:56 +0330 Subject: [PATCH 2/3] replace current time with start time --- jquery.simple.timer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.simple.timer.js b/jquery.simple.timer.js index e5f9647..42a3455 100644 --- a/jquery.simple.timer.js +++ b/jquery.simple.timer.js @@ -215,7 +215,7 @@ startTime += 1000; }; Timer.prototype.currentTime = function() { - return Math.round((new Date()).getTime() / 1000); + return Math.round(startTime / 1000); }; Timer.prototype.formatTimeLeft = function(timeLeft) { From edb37fc1901dd9efc0e285ed2f85c65a370f8d25 Mon Sep 17 00:00:00 2001 From: ali yeganeh Date: Fri, 20 Nov 2020 16:24:10 +0330 Subject: [PATCH 3/3] replace current time with start time replace current time with start time --- jquery.simple.timer.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jquery.simple.timer.js b/jquery.simple.timer.js index 42a3455..8c5f290 100644 --- a/jquery.simple.timer.js +++ b/jquery.simple.timer.js @@ -37,6 +37,7 @@ var timer; var Timer = function(targetElement){ + this.startTime = new Date().getTime(); this._options = {}; this.targetElement = targetElement; return this; @@ -211,12 +212,13 @@ element.find('.jst-hours').text('00:'); }; - Timer.prototype.forwardCurrentTime = function () { - startTime += 1000; - }; - Timer.prototype.currentTime = function() { - return Math.round(startTime / 1000); - }; + Timer.prototype.forwardCurrentTime = function () { + this.startTime += 1000; + }; + + Timer.prototype.currentTime = function () { + return Math.round(this.startTime / 1000); + }; Timer.prototype.formatTimeLeft = function(timeLeft) { @@ -263,9 +265,7 @@ element.find('.' + this._options.classNameHours).text(finalValues.pop() + ':'); }; -var startTime; $.fn.startTimer = function(options) { - startTime= new Date().getTime(); this.TimerObject = Timer; Timer.start(options, this); return this;