This Gist was automatically created by Carbide, a free online programming environment.
Last active
March 6, 2017 18:27
-
-
Save carbide-public/3c4c20da27ccad9159fb9a36824616a8 to your computer and use it in GitHub Desktop.
untitled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event{ | |
from | |
to | |
description | |
constructor(from, to, description ){ | |
this.from = from; | |
this.to = to; | |
this.description = description | |
} | |
} | |
var isConflicting = (event1, event2) => { | |
if( event1.from.getTime() <= event2.from.getTime() && event1.to.getTime() >= event2.from.getTime()) | |
return true; | |
if( event1.from.getTime() <= event2.to.getTime() && event1.to.getTime() >= event2.to.getTime() ) | |
return true | |
if( event2.from.getTime() <= event1.to.getTime() && event2.to.getTime() >= event1.to.getTime() ) | |
return true; | |
if( event2.from.getTime() <= event1.to.getTime() && event2.to.getTime() >= event1.to.getTime() ) | |
return true; | |
return false; | |
} | |
var events = []; | |
events.push( | |
new Event( | |
new Date(2017, 1, 23, 15, 0, 0, 0), | |
new Date(2017, 1, 23, 16, 30, 0, 0), | |
"Interview at the Portal" | |
) | |
) | |
events.push( | |
new Event( | |
new Date(2017, 1, 25, 12, 0, 0, 0), | |
new Date(2017, 1, 25, 1, 0, 0, 0), | |
'Lunch with Cindy' | |
) | |
) | |
events.push( | |
new Event( | |
new Date(2017, 1, 24, 17, 0, 0, 0), | |
new Date(2017, 1, 24, 17, 30, 0, 0), | |
'Dinner with John' | |
) | |
) | |
events.push( | |
new Event( | |
new Date(2017, 1, 24, 11, 0, 0, 0), | |
new Date(2017, 1, 24, 17, 30, 0, 0), | |
'Conference' | |
) | |
) | |
events.push( | |
new Event( | |
new Date(2017, 2, 24, 12, 0, 0, 0), | |
new Date(2017, 2, 24, 12, 30, 0, 0), | |
'Test1' | |
) | |
) | |
events.push( | |
new Event( | |
new Date(2017, 2, 24, 12, 29, 0, 0), | |
new Date(2017, 2, 24, 12, 30, 0, 0), | |
'Test2' | |
) | |
) | |
events.push( | |
new Event( | |
new Date(2017, 4, 24, 0, 29, 0, 0), | |
new Date(2017, 4, 24, 12, 30, 0, 0), | |
'Test3' | |
) | |
) | |
events.push( | |
new Event( | |
new Date(2017, 5, 24, 12, 29, 0, 0), | |
new Date(2017, 5, 24, 12, 30, 0, 0), | |
'Test4' | |
) | |
) | |
console.log(isConflicting(events[0], events[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment