time-spans
A time span, is always point to the end point of a time period.
A stock candlestick is a left-open right-closed interval, and its time is the close time or current time.
Install
$ npm install time-spans --save
Usage
// Gets the nearest 15-minute breakpointconst m15 = 2016 9 1 7 50const m15 = // Equals to `+ new Date(2016, 9, 1, 7, 45)`m15 // 15 minutes afterm15next // `+ new Date(2016, 9, 1, 8)` // 15 minute beforem15 // 15 * 3 minutes afterm15 // Test if the given time `2016-10-1 7:51`// is in the same period of m15m15 // returns `Boolean`
TimeSpan(time, span)
new {Constructor}(time)
- span
enum<DAY|WEEK|MONTH|...>
- time
(String|Date|Number.<timestamp>)=Date.now()
the initial value of the time.
timestamp()
Returns Number.<TimeStamp>
, the real date.
next()
Returns Number.<TimeStamp>
the next time span
prev()
Returns Number.<TimeStamp>
, the previous time span
offset(delta)
- delta
Number
Returns Number.<TimeStamp>
, the delta
-time time span relative
inSamePeriod(time)
- time
Date|String.<Date>
Date object or stringified date string
Returns Boolean
whether the given time is in the same period of the original time.
License
MIT