Sha256: d5558fa5df90131da0c69e949770c48db039ae1f9f1e6b7570ef7af621a27fbd
Contents?: true
Size: 1.42 KB
Versions: 14
Compression:
Stored size: 1.42 KB
Contents
define([ 'kbn' ], function (kbn) { 'use strict'; /** * manages the interval logic * @param {[type]} interval_string An interval string in the format '1m', '1y', etc */ function Interval(interval_string) { this.string = interval_string; var info = kbn.describe_interval(interval_string); this.type = info.type; this.ms = Math.ceil(info.sec * 1000 * info.count); // does the length of the interval change based on the current time? if (this.type === 'y' || this.type === 'M') { // we will just modify this time object rather that create a new one constantly this.get = this.get_complex; this.date = new Date(0); } else { this.get = this.get_simple; } } Interval.prototype = { toString: function () { return this.string; }, after: function(current_ms) { return this.get(current_ms, 1); }, before: function (current_ms) { return this.get(current_ms, -1); }, get_complex: function (current, delta) { this.date.setTime(current); switch(this.type) { case 'M': this.date.setUTCMonth(this.date.getUTCMonth() + delta); break; case 'y': this.date.setUTCFullYear(this.date.getUTCFullYear() + delta); break; } return this.date.getTime(); }, get_simple: function (current, delta) { return current + (delta * this.ms); } }; return Interval; });
Version data entries
14 entries across 7 versions & 1 rubygems