Skip to content

replace current time with start time #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions jquery.simple.timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
var timer;

var Timer = function(targetElement){
this.startTime = new Date().getTime();
this._options = {};
this.targetElement = targetElement;
return this;
Expand Down Expand Up @@ -191,6 +192,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.
Expand All @@ -210,9 +212,13 @@
element.find('.jst-hours').text('00:');
};

Timer.prototype.currentTime = function() {
return Math.round((new Date()).getTime() / 1000);
};
Timer.prototype.forwardCurrentTime = function () {
this.startTime += 1000;
};

Timer.prototype.currentTime = function () {
return Math.round(this.startTime / 1000);
};

Timer.prototype.formatTimeLeft = function(timeLeft) {

Expand Down Expand Up @@ -259,7 +265,6 @@
element.find('.' + this._options.classNameHours).text(finalValues.pop() + ':');
};


$.fn.startTimer = function(options) {
this.TimerObject = Timer;
Timer.start(options, this);
Expand Down