clock-interval

1.1.0 • Public • Published

perfect-interval

A precise interval timer pinned to system clock

How to use

npm install clock-interval

Example usage

Update an element with the currnt time

var clockInterval = require('clock-interval');
 
function pad(num) {
  return ('0' + num).slice(-2);
}
  
clockInterval(function() {
    var clockEl = document.getElementById('clock'),
        dateObj = new Date(); 
      clockEl.innerHTML = pad(dateObj.getHours()) + ':' + pad(dateObj.getMinutes()) + ':' + pad(dateObj.getSeconds());
});

Cancel the interval

var timer = clockInterval(function() {});
 
// Cancel the timer
timer.cancel();

Why not use setInterval?

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.0
    0
  • 1.0.0
    1

Package Sidebar

Install

npm i clock-interval

Weekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • taylorhakes