Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merge() and locking to moment 1.4

  • Loading branch information...
commit 24734543ba8564049093b8810a4a6962eebe4e96 1 parent 0e75493
@icambron authored
View
0  bin/moment.min.js 100644 → 100755
File mode changed
View
21 bin/twix.js
@@ -17,7 +17,7 @@
endM = moment(end);
this.start = startM.zone() === moment().zone ? startM : moment(startM.valueOf());
this.end = endM.zone() === moment().zone ? endM : moment(endM.valueOf());
- this.allDay = allDay;
+ this.allDay = allDay || false;
}
Twix.prototype.sameDay = function() {
@@ -32,6 +32,8 @@
var endDate, startDate;
startDate = this.start.sod();
endDate = this.end.sod();
+ console.log("start: " + (startDate.toString()));
+ console.log("end: " + (endDate.toString()));
return endDate.diff(startDate, 'days') + 1;
};
@@ -85,6 +87,19 @@
return this.trueStart() <= other.trueStart() && this.trueEnd() >= other.trueEnd();
};
+ Twix.prototype.merge = function(other) {
+ var allDay, newEnd, newStart;
+ allDay = this.allDay && other.allDay;
+ if (allDay) {
+ newStart = this.start < other.start ? this.start : other.start;
+ newEnd = this.end > other.end ? this.end : other.end;
+ } else {
+ newStart = this.trueStart() < other.trueStart() ? this.trueStart() : other.trueStart();
+ newEnd = this.trueEnd() > other.trueEnd() ? this.trueEnd() : other.trueEnd();
+ }
+ return new Twix(newStart, newEnd, allDay);
+ };
+
Twix.prototype.trueStart = function() {
if (this.allDay) {
return this.start.sod();
@@ -101,6 +116,10 @@
}
};
+ Twix.prototype.equals = function(other) {
+ return (other instanceof Twix) && this.allDay === other.allDay && this.start.valueOf() === other.start.valueOf() && this.end.valueOf() === other.end.valueOf();
+ };
+
Twix.prototype.format = function(inopts) {
var common_bucket, end_bucket, fold, format, fs, global_first, goesIntoTheMorning, needDate, options, process, start_bucket, together, _i, _len,
_this = this;
View
2  bin/twix.min.js
@@ -1 +1 @@
-((function(){var a,b,c;typeof module!="undefined"?c=require("moment"):c=window.moment;if(typeof c=="undefined")throw"Can't find moment";a=function(){function a(a,b,d){var e,f;f=c(a),e=c(b),this.start=f.zone()===c().zone?f:c(f.valueOf()),this.end=e.zone()===c().zone?e:c(e.valueOf()),this.allDay=d}return a.prototype.sameDay=function(){return this.start.year()===this.end.year()&&this.start.month()===this.end.month()&&this.start.date()===this.end.date()},a.prototype.sameYear=function(){return this.start.year()===this.end.year()},a.prototype.countDays=function(){var a,b;return b=this.start.sod(),a=this.end.sod(),a.diff(b,"days")+1},a.prototype.daysIn=function(a){var b,c,d=this;return c=this.start.sod(),b=this.end.sod(),{next:function(){var e;return c>b||a&&c.valueOf()===b.valueOf()&&d.end.hours()<a?null:(e=c.clone(),c.add("days",1),e)},hasNext:function(){return c<=b&&(!a||c.valueOf()!==b.valueOf()||d.end.hours()>a)}}},a.prototype.duration=function(){return this.allDay?this.sameDay()?"all day":this.start.from(this.end.clone().add("days",1),!0):this.start.from(this.end,!0)},a.prototype.past=function(){return this.allDay?this.end.eod()<c():this.end<c()},a.prototype.overlaps=function(a){return!(this.trueEnd()<a.trueStart()||this.trueStart()>a.trueEnd())},a.prototype.engulfs=function(a){return this.trueStart()<=a.trueStart()&&this.trueEnd()>=a.trueEnd()},a.prototype.trueStart=function(){return this.allDay?this.start.sod():this.start},a.prototype.trueEnd=function(){return this.allDay?this.end.eod():this.end},a.prototype.format=function(a){var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=this;l={groupMeridiems:!0,spaceBeforeMeridiem:!0,showDate:!0,showDayOfWeek:!1,twentyFourHour:!1,implicitMinutes:!0,yearFormat:"YYYY",monthFormat:"MMM",weekdayFormat:"ddd",dayFormat:"D",meridiemFormat:"A",hourFormat:"h",minuteFormat:"mm",allDay:"all day",explicitAllDay:!1,lastNightEndsAt:0},b(l,a||{}),h=[],l.twentyFourHour&&(l.hourFormat=l.hourFormat.replace("h","H")),j=l.lastNightEndsAt>0&&!this.allDay&&this.end.sod().valueOf()===this.start.clone().add("days",1).sod().valueOf()&&this.start.hours()>12&&this.end.hours()<l.lastNightEndsAt,k=l.showDate||!this.sameDay()&&!j,this.allDay&&this.sameDay()&&(!l.showDate||l.explicitAllDay)&&h.push({name:"all day simple",fn:function(){return l.allDay},slot:0,pre:" "}),k&&(this.start.year()!==c().year()||!this.sameYear())&&h.push({name:"year",fn:function(a){return a.format(l.yearFormat)},pre:", ",slot:4}),!this.allDay&&k&&h.push({name:"all day month",fn:function(a){return a.format(""+l.monthFormat+" "+l.dayFormat)},ignoreEnd:function(){return j},slot:2,pre:" "}),this.allDay&&k&&h.push({name:"month",fn:function(a){return a.format("MMM")},slot:2,pre:" "}),this.allDay&&k&&h.push({name:"date",fn:function(a){return a.format(l.dayFormat)},slot:3,pre:" "}),k&&l.showDayOfWeek&&h.push({name:"day of week",fn:function(a){return a.format(l.weekdayFormat)},pre:" ",slot:1}),l.groupMeridiems&&!l.twentyFourHour&&!this.allDay&&h.push({name:"meridiem",fn:function(a){return a.format(l.meridiemFormat)},slot:6,pre:l.spaceBeforeMeridiem?" ":""}),this.allDay||h.push({name:"time",fn:function(a){var b;return b=a.minutes()===0&&l.implicitMinutes&&!l.twentyFourHour?a.format(l.hourFormat):a.format(""+l.hourFormat+":"+l.minuteFormat),!l.groupMeridiems&&!l.twentyFourHour&&(l.spaceBeforeMeridiem&&(b+=" "),b+=a.format(l.meridiemFormat)),b},pre:", ",slot:5}),n=[],e=[],d=[],o=!0,m=function(a){var b,c,g;return g=a.fn(r.start),b=a.ignoreEnd&&a.ignoreEnd()?g:a.fn(r.end),c={format:a,value:function(){return g}},b===g&&o?d.push(c):(o&&(o=!1,d.push({format:{slot:a.slot,pre:""},value:function(){return""+f(n)+" -"+f(e,!0)}})),n.push(c),e.push({format:a,value:function(){return b}}))};for(p=0,q=h.length;p<q;p++)g=h[p],m(g);return i=!0,f=function(a,b){var c,d,e,f,g,h;c=!0,e="",h=a.sort(function(a,b){return a.format.slot-b.format.slot});for(f=0,g=h.length;f<g;f++)d=h[f],i||(c&&b?e+=" ":e+=d.format.pre),e+=d.value(),i=!1,c=!1;return e},f(d)},a}(),b=function(a,b){var c,d;d=[];for(c in b)typeof b[c]!="undefined"?d.push(a[c]=b[c]):d.push(void 0);return d},typeof module!="undefined"?module.exports=a:window.Twix=a})).call(this);
+((function(){var a,b,c;typeof module!="undefined"?c=require("moment"):c=window.moment;if(typeof c=="undefined")throw"Can't find moment";a=function(){function a(a,b,d){var e,f;f=c(a),e=c(b),this.start=f.zone()===c().zone?f:c(f.valueOf()),this.end=e.zone()===c().zone?e:c(e.valueOf()),this.allDay=d||!1}return a.prototype.sameDay=function(){return this.start.year()===this.end.year()&&this.start.month()===this.end.month()&&this.start.date()===this.end.date()},a.prototype.sameYear=function(){return this.start.year()===this.end.year()},a.prototype.countDays=function(){var a,b;return b=this.start.sod(),a=this.end.sod(),console.log("start: "+b.toString()),console.log("end: "+a.toString()),a.diff(b,"days")+1},a.prototype.daysIn=function(a){var b,c,d=this;return c=this.start.sod(),b=this.end.sod(),{next:function(){var e;return c>b||a&&c.valueOf()===b.valueOf()&&d.end.hours()<a?null:(e=c.clone(),c.add("days",1),e)},hasNext:function(){return c<=b&&(!a||c.valueOf()!==b.valueOf()||d.end.hours()>a)}}},a.prototype.duration=function(){return this.allDay?this.sameDay()?"all day":this.start.from(this.end.clone().add("days",1),!0):this.start.from(this.end,!0)},a.prototype.past=function(){return this.allDay?this.end.eod()<c():this.end<c()},a.prototype.overlaps=function(a){return!(this.trueEnd()<a.trueStart()||this.trueStart()>a.trueEnd())},a.prototype.engulfs=function(a){return this.trueStart()<=a.trueStart()&&this.trueEnd()>=a.trueEnd()},a.prototype.merge=function(b){var c,d,e;return c=this.allDay&&b.allDay,c?(e=this.start<b.start?this.start:b.start,d=this.end>b.end?this.end:b.end):(e=this.trueStart()<b.trueStart()?this.trueStart():b.trueStart(),d=this.trueEnd()>b.trueEnd()?this.trueEnd():b.trueEnd()),new a(e,d,c)},a.prototype.trueStart=function(){return this.allDay?this.start.sod():this.start},a.prototype.trueEnd=function(){return this.allDay?this.end.eod():this.end},a.prototype.equals=function(b){return b instanceof a&&this.allDay===b.allDay&&this.start.valueOf()===b.start.valueOf()&&this.end.valueOf()===b.end.valueOf()},a.prototype.format=function(a){var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=this;l={groupMeridiems:!0,spaceBeforeMeridiem:!0,showDate:!0,showDayOfWeek:!1,twentyFourHour:!1,implicitMinutes:!0,yearFormat:"YYYY",monthFormat:"MMM",weekdayFormat:"ddd",dayFormat:"D",meridiemFormat:"A",hourFormat:"h",minuteFormat:"mm",allDay:"all day",explicitAllDay:!1,lastNightEndsAt:0},b(l,a||{}),h=[],l.twentyFourHour&&(l.hourFormat=l.hourFormat.replace("h","H")),j=l.lastNightEndsAt>0&&!this.allDay&&this.end.sod().valueOf()===this.start.clone().add("days",1).sod().valueOf()&&this.start.hours()>12&&this.end.hours()<l.lastNightEndsAt,k=l.showDate||!this.sameDay()&&!j,this.allDay&&this.sameDay()&&(!l.showDate||l.explicitAllDay)&&h.push({name:"all day simple",fn:function(){return l.allDay},slot:0,pre:" "}),k&&(this.start.year()!==c().year()||!this.sameYear())&&h.push({name:"year",fn:function(a){return a.format(l.yearFormat)},pre:", ",slot:4}),!this.allDay&&k&&h.push({name:"all day month",fn:function(a){return a.format(""+l.monthFormat+" "+l.dayFormat)},ignoreEnd:function(){return j},slot:2,pre:" "}),this.allDay&&k&&h.push({name:"month",fn:function(a){return a.format("MMM")},slot:2,pre:" "}),this.allDay&&k&&h.push({name:"date",fn:function(a){return a.format(l.dayFormat)},slot:3,pre:" "}),k&&l.showDayOfWeek&&h.push({name:"day of week",fn:function(a){return a.format(l.weekdayFormat)},pre:" ",slot:1}),l.groupMeridiems&&!l.twentyFourHour&&!this.allDay&&h.push({name:"meridiem",fn:function(a){return a.format(l.meridiemFormat)},slot:6,pre:l.spaceBeforeMeridiem?" ":""}),this.allDay||h.push({name:"time",fn:function(a){var b;return b=a.minutes()===0&&l.implicitMinutes&&!l.twentyFourHour?a.format(l.hourFormat):a.format(""+l.hourFormat+":"+l.minuteFormat),!l.groupMeridiems&&!l.twentyFourHour&&(l.spaceBeforeMeridiem&&(b+=" "),b+=a.format(l.meridiemFormat)),b},pre:", ",slot:5}),n=[],e=[],d=[],o=!0,m=function(a){var b,c,g;return g=a.fn(r.start),b=a.ignoreEnd&&a.ignoreEnd()?g:a.fn(r.end),c={format:a,value:function(){return g}},b===g&&o?d.push(c):(o&&(o=!1,d.push({format:{slot:a.slot,pre:""},value:function(){return""+f(n)+" -"+f(e,!0)}})),n.push(c),e.push({format:a,value:function(){return b}}))};for(p=0,q=h.length;p<q;p++)g=h[p],m(g);return i=!0,f=function(a,b){var c,d,e,f,g,h;c=!0,e="",h=a.sort(function(a,b){return a.format.slot-b.format.slot});for(f=0,g=h.length;f<g;f++)d=h[f],i||(c&&b?e+=" ":e+=d.format.pre),e+=d.value(),i=!1,c=!1;return e},f(d)},a}(),b=function(a,b){var c,d;d=[];for(c in b)typeof b[c]!="undefined"?d.push(a[c]=b[c]):d.push(void 0);return d},typeof module!="undefined"?module.exports=a:window.Twix=a})).call(this);
View
0  lib/moment.min.js 100644 → 100755
File mode changed
View
2  package.json
@@ -6,7 +6,7 @@
"author": "Isaac Cambron",
"keywords": ["twix", "date", "date range"],
"dependencies": {
- "moment": ">=1.4"
+ "moment": "1.4"
},
"devDependencies": {
"mocha" : "0.8.x",
View
29 src/twix.coffee
@@ -8,14 +8,15 @@ if typeof moment == "undefined"
class Twix
constructor: (start, end, allDay) ->
-
startM = moment start
endM = moment end
-
@start = if startM.zone() == moment().zone then startM else moment(startM.valueOf())
@end = if endM.zone() == moment().zone then endM else moment(endM.valueOf())
- @allDay = allDay
+ #@start = moment start
+ #@end = moment end
+
+ @allDay = allDay || false
sameDay: ->
@start.year() == @end.year() &&
@@ -28,6 +29,8 @@ class Twix
countDays: ->
startDate = @start.sod()
endDate = @end.sod()
+ console.log "start: #{startDate.toString()}"
+ console.log "end: #{endDate.toString()}"
endDate.diff(startDate, 'days') + 1
daysIn: (minHours) ->
@@ -62,10 +65,26 @@ class Twix
engulfs: (other) -> @trueStart() <= other.trueStart() && @trueEnd() >= other.trueEnd()
- trueStart: -> if @allDay then @start.sod() else @start
+ merge: (other) ->
+ allDay = @allDay && other.allDay
+ if allDay
+ newStart = if @start < other.start then @start else other.start
+ newEnd = if @end > other.end then @end else other.end
+ else
+ newStart = if @trueStart() < other.trueStart() then @trueStart() else other.trueStart()
+ newEnd = if @trueEnd() > other.trueEnd() then @trueEnd() else other.trueEnd()
+ new Twix(newStart, newEnd, allDay)
+
+ trueStart: -> if @allDay then @start.sod() else @start
trueEnd: -> if @allDay then @end.eod() else @end
-
+
+ equals: (other) ->
+ (other instanceof Twix) &&
+ @allDay == other.allDay &&
+ @start.valueOf() == other.start.valueOf() &&
+ @end.valueOf() == other.end.valueOf()
+
format: (inopts) ->
options =
groupMeridiems: true
View
83 test/bin/twix.spec.js
@@ -1,9 +1,10 @@
(function() {
- var Twix, assertEqual, moment, thatDay, thisYear, tomorrow, yesterday;
+ var Twix, assertDeepEqual, assertEqual, moment, thatDay, thisYear, tomorrow, yesterday;
if (typeof module !== "undefined") {
moment = require("moment");
assertEqual = require('assert').equal;
+ assertDeepEqual = require('assert').deepEqual;
Twix = require("../../bin/twix");
} else {
moment = window.moment;
@@ -11,6 +12,9 @@
assertEqual = function(a, b) {
if (a !== b) throw new Error("Found " + b + ", expected " + a);
};
+ assertDeepEqual = function(a, b) {
+ if (!a.equals(b)) throw new Error("Found " + b + ", expected " + a);
+ };
}
thisYear = function(partial, time) {
@@ -89,12 +93,14 @@
return assertEqual(first.date(), second.date());
};
it("provides 1 day if the range includes 1 day", function() {
- var end, iter, range, start;
+ var end, iter, next, range, start;
start = thisYear("5/25", "3:00");
end = thisYear("5/25", "14:00");
range = new Twix(start, end);
iter = range.daysIn();
- assertSameDay(thisYear("5/25"), iter.next());
+ next = iter.next();
+ console.log(next);
+ assertSameDay(thisYear("5/25"), next);
return assertEqual(null, iter.next());
});
it("provides 2 days if the range crosses midnight", function() {
@@ -122,7 +128,7 @@
})();
return assertEqual(366, results.length);
});
- return describe("with a minimum time", function() {
+ return it("doesn't generate extra days when there's a min time", function() {
var end, iter, range, start;
start = thisYear("5/25", "16:00");
end = thisYear("5/26", "3:00");
@@ -198,10 +204,10 @@
return assertNoOverlap(someTime, thatDay("3:30", "4:30"));
});
it("returns true for a partially later event", function() {
- return assertOverlap(someTime, thatDay("4:30", "6:30"));
+ return assertOverlap(someTime, thatDay("8:00", "11:30"));
});
it("returns true for a partially earlier event", function() {
- return assertOverlap(someTime, thatDay("8:00", "11:30"));
+ return assertOverlap(someTime, thatDay("4:30", "6:30"));
});
it("returns true for an engulfed event", function() {
return assertOverlap(someTime, thatDay("6:30", "7:30"));
@@ -264,10 +270,10 @@
return assertNotEngulfing(someTime, thatDay("3:30", "4:30"));
});
it("returns true for a partially later event", function() {
- return assertNotEngulfing(someTime, thatDay("4:30", "6:30"));
+ return assertNotEngulfing(someTime, thatDay("8:00", "11:30"));
});
it("returns true for a partially earlier event", function() {
- return assertNotEngulfing(someTime, thatDay("8:00", "11:30"));
+ return assertNotEngulfing(someTime, thatDay("4:30", "6:30"));
});
it("returns true for an engulfed event", function() {
return assertEngulfing(someTime, thatDay("6:30", "7:30"));
@@ -312,6 +318,67 @@
});
});
+ describe("merge()", function() {
+ var someDays, someTime;
+ someTime = thatDay("5:30", "8:30");
+ someDays = new Twix("5/24/1982", "5/25/1982", true);
+ describe("non-all-day events", function() {
+ it("spans a later time", function() {
+ return assertDeepEqual(thatDay("5:30", "11:30"), someTime.merge(thatDay("9:30", "11:30")));
+ });
+ it("spans an earlier time", function() {
+ return assertDeepEqual(thatDay("3:30", "8:30"), someTime.merge(thatDay("3:30", "4:30")));
+ });
+ it("spans a partially later event", function() {
+ return assertDeepEqual(thatDay("5:30", "11:30"), someTime.merge(thatDay("8:00", "11:30")));
+ });
+ it("spans a partially earlier event", function() {
+ return assertDeepEqual(thatDay("4:30", "8:30"), someTime.merge(thatDay("4:30", "6:30")));
+ });
+ it("isn't affected by engulfed events", function() {
+ return assertDeepEqual(someTime, someTime.merge(thatDay("6:30", "7:30")));
+ });
+ return it("becomes an engulfing event", function() {
+ return assertDeepEqual(thatDay("4:30", "9:30"), someTime.merge(thatDay("4:30", "9:30")));
+ });
+ });
+ describe("one all-day event", function() {
+ it("spans a later time", function() {
+ console.log(someDays.trueEnd());
+ return assertDeepEqual(new Twix("5/24/1982 00:00", "5/26/1982 7:00"), someDays.merge(new Twix("5/24/1982 20:00", "5/26/1982 7:00")));
+ });
+ it("spans an earlier time", function() {
+ return assertDeepEqual(new Twix("5/23/1982 8:00", moment("5/25/1982").eod()), someDays.merge(new Twix("5/23/1982 8:00", "5/25/1982 7:00")));
+ });
+ it("isn't affected by engulfing events", function() {
+ return assertDeepEqual(new Twix("5/24/1982 00:00", moment("5/25/1982").eod()), someDays.merge(someTime));
+ });
+ return it("becomes an engulfing event", function() {
+ return assertDeepEqual(new Twix("5/23/1982 20:00", "5/26/1982 8:30"), someDays.merge(new Twix("5/23/1982 20:00", "5/26/1982 8:30")));
+ });
+ });
+ return describe("two all-day events", function() {
+ it("spans a later time", function() {
+ return assertDeepEqual(new Twix("5/24/1982", "5/28/1982", true), someDays.merge(new Twix("5/27/1982", "5/28/1982", true)));
+ });
+ it("spans an earlier time", function() {
+ return assertDeepEqual(new Twix("5/21/1982", "5/25/1982", true), someDays.merge(new Twix("5/21/1982", "5/22/1982", true)));
+ });
+ it("spans a partially later time", function() {
+ return assertDeepEqual(new Twix("5/24/1982", "5/26/1982", true), someDays.merge(new Twix("5/25/1982", "5/26/1982", true)));
+ });
+ it("spans a partially earlier time", function() {
+ return assertDeepEqual(new Twix("5/23/1982", "5/25/1982", true), someDays.merge(new Twix("5/23/1982", "5/25/1982", true)));
+ });
+ it("isn't affected by engulfing events", function() {
+ return assertDeepEqual(someDays, someDays.merge(thatDay()));
+ });
+ return it("becomes an engulfing event", function() {
+ return assertDeepEqual(someDays, thatDay().merge(someDays));
+ });
+ });
+ });
+
describe("format()", function() {
var test;
test = function(name, t) {
View
6 test/test.html
@@ -4,10 +4,10 @@
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://raw.github.com/visionmedia/mocha/master/mocha.css" />
<script src="https://raw.github.com/visionmedia/mocha/master/mocha.js"></script>
- <script src="https://raw.github.com/timrwood/moment/master/moment.js"></script>
+ <script src="../lib/moment.js"></script>
<script>mocha.setup('bdd')</script>
- <script src="../lib/twix.js"></script>
- <script src="lib/twix.spec.js"></script>
+ <script src="../bin/twix.js"></script>
+ <script src="bin/twix.spec.js"></script>
<script>
$(function(){
mocha.run();
View
78 test/twix.spec.coffee
@@ -1,11 +1,13 @@
if typeof module != "undefined"
moment = require("moment")
assertEqual = require('assert').equal
+ assertDeepEqual = require('assert').deepEqual
Twix = require("../../bin/twix")
-else
+else
moment = window.moment
Twix = window.Twix
assertEqual = (a, b) -> throw new Error("Found #{b}, expected #{a}") unless a == b
+ assertDeepEqual = (a, b) -> throw new Error("Found #{b}, expected #{a}") unless a.equals(b)
thisYear = (partial, time) ->
fullDate = "#{partial}/#{moment().year()}"
@@ -73,7 +75,9 @@ describe "daysIn()", ->
range = new Twix start, end
iter = range.daysIn()
- assertSameDay thisYear("5/25"), iter.next()
+ next = iter.next()
+ console.log next
+ assertSameDay thisYear("5/25"), next
assertEqual null, iter.next()
it "provides 2 days if the range crosses midnight", ->
@@ -94,7 +98,7 @@ describe "daysIn()", ->
iter.next()
assertEqual(366, results.length)
- describe "with a minimum time", ->
+ it "doesn't generate extra days when there's a min time", ->
start = thisYear "5/25", "16:00"
end = thisYear "5/26", "3:00"
range = new Twix start, end
@@ -158,10 +162,10 @@ describe "overlaps", ->
assertNoOverlap someTime, thatDay "3:30", "4:30"
it "returns true for a partially later event", ->
- assertOverlap someTime, thatDay "4:30", "6:30"
+ assertOverlap someTime, thatDay "8:00", "11:30"
it "returns true for a partially earlier event", ->
- assertOverlap someTime, thatDay "8:00", "11:30"
+ assertOverlap someTime, thatDay "4:30", "6:30"
it "returns true for an engulfed event", ->
assertOverlap someTime, thatDay "6:30", "7:30"
@@ -218,10 +222,10 @@ describe "engulfs", ->
assertNotEngulfing someTime, thatDay "3:30", "4:30"
it "returns true for a partially later event", ->
- assertNotEngulfing someTime, thatDay "4:30", "6:30"
+ assertNotEngulfing someTime, thatDay "8:00", "11:30"
it "returns true for a partially earlier event", ->
- assertNotEngulfing someTime, thatDay "8:00", "11:30"
+ assertNotEngulfing someTime, thatDay "4:30", "6:30"
it "returns true for an engulfed event", ->
assertEngulfing someTime, thatDay "6:30", "7:30"
@@ -261,6 +265,66 @@ describe "engulfs", ->
it "returns true for an engulfing event", ->
assertNotEngulfing someDays, new Twix("5/22/1982", "5/28/1982", true)
+describe "merge()", ->
+
+ someTime = thatDay "5:30", "8:30"
+ someDays = new Twix("5/24/1982", "5/25/1982", true)
+
+ describe "non-all-day events", ->
+
+ it "spans a later time", ->
+ assertDeepEqual thatDay("5:30", "11:30"), someTime.merge(thatDay "9:30", "11:30")
+
+ it "spans an earlier time", ->
+ assertDeepEqual thatDay("3:30", "8:30"), someTime.merge(thatDay "3:30", "4:30")
+
+ it "spans a partially later event", ->
+ assertDeepEqual thatDay("5:30", "11:30"), someTime.merge(thatDay "8:00", "11:30")
+
+ it "spans a partially earlier event", ->
+ assertDeepEqual thatDay("4:30", "8:30"), someTime.merge(thatDay "4:30", "6:30")
+
+ it "isn't affected by engulfed events", ->
+ assertDeepEqual someTime, someTime.merge(thatDay "6:30", "7:30")
+
+ it "becomes an engulfing event", ->
+ assertDeepEqual thatDay("4:30", "9:30"), someTime.merge(thatDay "4:30", "9:30")
+
+ describe "one all-day event", ->
+ it "spans a later time", ->
+ console.log(someDays.trueEnd())
+ assertDeepEqual new Twix("5/24/1982 00:00", "5/26/1982 7:00"), someDays.merge(new Twix("5/24/1982 20:00", "5/26/1982 7:00"))
+
+ it "spans an earlier time", ->
+ assertDeepEqual new Twix("5/23/1982 8:00", moment("5/25/1982").eod()), someDays.merge(new Twix("5/23/1982 8:00", "5/25/1982 7:00"))
+
+ #i'm tempted to just say this is wrong...shouldn't it get to stay an all-day event?
+ it "isn't affected by engulfing events", ->
+ assertDeepEqual new Twix("5/24/1982 00:00", moment("5/25/1982").eod()), someDays.merge(someTime)
+
+ it "becomes an engulfing event", ->
+ assertDeepEqual new Twix("5/23/1982 20:00", "5/26/1982 8:30"), someDays.merge(new Twix("5/23/1982 20:00", "5/26/1982 8:30"))
+
+ describe "two all-day events", ->
+
+ it "spans a later time", ->
+ assertDeepEqual new Twix("5/24/1982", "5/28/1982", true), someDays.merge(new Twix("5/27/1982", "5/28/1982", true))
+
+ it "spans an earlier time", ->
+ assertDeepEqual new Twix("5/21/1982", "5/25/1982", true), someDays.merge(new Twix("5/21/1982", "5/22/1982", true))
+
+ it "spans a partially later time", ->
+ assertDeepEqual new Twix("5/24/1982", "5/26/1982", true), someDays.merge(new Twix("5/25/1982", "5/26/1982", true))
+
+ it "spans a partially earlier time", ->
+ assertDeepEqual new Twix("5/23/1982", "5/25/1982", true), someDays.merge(new Twix("5/23/1982", "5/25/1982", true))
+
+ it "isn't affected by engulfing events", ->
+ assertDeepEqual someDays, someDays.merge(thatDay())
+
+ it "becomes an engulfing event", ->
+ assertDeepEqual someDays, thatDay().merge(someDays)
+
describe "format()", ->
test = (name, t) -> it name, ->
Please sign in to comment.
Something went wrong with that request. Please try again.