UNPKG

diffusion

Version:

Diffusion JavaScript client

81 lines (60 loc) 2.04 kB
var Point = require('features/time-series/point'); function Range(anchor, end) { this.anchor = anchor; this.span = end; this.equals = function(other) { if (other && other instanceof Range) { return this.anchor.equals(other.anchor) && this.span.equals(other.span); } return false; }; this.from = function(start) { return new Range(Point.at(start), this.span); }; this.fromStart = function() { return new Range(Point.atStart(), this.span); }; this.fromLast = function(count) { return new Range(Point.offset(count), this.span); }; this.fromLastMillis = function(timespan) { return new Range(Point.offsetMillis(timespan), this.span); }; this.to = function(sequence) { return new Range(this.anchor, Point.at(sequence)); }; this.toStart = function() { return new Range(this.anchor, Point.atStart()); }; this.untilLast = function(count) { return new Range(this.anchor, Point.offset(count)); }; this.untilLastMillis = function(timespan) { return new Range(this.anchor, Point.offsetMillis(timespan)); }; this.next = function(count) { return new Range(anchor, Point.next(count)); }; this.nextMillis = function(timespan) { return new Range(this.anchor, Point.nextMillis(timespan)); }; this.previous = function(count) { return new Range(this.anchor, Point.previous(count)); }; this.previousMillis = function(timespan) { return new Range(this.anchor, Point.previousMillis(timespan)); }; } Range.DEFAULT_RANGE = new Range(Point.atStart(), Point.offset(0)); Range.prototype.toString = function() { var s = ""; if (!this.anchor.equals(Range.DEFAULT_RANGE.anchor)) { s += this.anchor.toAnchorDescription(); } if (!this.span.equals(Range.DEFAULT_RANGE.span)) { s += this.span.toSpanDescription(); } return s; }; module.exports = Range;