0.0.6 • Published 9 years ago

time-intervals v0.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
9 years ago

Time Intervals

Simple way to output time intervals and date ranges. Ideal for bridging the gap between databases or third party APIs and UI charting libraries. Date types default to Moment objects.

Install

$ npm install time-intervals --save

Usage

Given an interval and duration, output an array of date objects or date strings.. Relative n_period strings use an end date of now.

var timei = require('time-intervals');

// Return 1 minute intervals starting 1 day ago until now.
timei.intervals('1_minute', '1_day');

// Return 1 day intervals for a specific date range.
timei.intervals('1_minute', ['2015-05-01', '2015-06-01']);

// Return 1 day intervals for a relative date range.
timei.intervals('1_minute', chartr.last_year());

// Return 1 second intervals for 1 minute.
timei.intervals('1_second', '1_minute');

Options

Formatting options and timezone offsets.

timei.intervals('1_day', '1_month', {

  // The format to output any date strings.
  format: 'YYYY-MM-DD',
  
  // The value type for intervals ['moment', 'string']
  type: 'moment',
  
  // The object type for the output. ['array', 'object']
  // Object type will apply 0 as the default value.
  output: 'array',
  
  // The UTC offset to use.
  utc_offset: 0
});

Range Helpers

The following helpers can be used for date range durations.

  • this_year()
  • previous_year()
  • next_year()
  • this_month()
  • previous_month()
  • next_month()
  • today()
  • yesterday()
  • tomorrow()
0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago