Date Grab
Date grab provides a thin functional wrapper for getting Date object properties.
Useage
var grab = require('date-grab');
var countdown = new Date('July 1, 2015');
var year = grab('year')
var date = grab('date')
var utcHours = grab('hours', { utc: true })
var monthYear = grab(['month', 'year'])
grab(property, options)
Date grab creates a function that gets date property, wraps standard Date
object functions. property should be a String or String Array and config should be an Object.
More thorough documentation on Dates can be found at MDN, but here is a basic conversion chart.
grab('time')(date) | date.getTime() |
grab('timezone')(date) | date.getTimezoneOffset() |
grab('year')(date) | date.getYear() |
grab('month')(date) | date.getMonth() |
grab('date')(date) | date.getDate() |
grab('day')(date) | date.getDay() |
grab('hours')(date) | date.getHours() |
grab('minutes')(date) | date.getMinutes() |
grab('seconds')(date) | date.getSeconds() |
grab('milliseconds')(date) | date.getMilliseconds() |
options
utc
Setting utc
to true
will use UTC instead of local date functions.
var now = new Date()
var utcHours = grab('hours', { utc: true })
utcHours(now) === now.getUTCHours()