LocalCDN-Firefox-Chrome-Brave/resources/twix.js/1.3.0/twix.min.jsm

1 line
15 KiB
JavaScript
Raw Normal View History

2022-06-28 08:25:56 +02:00
(function(){var hasModule,isArray,makeTwix,slice=[].slice;hasModule=typeof module!=="undefined"&&module!==null&&module.exports!=null&&typeof require==="function";isArray=function(input){return Object.prototype.toString.call(input)==="[object Array]"};makeTwix=function(moment){var Twix;if(moment==null){throw new Error("Can't find moment")}Twix=function(){function Twix(start,end,parseFormat,options){var ref;if(options==null){options={}}if(typeof parseFormat!=="string"){options=parseFormat!=null?parseFormat:{};parseFormat=null}if(typeof options==="boolean"){options={allDay:options}}this._oStart=moment(start,parseFormat,options.parseStrict);this._oEnd=moment(end,parseFormat,options.parseStrict);this.allDay=(ref=options.allDay)!=null?ref:false;this._mutated()}Twix._extend=function(){var attr,first,j,len,other,others;first=arguments[0],others=2<=arguments.length?slice.call(arguments,1):[];for(j=0,len=others.length;j<len;j++){other=others[j];for(attr in other){if(typeof other[attr]!=="undefined"){first[attr]=other[attr]}}}return first};Twix.prototype.start=function(){return this._start.clone()};Twix.prototype.end=function(){return this._end.clone()};Twix.prototype.isSame=function(period){return this._start.isSame(this._end,period)};Twix.prototype.length=function(period,floatingPoint){if(floatingPoint==null){floatingPoint=false}return this._displayEnd.diff(this._start,period,floatingPoint)};Twix.prototype.count=function(period){var end,start;start=this.start().startOf(period);end=this.end().startOf(period);return end.diff(start,period)+1};Twix.prototype.countInner=function(period){var end,ref,start;ref=this._inner(period),start=ref[0],end=ref[1];if(start>=end){return 0}return end.diff(start,period)};Twix.prototype.iterate=function(intervalAmount,period,minHours){var end,hasNext,ref,start;ref=this._prepIterateInputs(intervalAmount,period,minHours),intervalAmount=ref[0],period=ref[1],minHours=ref[2];start=this.start().startOf(period);end=this.end().startOf(period);if(this.allDay){end=end.add(1,"d")}hasNext=function(_this){return function(){return!_this.allDay&&start<=end&&(!minHours||!start.isSame(end)||_this._end.hours()>minHours)||_this.allDay&&start<end}}(this);return this._iterateHelper(period,start,hasNext,intervalAmount)};Twix.prototype.iterateInner=function(intervalAmount,period){var end,hasNext,ref,ref1,start;ref=this._prepIterateInputs(intervalAmount,period),intervalAmount=ref[0],period=ref[1];ref1=this._inner(period,intervalAmount),start=ref1[0],end=ref1[1];hasNext=function(){return start<end};return this._iterateHelper(period,start,hasNext,intervalAmount)};Twix.prototype.humanizeLength=function(){if(this.allDay){if(this.isSame("d")){return"all day"}else{return this._start.from(this.end().add(1,"d"),true)}}else{return this._start.from(this._end,true)}};Twix.prototype.asDuration=function(units){var diff;diff=this._end.diff(this._start);return moment.duration(diff)};Twix.prototype.isPast=function(){return this._lastMilli<moment()};Twix.prototype.isFuture=function(){return this._start>moment()};Twix.prototype.isCurrent=function(){return!this.isPast()&&!this.isFuture()};Twix.prototype.contains=function(mom){if(!moment.isMoment(mom)){mom=moment(mom)}return this._start<=mom&&this._lastMilli>=mom};Twix.prototype.isEmpty=function(){return this._start.isSame(this._displayEnd)};Twix.prototype.overlaps=function(other){return this._displayEnd.isAfter(other._start)&&this._start.isBefore(other._displayEnd)};Twix.prototype.engulfs=function(other){return this._start<=other._start&&this._displayEnd>=other._displayEnd};Twix.prototype.union=function(other){var allDay,newEnd,newStart;allDay=this.allDay&&other.allDay;newStart=this._start<other._start?this._start:other._start;newEnd=this._lastMilli>other._lastMilli?allDay?this._end:this._displayEnd:allDay?other._end:other._displayEnd;return new Twix(newStart,newEnd,allDay)};Twix.prototype.intersection=function(other){var allDay,newEnd,newStart;allDay=this.allDay&&other.allDay;newStart=this._start>other._start?this._start:other._start;newEnd=this._lastMilli<other._lastMilli?allDay?this._end:t