time-spans
v3.2.0
Published
Time spans, especially for financial technology.
Downloads
426
Maintainers
Readme
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
import TimeSpan, {
Second,
Minute,
Minute5,
Minute15,
Minute30,
Minute60,
Day,
Week,
Month
} from 'time-spans'
// Gets the nearest 15-minute breakpoint
const m15 = new Minute15(new Date(2016, 9, 1, 7, 50))
const m15 = TimeSpan(new Date(2016, 9, 1, 7, 50), 'MINUTE15')
// Equals to `+ new Date(2016, 9, 1, 7, 45)`
m15.time()
// 15 minutes after
m15.next() // `+ new Date(2016, 9, 1, 8)`
// 15 minute before
m15.prev()
// 15 * 3 minutes after
m15.offset(3)
// Test if the given time `2016-10-1 7:51`
// is in the same period of m15
m15.inPeriod('2016-10-1 7:51') // 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