Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const timer = {
  2.       time: 0,
  3.       timeStart: 0,
  4.       timeEnd: 0,
  5.       interval: 50,
  6.  
  7.       init: function() {
  8.         this.timeStart = new Date();
  9.       },
  10.  
  11.       setTimeStart: function() {
  12.         if (this.timeStart == 0) {
  13.           this.timeStart = Math.floor(Date.now() / 1000);
  14.         }
  15.       },
  16.  
  17.       start: function() {
  18.         this.setTimeStart();
  19.  
  20.         var now = Math.floor(Date.now() / 1000); // get the time now
  21.         var diff = now - this.timeStart; // diff in seconds between now and start
  22.  
  23.         // console.log('now', now);
  24.         // console.log('timestart', this.timeStart);
  25.         console.log('diff', diff);
  26.         this.sync(diff);
  27.  
  28.         setTimeout(this.start(), this.interval * 1000); // set a timeout to update the timer
  29.       },
  30.  
  31.       stop: function() {
  32.         clearTimeout(this.start());
  33.       },
  34.  
  35.       sync: function(time) {
  36.  
  37.       }
  38.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement