-
Notifications
You must be signed in to change notification settings - Fork 3
/
fluent-time.min.js
1 lines (1 loc) · 2.3 KB
/
fluent-time.min.js
1
!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.FluentTime=e()}(this,function(){"use strict";var t=function(t,e){for(var i in t.prototype)e.prototype[i]=t.prototype[i]},e={every:function(t){return new e.Interval(t)},after:function(t){return new e.TimeOut(t)}};return e.TimeLeap=function(t){this.leap=t||1,this.ms=0},e.TimeLeap.prototype.days=function(t){return this.ms+=864e5*this.leap,this.leap=0,this.finalizeIfCallback(t),this},e.TimeLeap.prototype.day=function(t){return this.days(t)},e.TimeLeap.prototype.hours=function(t){return this.ms+=36e5*this.leap,this.leap=0,this.finalizeIfCallback(t),this},e.TimeLeap.prototype.hour=function(t){return this.hours(t)},e.TimeLeap.prototype.minutes=function(t){return this.ms+=6e4*this.leap,this.leap=0,this.finalizeIfCallback(t),this},e.TimeLeap.prototype.minute=function(t){return this.minutes(t)},e.TimeLeap.prototype.seconds=function(t){return this.ms+=1e3*this.leap,this.leap=0,this.finalizeIfCallback(t),this},e.TimeLeap.prototype.second=function(t){return this.seconds(t)},e.TimeLeap.prototype.milliseconds=function(t){return this.ms+=this.leap,this.leap=0,this.finalizeIfCallback(t),this},e.TimeLeap.prototype.millisecond=function(t){return this.milliseconds(t)},e.TimeLeap.prototype.and=function(t){return this.leap=t,this},e.TimeLeap.prototype.finalizeIfCallback=function(t){t&&"function"==typeof t&&this.schedule(t,this.ms)},e.TimeLeap.prototype.occurs=function(){return new Date(Date.now()+this.ms)},e.TimeLeap.prototype.schedule=function(){},e.TimeOut=function(){e.TimeLeap.apply(this,arguments)},t(e.TimeLeap,e.TimeOut),e.TimeOut.prototype.schedule=function(t){var e=this;this.timeout=setTimeout(function(){t(e)},this.ms)},e.TimeOut.prototype.cancel=function(){return this.timeout&&clearTimeout(this.timeout),this},e.Interval=function(){e.TimeOut.apply(this,arguments),this.times=0,this.skippingNext=0},t(e.TimeOut,e.Interval),e.Interval.prototype.schedule=function(t,e){var i=this;this.timeout=setTimeout(function(){i.times++;var e=Date.now();i.skippingNext?i.skippingNext--:t(i);var n=Math.max(0,i.ms-(Date.now()-e));i.schedule(t,n)},e)},e.Interval.prototype.skip=function(t){if("undefined"==typeof t)t=1;else if("number"!=typeof t||1>t)throw new Error("You must provide a non negative number");return this.skippingNext+=t,this},e});