Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-gonzalez committed Feb 18, 2018
1 parent 9314116 commit 3e62abf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
62 changes: 39 additions & 23 deletions dist/easytimer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* easytimer.js
* Generated: 2018-01-26
* Version: 2.0.3
* Generated: 2018-02-18
* Version: 2.1.0
*/

(function (global, factory) {
Expand Down Expand Up @@ -172,11 +172,16 @@ function Timer() {
}
};

function updateCounters(precision, value) {
var roundedValue = Math.floor(value);

function updateCounters(precision, roundedValue) {
totalCounters[precision] = roundedValue;
counters[precision] = precision !== DAYS ? mod(roundedValue, groupedUnits[precision]) : roundedValue;

if (precision === DAYS) {
counters[precision] = roundedValue;
} else if (roundedValue >= 0) {
counters[precision] = mod(roundedValue, groupedUnits[precision]);
} else {
counters[precision] = groupedUnits[precision] - mod(roundedValue, groupedUnits[precision]);
}
}

function updateDays(value) {
Expand All @@ -201,7 +206,7 @@ function Timer() {

function updateUnitByPrecision(value, precision) {
var previousValue = totalCounters[precision];
updateCounters(precision, value / unitsInMilliseconds[precision]);
updateCounters(precision, calculateIntegerUnitQuotient(value, unitsInMilliseconds[precision]));

return totalCounters[precision] !== previousValue;
}
Expand Down Expand Up @@ -248,6 +253,20 @@ function Timer() {

function updateTimerAndDispatchEvents() {
var currentTime = roundTimestamp(Date.now());
var valuesUpdated = updateTimer();

dispatchEvents(valuesUpdated);

customCallback(eventData.detail.timer);
if (isTargetAchieved(currentTime)) {
stop();
dispatchEvent('targetAchieved', eventData);
}
}

function updateTimer() {
var currentTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : roundTimestamp(Date.now());

var ellapsedTime = timerTypeFactor > 0 ? currentTime - startingDate : startingDate - currentTime;
var valuesUpdated = {};

Expand All @@ -256,13 +275,8 @@ function Timer() {
valuesUpdated[MINUTES] = updateMinutes(ellapsedTime);
valuesUpdated[HOURS] = updateHours(ellapsedTime);
valuesUpdated[DAYS] = updateDays(ellapsedTime);
dispatchEvents(valuesUpdated);

customCallback(eventData.detail.timer);
if (isTargetAchieved(currentTime)) {
stop();
dispatchEvent('targetAchieved', eventData);
}
return valuesUpdated;
}

function roundTimestamp(timestamp) {
Expand Down Expand Up @@ -322,6 +336,8 @@ function Timer() {

startingDate = calculateStartingDate();

updateTimer();

if (_typeof(params.target) === 'object') {
targetValues = setTarget(params.target);
} else if (countdown) {
Expand Down Expand Up @@ -358,17 +374,11 @@ function Timer() {
}
}

for (var i = 0; i < inputValues.length; i = i + 1) {
if (inputValues[i] < 0) {
inputValues[i] = 0;
}
}

secondTenths = values[SECOND_TENTHS_POSITION];
seconds = values[SECONDS_POSITION] + Math.floor(secondTenths / SECOND_TENTHS_PER_SECOND);
minutes = values[MINUTES_POSITION] + Math.floor(seconds / SECONDS_PER_MINUTE);
hours = values[HOURS_POSITION] + Math.floor(minutes / MINUTES_PER_HOUR);
days = values[DAYS_POSITION] + Math.floor(hours / HOURS_PER_DAY);
seconds = values[SECONDS_POSITION] + calculateIntegerUnitQuotient(secondTenths, SECOND_TENTHS_PER_SECOND);
minutes = values[MINUTES_POSITION] + calculateIntegerUnitQuotient(seconds, SECONDS_PER_MINUTE);
hours = values[HOURS_POSITION] + calculateIntegerUnitQuotient(minutes, MINUTES_PER_HOUR);
days = values[DAYS_POSITION] + calculateIntegerUnitQuotient(hours, HOURS_PER_DAY);

values[SECOND_TENTHS_POSITION] = secondTenths % SECOND_TENTHS_PER_SECOND;
values[SECONDS_POSITION] = seconds % SECONDS_PER_MINUTE;
Expand All @@ -379,6 +389,12 @@ function Timer() {
return values;
}

function calculateIntegerUnitQuotient(unit, divisor) {
var quotient = unit / divisor;

return quotient < 0 ? Math.ceil(quotient) : Math.floor(quotient);
}

function setTarget(inputTarget) {
if (!inputTarget) {
return;
Expand Down
6 changes: 3 additions & 3 deletions 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 dist/examples.min.js

Large diffs are not rendered by default.

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": "2.0.3",
"version": "2.1.0",
"description": "Timer/Chronometer/Countdown compatible with AMD and NodeJS",
"main": "dist/easytimer.js",
"repository": {
Expand Down

0 comments on commit 3e62abf

Please sign in to comment.