A very simple interval library
npm i @lezram/math-interval --save
const Interval = require("@lezram/math-interval").Interval;
const timeInterval = new Interval(Date.UTC(2020, 0, 1), Date.UTC(2020, 0, 3), false, true);
import {Interval} from "@lezram/math-interval";
const timeInterval = new Interval(Date.UTC(2020, 0, 1), Date.UTC(2020, 0, 3), false, true);
<script src="math-interval.js"></script>
<script>
const Interval = MathInterval.Interval;
const timeInterval = new Interval(Date.UTC(2020, 0, 1), Date.UTC(2020, 0, 3), false, true);
console.log(timeInterval);
</script>
new Interval(start: number, end: number, includeStart: boolean, includeEnd: boolean)
Create an interval objectnew Interval(1, 2, true, false);
Interval.from(intervalNotation: string): Interval
Create an interval object from mathematical interval notationInterval.from("[1,2]");
Interval.sort(interval1, interval2, ...): Interval[]
Sort intervals with following order: empty, lowest start, lowest endInterval.union(interval1, interval2, ...): Interval[]
Union elements and sortconst interval1 = new Interval(1, 2, true, true); const interval2 = new Interval(2, 4, false, false); const union = Interval.union(interval1, interval2); // union = new Interval(1, 4, true, false);
obj.isOverlapping(interval: Interval): boolean
Checks if passed interval overlaps/intersectobj.contains(numberOrInterval: number | Interval): boolean
Contains passed number or interval completelyobj.isEmpty(): boolean
If is an empty interval{}
,[2,1]
,(1,1)
,(1,1]
,[1,1)
obj.copy(): Interval
Copy intervalobj.isEqual(interval: Interval): boolean
Check if interval is equal