Skip to content

Timer Keeps on running if provided seconds are already greater than duration #90

@mohitYogi

Description

@mohitYogi

I faced an issue when passing seconds & duration to timer.
Suppose I passed 300 to seconds & 4 mins as duration than the timer never stops and the callback is never called.
Line number 260 in timer.jquery.js:


if (timerInstance.totalSeconds > 0 &&
		timerInstance.totalSeconds % timerInstance.config.duration === 0) {
		if (timerInstance.config.callback) {
			timerInstance.config.callback();
		}
		if (!timerInstance.config.repeat) {
			clearInterval(timerInstance.intervalId);
			setState(timerInstance, Constants.TIMER_STOPPED);
			timerInstance.config.duration = null;
		}
	}

I have changed it to :


if (timerInstance.totalSeconds > 0 && (
		timerInstance.totalSeconds % timerInstance.config.duration === 0 || 
		timerInstance.totalSeconds > timerInstance.config.duration )) {
		if (timerInstance.config.callback) {
			timerInstance.config.callback();
		}
		if (!timerInstance.config.repeat) {
			clearInterval(timerInstance.intervalId);
			setState(timerInstance, Constants.TIMER_STOPPED);
			timerInstance.config.duration = null;
		}
	}

Might save someones day.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions