Skip to content

Commit

Permalink
Merge pull request #20 from albert-gonzalez/countdown_fix
Browse files Browse the repository at this point in the history
Countdown fix
  • Loading branch information
albert-gonzalez authored Sep 25, 2017
2 parents 87db03a + ce1e26c commit 154441d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easytimer.js",
"version": "1.3.1",
"version": "1.3.2",
"authors": [
"Albert Gonzalez ([email protected])"
],
Expand Down
2 changes: 1 addition & 1 deletion dist/easytimer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easytimer.js",
"version": "1.3.1",
"version": "1.3.2",
"description": "Timer/Chronometer/Countdown compatible with AMD and NodeJS",
"main": "src/timer.js",
"directories": {
Expand Down
11 changes: 8 additions & 3 deletions src/easytimer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license easytimer.js v1.2
* @license easytimer.js v1.3.2
* Created by Albert González
* Licensed under The MIT License.
*
Expand Down Expand Up @@ -241,7 +241,7 @@ var Timer = (

var interval = unitsInMilliseconds[precision];

startingDate = Date.now() - totalCounters.secondTenths
startingDate = roundTimestamp(Date.now()) - totalCounters.secondTenths
* unitsInMilliseconds[SECOND_TENTHS]
* timerTypeFactor;

Expand All @@ -255,7 +255,8 @@ var Timer = (
}

function updateTimerAndDispatchEvents() {
var ellapsedTime = timerTypeFactor > 0 ? (Date.now() - startingDate) : (startingDate - Date.now()),
var currentTime = roundTimestamp(Date.now());
var ellapsedTime = timerTypeFactor > 0 ? (currentTime - startingDate) : (startingDate - currentTime),
valuesUpdated = {};

valuesUpdated[SECOND_TENTHS] = updateSecondTenths(ellapsedTime);
Expand All @@ -272,6 +273,10 @@ var Timer = (
}
}

function roundTimestamp(timestamp) {
return Math.floor(timestamp / unitsInMilliseconds[precision]) * unitsInMilliseconds[precision];
}

function dispatchEvents(valuesUpdated) {
if (valuesUpdated[SECOND_TENTHS]) {
dispatchEvent('secondTenthsUpdated', eventData);
Expand Down

0 comments on commit 154441d

Please sign in to comment.