3.2.0 • Published 6 years ago

time-spans v3.2.0

Weekly downloads
62
License
MIT
Repository
github
Last release
6 years ago

Build Status

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

3.2.0

6 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.2.2

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.0

8 years ago