diff --git a/.gitignore b/.gitignore index b903276..f070284 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ test/coverage.html *.bak npm-debug.log .DS_Store +.#* #Jetbrains IDE files .idea diff --git a/.travis.yml b/.travis.yml index 8f96a07..d3c6666 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ language: node_js node_js: - 0.12 - 4.2.4 - - 5.3.0 + - 5.9.0 before_install: - make configure diff --git a/dist/twix.js b/dist/twix.js index 473aa1c..c7b392c 100644 --- a/dist/twix.js +++ b/dist/twix.js @@ -339,7 +339,7 @@ }; Twix.prototype.format = function(inopts) { - var common_bucket, end_bucket, fold, format, fs, global_first, goesIntoTheMorning, j, len, momentHourFormat, needDate, needsMeridiem, options, process, start_bucket, together; + var atomicMonthDate, common_bucket, end_bucket, fold, format, fs, global_first, goesIntoTheMorning, j, len, momentHourFormat, needDate, needsMeridiem, options, process, start_bucket, together; if (this.isEmpty()) { return ''; } @@ -370,6 +370,7 @@ needsMeridiem = options.hourFormat && options.hourFormat[0] === 'h'; goesIntoTheMorning = options.lastNightEndsAt > 0 && !this.allDay && this.end().startOf('d').valueOf() === this.start().add(1, 'd').startOf('d').valueOf() && this._start.hours() > 12 && this._end.hours() < options.lastNightEndsAt; needDate = !options.hideDate && (!options.implicitDate || this.start().startOf('d').valueOf() !== moment().startOf('d').valueOf() || !(this.isSame('d') || goesIntoTheMorning)); + atomicMonthDate = !(this.allDay || options.hideTime); if (this.allDay && this.isSame('d') && (options.implicitDate || options.explicitAllDay)) { fs.push({ name: 'all day simple', @@ -390,9 +391,9 @@ slot: 4 }); } - if (!this.allDay && needDate) { + if (atomicMonthDate && needDate) { fs.push({ - name: 'all day month', + name: 'month-date', fn: function(date) { return date.format(options.monthFormat + " " + options.dayFormat); }, @@ -403,7 +404,7 @@ slot: 2 }); } - if (this.allDay && needDate) { + if (!atomicMonthDate && needDate) { fs.push({ name: 'month', fn: function(date) { @@ -413,7 +414,7 @@ slot: 2 }); } - if (this.allDay && needDate) { + if (!atomicMonthDate && needDate) { fs.push({ name: 'date', fn: function(date) { @@ -476,6 +477,9 @@ return start_str; } }; + if (_this._start.month() === 9 && _this._start.date() === 6) { + console.log("Format: " + (JSON.stringify(format))); + } if (end_str === start_str && together) { return common_bucket.push(start_group); } else { diff --git a/dist/twix.min.js b/dist/twix.min.js index 6b3a5fc..da84e36 100644 --- a/dist/twix.min.js +++ b/dist/twix.min.js @@ -1 +1 @@ -(function(){var hasModule,isArray,makeTwix,slice=[].slice;hasModule=typeof module!=="undefined"&&module!==null&&module.exports!=null;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=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&&startmoment()};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._startother._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=start){results1.push(mom)}}return results1}().sort()}if(dur&&dur.asMilliseconds()===0||times&×.length===0){return[this]}vals=[];i=0;final=this._displayEnd;while(start0&&!this.allDay&&this.end().startOf("d").valueOf()===this.start().add(1,"d").startOf("d").valueOf()&&this._start.hours()>12&&this._end.hours()start.clone().startOf(period)){start.startOf(period).add(intervalAmount,period)}if(end=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&&startmoment()};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._startother._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=start){results1.push(mom)}}return results1}().sort()}if(dur&&dur.asMilliseconds()===0||times&×.length===0){return[this]}vals=[];i=0;final=this._displayEnd;while(start0&&!this.allDay&&this.end().startOf("d").valueOf()===this.start().add(1,"d").startOf("d").valueOf()&&this._start.hours()>12&&this._end.hours()start.clone().startOf(period)){start.startOf(period).add(intervalAmount,period)}if(end needDate = !options.hideDate && (!options.implicitDate || @start().startOf('d').valueOf() != moment().startOf('d').valueOf() || !(@isSame('d') || goesIntoTheMorning)) + atomicMonthDate = !(@allDay || options.hideTime) + if @allDay && @isSame('d') && (options.implicitDate || options.explicitAllDay) fs.push name: 'all day simple' @@ -262,22 +264,22 @@ makeTwix = (moment) -> pre: ', ' slot: 4 - if !@allDay && needDate + if atomicMonthDate && needDate fs.push - name: 'all day month' + name: 'month-date' fn: (date) -> date.format "#{options.monthFormat} #{options.dayFormat}" ignoreEnd: -> goesIntoTheMorning pre: ' ' slot: 2 - if @allDay && needDate + if !atomicMonthDate && needDate fs.push name: 'month' fn: (date) -> date.format options.monthFormat pre: ' ' slot: 2 - if @allDay && needDate + if !atomicMonthDate && needDate fs.push name: 'date' fn: (date) -> date.format options.dayFormat @@ -331,6 +333,9 @@ makeTwix = (moment) -> start_group = {format: format, value: -> start_str} + if @_start.month() == 9 && @_start.date() == 6 + console.log "Format: #{JSON.stringify(format)}" + if end_str == start_str && together common_bucket.push start_group else diff --git a/test/twix.spec.coffee b/test/twix.spec.coffee index d327bf8..e18a518 100644 --- a/test/twix.spec.coffee +++ b/test/twix.spec.coffee @@ -1357,7 +1357,7 @@ test = (moment, Twix) -> start: thisYear '05-25', '05:30' end: thisYear '05-27', '06:30' options: {hideTime: true} - result: 'May 25 - May 27' + result: 'May 25 - 27' test 'hide times even for a single day', start: thisYear '05-25', '05:30'