abacus-timewindow
Utilities for dealing with time windows.
A time window in this context is defined as a range of time covering the boundaries of a specific time to a specific time dimension. For example, [2015-01-01T00:30:00.000Z, 2015-01-01T00:31:00.000Z] would be a time window of January 1, 2015 at 12:30 A.M.
abacus-timewindow works with UTC time. It works in the dimensions of a second, minute, hour, day, and month. The notation for these is as follows:
[M = month, W = week, D = day, h = hour, m = minute, s = second]
Calculating the number of time windows between two dates
abacus-timewindow allows calculating the difference in number of time windows between two dates of a given dimension. For example, calculating the number of monthly time windows between 2016-01 and 2015-09 would result in 4.
// Results in 4timewindow; // Results in 6timewindow; // Results in 13timewindow; // Results in 23timewindow; // Results in 35timewindow;
"Flattening" a date
abacus-timewindow can "flatten" or "zero" out a given date to a single time dimensions. This means that with any given date and dimension, the date will have all values in dimensions lower that the specified one set to zero.
// Returns 2015-05-01, at 00:00:00.000Z timetimewindow;
Calculating the time window bounds of a date
abacus-timewindow can also calculate the beginning and ending bounds of the time window containing the given date to a specified dimension.
// Returns from = 2015-04-20 and to = 2015-04-21 with both at 00:00:00:000Ztimewindow; // Shifts the boundary calculations by -5 days// Returns from = 2015-04-15 and to = 2015-04-16 with both at 00:00:00:000Ztimewindow;