Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- /*@flow*/
- // Creates a function that clones dates and shifts by the
- // seconds specified.
- // Example:
- // >>> import { seconds } from './shift'
- // >>> const fiveSecondsLater = seconds(5)
- // >>> const d = new Date()
- // >>> fiveSecondsLater(d) - d
- // 5000
- export const seconds
- : (sec:number) => (date:Date) => Date
- = sec => date => {
- const shifted = new Date(date) // clone
- shifted.setSeconds(shifted.getSeconds() + sec)
- return shifted
- };
- // Creates a function that clones dates and shifts them by the
- // minutes specified.
- // Example:
- // >>> import { minutes } from './shift'
- // >>> const minutesWindow = (lo, hi) => date =>
- // >>> [minutes(lo), minutes(hi)].map(f => f(date))
- // >>> const within2MinWindow = minutesWindow(-1, 1)
- // >>> const d = new Date('2016-07-01T18:00:00Z')
- // >>> within2MinWindow(d)
- // [ 2016-07-01T17:59:00.000Z, 2016-07-01T18:01:00.000Z ]
- export const minutes
- : (min:number) => (date:Date) => Date
- = min =>
- seconds(min * 60)
- // Creates a function that clones dates and shifts them by the
- // hours specified.
- // Example:
- // >>> import { hours } from './shift'
- // >>> const halfDaySooner = hours(-12)
- // >>> const d = new Date()
- // >>> halfDaySooner(d) - d
- // -43200000
- export const hours
- : (hr:number) => (date:Date) => Date
- = hr =>
- seconds(hr * 3600)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement