Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nils_penzel committed Sep 9, 2024
1 parent 5121e36 commit e922e14
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 203 deletions.
21 changes: 21 additions & 0 deletions src/lib/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,25 @@ export class Interval {
merged.push(unmerged.pop()!);
return merged;
};

intersect(other:Interval):Interval|undefined{
if(this.overlaps(other)){
return new Interval(new Date(Math.max(this.startTime.getTime(), other.startTime.getTime())), new Date(Math.min(this.endTime.getTime(), other.endTime.getTime())));
}
return undefined;
};

static intersect = (many: Interval[], one: Interval): Interval[] => {
const result: Interval[] = [];
for(let i=0;i!=many.length;++i){
if(one.startTime.getTime() > many[i].endTime.getTime()){
break;
}
if(!many[i].overlaps(one)){
continue;
}
result.push(many[i].intersect(one)!);
}
return result;
}
}
Loading

0 comments on commit e922e14

Please sign in to comment.