forked from bunkat/later
-
Notifications
You must be signed in to change notification settings - Fork 0
/
later-core.min.js
1 lines (1 loc) · 16 KB
/
later-core.min.js
1
later=function(){var t={version:"1.1.6"};return Array.prototype.indexOf||(Array.prototype.indexOf=function(t){"use strict";if(null==this)throw new TypeError;var e=Object(this),n=e.length>>>0;if(0===n)return-1;var r=0;if(arguments.length>1&&(r=Number(arguments[1]),r!=r?r=0:0!=r&&1/0!=r&&r!=-1/0&&(r=(r>0||-1)*Math.floor(Math.abs(r)))),r>=n)return-1;for(var a=r>=0?r:Math.max(n-Math.abs(r),0);n>a;a++)if(a in e&&e[a]===t)return a;return-1}),String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),t.array={},t.array.sort=function(t,e){t.sort(function(t,e){return+t-+e}),e&&0===t[0]&&t.push(t.shift())},t.array.next=function(t,e,n){for(var r,a=0!==n[0],i=0,u=e.length-1;u>-1;--u){if(r=e[u],r===t)return r;if(!(r>t||0===r&&a&&n[1]>t))break;i=u}return e[i]},t.array.nextInvalid=function(t,e,n){for(var r=n[0],a=n[1],i=e.length,u=0===e[i-1]&&0!==r?a:0,v=t,l=e.indexOf(t),o=v;v===(e[l]||u);)if(v++,v>a&&(v=r),l++,l===i&&(l=0),v===o)return void 0;return v},t.array.prev=function(t,e,n){for(var r,a=e.length,i=0!==n[0],u=a-1,v=0;a>v;v++){if(r=e[v],r===t)return r;if(!(t>r||0===r&&i&&n[1]<t))break;u=v}return e[u]},t.array.prevInvalid=function(t,e,n){for(var r=n[0],a=n[1],i=e.length,u=0===e[i-1]&&0!==r?a:0,v=t,l=e.indexOf(t),o=v;v===(e[l]||u);)if(v--,r>v&&(v=a),l--,-1===l&&(l=i-1),v===o)return void 0;return v},t.day=t.D={name:"day",range:86400,val:function(e){return e.D||(e.D=t.date.getDate.call(e))},isValid:function(e,n){return t.D.val(e)===(n||t.D.extent(e)[1])},extent:function(e){if(e.DExtent)return e.DExtent;var n=t.M.val(e),r=t.DAYS_IN_MONTH[n-1];return 2===n&&366===t.dy.extent(e)[1]&&(r+=1),e.DExtent=[1,r]},start:function(e){return e.DStart||(e.DStart=t.date.next(t.Y.val(e),t.M.val(e),t.D.val(e)))},end:function(e){return e.DEnd||(e.DEnd=t.date.prev(t.Y.val(e),t.M.val(e),t.D.val(e)))},next:function(e,n){n=n>t.D.extent(e)[1]?1:n;var r=t.date.nextRollover(e,n,t.D,t.M),a=t.D.extent(r)[1];return n=n>a?1:n||a,t.date.next(t.Y.val(r),t.M.val(r),n)},prev:function(e,n){var r=t.date.prevRollover(e,n,t.D,t.M),a=t.D.extent(r)[1];return t.date.prev(t.Y.val(r),t.M.val(r),n>a?a:n||a)}},t.dayOfWeekCount=t.dc={name:"day of week count",range:604800,val:function(e){return e.dc||(e.dc=Math.floor((t.D.val(e)-1)/7)+1)},isValid:function(e,n){return t.dc.val(e)===n||0===n&&t.D.val(e)>t.D.extent(e)[1]-7},extent:function(e){return e.dcExtent||(e.dcExtent=[1,Math.ceil(t.D.extent(e)[1]/7)])},start:function(e){return e.dcStart||(e.dcStart=t.date.next(t.Y.val(e),t.M.val(e),Math.max(1,7*(t.dc.val(e)-1)+1||1)))},end:function(e){return e.dcEnd||(e.dcEnd=t.date.prev(t.Y.val(e),t.M.val(e),Math.min(7*t.dc.val(e),t.D.extent(e)[1])))},next:function(e,n){n=n>t.dc.extent(e)[1]?1:n;var r=t.date.nextRollover(e,n,t.dc,t.M),a=t.dc.extent(r)[1];n=n>a?1:n;var i=t.date.next(t.Y.val(r),t.M.val(r),0===n?t.D.extent(r)[1]-6:1+7*(n-1));return i.getTime()<=e.getTime()?(r=t.M.next(e,t.M.val(e)+1),t.date.next(t.Y.val(r),t.M.val(r),0===n?t.D.extent(r)[1]-6:1+7*(n-1))):i},prev:function(e,n){var r=t.date.prevRollover(e,n,t.dc,t.M),a=t.dc.extent(r)[1];return n=n>a?a:n||a,t.dc.end(t.date.prev(t.Y.val(r),t.M.val(r),1+7*(n-1)))}},t.dayOfWeek=t.dw=t.d={name:"day of week",range:86400,val:function(e){return e.dw||(e.dw=t.date.getDay.call(e)+1)},isValid:function(e,n){return t.dw.val(e)===(n||7)},extent:function(){return[1,7]},start:function(e){return t.D.start(e)},end:function(e){return t.D.end(e)},next:function(e,n){return n=n>7?1:n||7,t.date.next(t.Y.val(e),t.M.val(e),t.D.val(e)+(n-t.dw.val(e))+(n<=t.dw.val(e)?7:0))},prev:function(e,n){return n=n>7?7:n||7,t.date.prev(t.Y.val(e),t.M.val(e),t.D.val(e)+(n-t.dw.val(e))+(n>=t.dw.val(e)?-7:0))}},t.dayOfYear=t.dy={name:"day of year",range:86400,val:function(e){return e.dy||(e.dy=Math.ceil(1+(t.D.start(e).getTime()-t.Y.start(e).getTime())/t.DAY))},isValid:function(e,n){return t.dy.val(e)===(n||t.dy.extent(e)[1])},extent:function(e){var n=t.Y.val(e);return e.dyExtent||(e.dyExtent=[1,n%4?365:366])},start:function(e){return t.D.start(e)},end:function(e){return t.D.end(e)},next:function(e,n){n=n>t.dy.extent(e)[1]?1:n;var r=t.date.nextRollover(e,n,t.dy,t.Y),a=t.dy.extent(r)[1];return n=n>a?1:n||a,t.date.next(t.Y.val(r),t.M.val(r),n)},prev:function(e,n){var r=t.date.prevRollover(e,n,t.dy,t.Y),a=t.dy.extent(r)[1];return n=n>a?a:n||a,t.date.prev(t.Y.val(r),t.M.val(r),n)}},t.hour=t.h={name:"hour",range:3600,val:function(e){return e.h||(e.h=t.date.getHour.call(e))},isValid:function(e,n){return t.h.val(e)===n},extent:function(){return[0,23]},start:function(e){return e.hStart||(e.hStart=t.date.next(t.Y.val(e),t.M.val(e),t.D.val(e),t.h.val(e)))},end:function(e){return e.hEnd||(e.hEnd=t.date.prev(t.Y.val(e),t.M.val(e),t.D.val(e),t.h.val(e)))},next:function(e,n){n=n>23?0:n;var r=t.date.next(t.Y.val(e),t.M.val(e),t.D.val(e)+(n<=t.h.val(e)?1:0),n);return!t.date.isUTC&&r.getTime()<=e.getTime()&&(r=t.date.next(t.Y.val(r),t.M.val(r),t.D.val(r),n+1)),r},prev:function(e,n){return n=n>23?23:n,t.date.prev(t.Y.val(e),t.M.val(e),t.D.val(e)+(n>=t.h.val(e)?-1:0),n)}},t.minute=t.m={name:"minute",range:60,val:function(e){return e.m||(e.m=t.date.getMin.call(e))},isValid:function(e,n){return t.m.val(e)===n},extent:function(){return[0,59]},start:function(e){return e.mStart||(e.mStart=t.date.next(t.Y.val(e),t.M.val(e),t.D.val(e),t.h.val(e),t.m.val(e)))},end:function(e){return e.mEnd||(e.mEnd=t.date.prev(t.Y.val(e),t.M.val(e),t.D.val(e),t.h.val(e),t.m.val(e)))},next:function(e,n){var r=t.m.val(e),a=t.s.val(e),i=n>59?60-r:r>=n?60-r+n:n-r,u=new Date(e.getTime()+i*t.MIN-a*t.SEC);return!t.date.isUTC&&u.getTime()<=e.getTime()&&(u=new Date(e.getTime()+(i+120)*t.MIN-a*t.SEC)),u},prev:function(e,n){return n=n>59?59:n,t.date.prev(t.Y.val(e),t.M.val(e),t.D.val(e),t.h.val(e)+(n>=t.m.val(e)?-1:0),n)}},t.month=t.M={name:"month",range:2629740,val:function(e){return e.M||(e.M=t.date.getMonth.call(e)+1)},isValid:function(e,n){return t.M.val(e)===(n||12)},extent:function(){return[1,12]},start:function(e){return e.MStart||(e.MStart=t.date.next(t.Y.val(e),t.M.val(e)))},end:function(e){return e.MEnd||(e.MEnd=t.date.prev(t.Y.val(e),t.M.val(e)))},next:function(e,n){return n=n>12?1:n||12,t.date.next(t.Y.val(e)+(n>t.M.val(e)?0:1),n)},prev:function(e,n){return n=n>12?12:n||12,t.date.prev(t.Y.val(e)-(n>=t.M.val(e)?1:0),n)}},t.second=t.s={name:"second",range:1,val:function(e){return e.s||(e.s=t.date.getSec.call(e))},isValid:function(e,n){return t.s.val(e)===n},extent:function(){return[0,59]},start:function(t){return t},end:function(t){return t},next:function(e,n){var r=t.s.val(e),a=n>59?60-r:r>=n?60-r+n:n-r,i=new Date(e.getTime()+a*t.SEC);return!t.date.isUTC&&i.getTime()<=e.getTime()&&(i=new Date(e.getTime()+(a+7200)*t.SEC)),i},prev:function(e,n){return n=n>59?59:n,t.date.prev(t.Y.val(e),t.M.val(e),t.D.val(e),t.h.val(e),t.m.val(e)+(n>=t.s.val(e)?-1:0),n)}},t.time=t.t={name:"time",range:1,val:function(e){return e.t||(e.t=3600*t.h.val(e)+60*t.m.val(e)+t.s.val(e))},isValid:function(e,n){return t.t.val(e)===n},extent:function(){return[0,86399]},start:function(t){return t},end:function(t){return t},next:function(e,n){n=n>86399?0:n;var r=t.date.next(t.Y.val(e),t.M.val(e),t.D.val(e)+(n<=t.t.val(e)?1:0),0,0,n);return!t.date.isUTC&&r.getTime()<e.getTime()&&(r=t.date.next(t.Y.val(r),t.M.val(r),t.D.val(r),t.h.val(r),t.m.val(r),n+7200)),r},prev:function(e,n){return n=n>86399?86399:n,t.date.next(t.Y.val(e),t.M.val(e),t.D.val(e)+(n>=t.t.val(e)?-1:0),0,0,n)}},t.weekOfMonth=t.wm={name:"week of month",range:604800,val:function(e){return e.wm||(e.wm=(t.D.val(e)+(t.dw.val(t.M.start(e))-1)+(7-t.dw.val(e)))/7)},isValid:function(e,n){return t.wm.val(e)===(n||t.wm.extent(e)[1])},extent:function(e){return e.wmExtent||(e.wmExtent=[1,(t.D.extent(e)[1]+(t.dw.val(t.M.start(e))-1)+(7-t.dw.val(t.M.end(e))))/7])},start:function(e){return e.wmStart||(e.wmStart=t.date.next(t.Y.val(e),t.M.val(e),Math.max(t.D.val(e)-t.dw.val(e)+1,1)))},end:function(e){return e.wmEnd||(e.wmEnd=t.date.prev(t.Y.val(e),t.M.val(e),Math.min(t.D.val(e)+(7-t.dw.val(e)),t.D.extent(e)[1])))},next:function(e,n){n=n>t.wm.extent(e)[1]?1:n;var r=t.date.nextRollover(e,n,t.wm,t.M),a=t.wm.extent(r)[1];return n=n>a?1:n||a,t.date.next(t.Y.val(r),t.M.val(r),Math.max(1,7*(n-1)-(t.dw.val(r)-2)))},prev:function(e,n){var r=t.date.prevRollover(e,n,t.wm,t.M),a=t.wm.extent(r)[1];return n=n>a?a:n||a,t.wm.end(t.date.next(t.Y.val(r),t.M.val(r),Math.max(1,7*(n-1)-(t.dw.val(r)-2))))}},t.weekOfYear=t.wy={name:"week of year (ISO)",range:604800,val:function(e){if(e.wy)return e.wy;var n=t.dw.next(t.wy.start(e),5),r=t.dw.next(t.Y.prev(n,t.Y.val(n)-1),5);return e.wy=1+Math.ceil((n.getTime()-r.getTime())/t.WEEK)},isValid:function(e,n){return t.wy.val(e)===(n||t.wy.extent(e)[1])},extent:function(e){if(e.wyExtent)return e.wyExtent;var n=t.dw.next(t.wy.start(e),5),r=t.dw.val(t.Y.start(n)),a=t.dw.val(t.Y.end(n));return e.wyExtent=[1,5===r||5===a?53:52]},start:function(e){return e.wyStart||(e.wyStart=t.date.next(t.Y.val(e),t.M.val(e),t.D.val(e)-(t.dw.val(e)>1?t.dw.val(e)-2:6)))},end:function(e){return e.wyEnd||(e.wyEnd=t.date.prev(t.Y.val(e),t.M.val(e),t.D.val(e)+(t.dw.val(e)>1?8-t.dw.val(e):0)))},next:function(e,n){n=n>t.wy.extent(e)[1]?1:n;var r=t.dw.next(t.wy.start(e),5),a=t.date.nextRollover(r,n,t.wy,t.Y);1!==t.wy.val(a)&&(a=t.dw.next(a,2));var i=t.wy.extent(a)[1],u=t.wy.start(a);return n=n>i?1:n||i,t.date.next(t.Y.val(u),t.M.val(u),t.D.val(u)+7*(n-1))},prev:function(e,n){var r=t.dw.next(t.wy.start(e),5),a=t.date.prevRollover(r,n,t.wy,t.Y);1!==t.wy.val(a)&&(a=t.dw.next(a,2));var i=t.wy.extent(a)[1],u=t.wy.end(a);return n=n>i?i:n||i,t.wy.end(t.date.next(t.Y.val(u),t.M.val(u),t.D.val(u)+7*(n-1)))}},t.year=t.Y={name:"year",range:31556900,val:function(e){return e.Y||(e.Y=t.date.getYear.call(e))},isValid:function(e,n){return t.Y.val(e)===n},extent:function(){return[1970,2099]},start:function(e){return e.YStart||(e.YStart=t.date.next(t.Y.val(e)))},end:function(e){return e.YEnd||(e.YEnd=t.date.prev(t.Y.val(e)))},next:function(e,n){return n>t.Y.val(e)&&n<=t.Y.extent()[1]?t.date.next(n):t.NEVER},prev:function(e,n){return n<t.Y.val(e)&&n>=t.Y.extent()[0]?t.date.prev(n):t.NEVER}},t.fullDate=t.fd={name:"full date",range:1,val:function(t){return t.fd||(t.fd=t.getTime())},isValid:function(e,n){return t.fd.val(e)===n},extent:function(){return[0,3250368e7]},start:function(t){return t},end:function(t){return t},next:function(e,n){return t.fd.val(e)<n?new Date(n):t.NEVER},prev:function(e,n){return t.fd.val(e)>n?new Date(n):t.NEVER}},t.modifier={},t.modifier.after=t.modifier.a=function(t,e){var n=e[0];return{name:"after "+t.name,range:(t.extent(new Date)[1]-n)*t.range,val:t.val,isValid:function(t){return this.val(t)>=n},extent:t.extent,start:t.start,end:t.end,next:function(e,r){return r!=n&&(r=t.extent(e)[0]),t.next(e,r)},prev:function(e,r){return r=r===n?t.extent(e)[1]:n-1,t.prev(e,r)}}},t.modifier.before=t.modifier.b=function(t,e){var n=e[e.length-1];return{name:"before "+t.name,range:t.range*(n-1),val:t.val,isValid:function(t){return this.val(t)<n},extent:t.extent,start:t.start,end:t.end,next:function(e,r){return r=r===n?t.extent(e)[0]:n,t.next(e,r)},prev:function(e,r){return r=r===n?n-1:t.extent(e)[1],t.prev(e,r)}}},t.compile=function(e){function n(t){return"next"===t?function(t,e){return t.getTime()>e.getTime()}:function(t,e){return e.getTime()>t.getTime()}}var r,a=[],i=0;for(var u in e){var v=u.split("_"),l=v[0],o=v[1],d=e[u],f=o?t.modifier[o](t[l],d):t[l];a.push({constraint:f,vals:d}),i++}return a.sort(function(t,e){var n=t.constraint.range,r=e.constraint.range;return n>r?-1:r>n?1:0}),r=a[i-1].constraint,{start:function(e,n){for(var u,v=n,l=t.array[e],o=1e3;o--&&!u&&v;){u=!0;for(var d=0;i>d;d++){var f=a[d].constraint,c=f.val(v),x=f.extent(v),m=l(c,a[d].vals,x);if(!f.isValid(v,m)){v=f[e](v,m),u=!1;break}}}return v!==t.NEVER&&(v="next"===e?r.start(v):r.end(v)),v},end:function(e,r){for(var u,v=t.array[e+"Invalid"],l=n(e),o=i-1;o>=0;o--){var d,f=a[o].constraint,c=f.val(r),x=f.extent(r),m=v(c,a[o].vals,x);void 0!==m&&(d=f[e](r,m),!d||u&&!l(u,d)||(u=d))}return u},tick:function(e,n){return new Date("next"===e?r.end(n).getTime()+t.SEC:r.start(n).getTime()-t.SEC)},tickStart:function(t){return r.start(t)}}},t.schedule=function(e){function n(e,n,g,M,D){var p,y,Y,E=x(e),T=n,S=1e3,V=[],R=[],C=[],N="next"===e,k=N?0:1,O=N?1:0;if(g=g?new Date(g):new Date,!g||!g.getTime())throw new Error("Invalid start date.");for(a(e,s,V,g),u(e,w,R,g);S--&&T&&(p=m(V,E))&&(!M||!E(p,M));)if(h&&(v(e,w,R,p),y=d(e,R,p)))i(e,s,V,y);else{if(D){var b=f(R,E);if(y=c(e,s,V,p,b),r=N?[new Date(Math.max(g,p)),y?new Date(M?Math.min(y,M):y):void 0]:[y?new Date(M?Math.max(M,y.getTime()+t.SEC):y.getTime()+t.SEC):void 0,new Date(Math.min(g,p.getTime()+t.SEC))],Y&&r[k].getTime()===Y[O].getTime()?(Y[O]=r[O],T++):(Y=r,C.push(Y)),!y)break;i(e,s,V,y)}else C.push(N?new Date(Math.max(g,p)):o(s,V,p,M)),l(e,s,V,p);T--}return 0===C.length?t.NEVER:1===n?C[0]:C}function a(t,e,n,r){for(var a=0,i=e.length;i>a;a++)n[a]=e[a].start(t,r)}function i(t,e,n,r){for(var a=x(t),i=0,u=e.length;u>i;i++)n[i]&&!a(n[i],r)&&(n[i]=e[i].start(t,r))}function u(e,n,r,a){x(e);for(var i=0,u=n.length;u>i;i++){var v=n[i].start(e,a);r[i]=v?[v,n[i].end(e,v)]:t.NEVER}}function v(e,n,r,a){for(var i=x(e),u=0,v=n.length;v>u;u++)if(r[u]&&!i(r[u][0],a)){var l=n[u].start(e,a);r[u]=l?[l,n[u].end(e,l)]:t.NEVER}}function l(t,e,n,r){for(var a=0,i=e.length;i>a;a++)n[a]&&n[a].getTime()===r.getTime()&&(n[a]=e[a].start(t,e[a].tick(t,r)))}function o(t,e,n,r){for(var a,i=0,u=e.length;u>i;i++)if(e[i]&&e[i].getTime()===n.getTime()){var v=t[i].tickStart(n);if(r&&r>v)return r;(!a||v>a)&&(a=v)}return a}function d(t,e,n){for(var r,a=x(t),i=0,u=e.length;u>i;i++){var v=e[i];!v||a(v[0],n)||v[1]&&!a(v[1],n)||(!r||a(v[1],r))&&(r=v[1])}return r}function f(t,e){for(var n,r=0,a=t.length;a>r;r++)!t[r]||n&&!e(n,t[r][0])||(n=t[r][0]);return n}function c(t,e,n,r,a){for(var i,u=x(t),v=0,l=e.length;l>v;v++){var o=n[v];if(o&&o.getTime()===r.getTime()){var d=e[v].end(t,o);if(a&&(!d||u(d,a)))return a;(!i||u(d,i))&&(i=d)}}return i}function x(t){return"next"===t?function(t,e){return!e||t.getTime()>e.getTime()}:function(t,e){return!t||e.getTime()>t.getTime()}}function m(t,e){for(var n=t[0],r=1,a=t.length;a>r;r++)t[r]&&e(n,t[r])&&(n=t[r]);return n}if(!e)throw new Error("Missing schedule definition.");if(!e.schedules)throw new Error("Definition must include at least one schedule.");for(var s=[],g=e.schedules.length,w=[],h=e.exceptions?e.exceptions.length:0,M=0;g>M;M++)s.push(t.compile(e.schedules[M]));for(var D=0;h>D;D++)w.push(t.compile(e.exceptions[D]));return{isValid:function(e){return n("next",1,e,e)!==t.NEVER},next:function(t,e,r){return n("next",t||1,e,r)},prev:function(t,e,r){return n("prev",t||1,e,r)},nextRange:function(t,e,r){return n("next",t||1,e,r,!0)},prevRange:function(t,e,r){return n("prev",t||1,e,r,!0)}}},t.setTimeout=function(e,n){function r(){var t=Date.now(),n=i.next(2,t),u=n[0].getTime()-t;1e3>u&&(u=n[1].getTime()-t),a=2147483647>u?setTimeout(e,u):setTimeout(r,2147483647)}var a,i=t.schedule(n);return r(),{clear:function(){clearTimeout(a)}}},t.setInterval=function(e,n){function r(){i||(e(),a=t.setTimeout(r,n))}var a=t.setTimeout(r,n),i=!1;return{clear:function(){i=!0,a.clear()}}},t.date={},t.date.timezone=function(e){t.date.build=e?function(t,e,n,r,a,i){return new Date(t,e,n,r,a,i)}:function(t,e,n,r,a,i){return new Date(Date.UTC(t,e,n,r,a,i))};var n=e?"get":"getUTC",r=Date.prototype;t.date.getYear=r[n+"FullYear"],t.date.getMonth=r[n+"Month"],t.date.getDate=r[n+"Date"],t.date.getDay=r[n+"Day"],t.date.getHour=r[n+"Hours"],t.date.getMin=r[n+"Minutes"],t.date.getSec=r[n+"Seconds"],t.date.isUTC=!e},t.date.UTC=function(){t.date.timezone(!1)},t.date.localTime=function(){t.date.timezone(!0)},t.date.UTC(),t.SEC=1e3,t.MIN=60*t.SEC,t.HOUR=60*t.MIN,t.DAY=24*t.HOUR,t.WEEK=7*t.DAY,t.DAYS_IN_MONTH=[31,28,31,30,31,30,31,31,30,31,30,31],t.NEVER=0,t.date.next=function(e,n,r,a,i,u){return t.date.build(e,void 0!==n?n-1:0,void 0!==r?r:1,a||0,i||0,u||0)},t.date.nextRollover=function(e,n,r,a){var i=r.val(e),u=r.extent(e)[1];return i>=(n||u)||n>u?new Date(a.end(e).getTime()+t.SEC):a.start(e)},t.date.prev=function(e,n,r,a,i,u){var v=arguments.length;return n=2>v?11:n-1,r=3>v?t.D.extent(t.date.next(e,n+1))[1]:r,a=4>v?23:a,i=5>v?59:i,u=6>v?59:u,t.date.build(e,n,r,a,i,u)},t.date.prevRollover=function(t,e,n,r){var a=n.val(t);return e>=a||!e?r.start(r.prev(t,r.val(t)-1)):r.start(t)},t}();