@date/generator
v0.2.0
Published
Calculate dates with easy to read helper functions
Downloads
6,557
Maintainers
Readme
@date/generator
Generate dates with readable function chaining.
Also has functions accepting numbers to help with using values provided from elsewhere.
Install
npm install @date/generator --save
Usage
var gen = require('@date/generator')
// these are equivalent:
// specify each thing individually
var washingtonDay = gen.third().monday().in().february().of(2016)
// skip the in() and of() and specify the year in the february() call
var washingtonDay = gen.third().monday().february(2016)
// specify 'third' with a '3' to monday(),
// 'february' with '1' to month()
var washingtonDay = gen.monday(3).month(1).of(2016)
var thanksgiving = gen.fourth().thursday().in().november().of(2016)
Order
Start with the order functions:
first()
- 1second()
- 2third()
- 3fourth()
- 4last()
- 5 (will be last, even when last is the fourth)
Days
Day functions are available after calling an order function, or, start with them and specify the order value as 1-5:
sunday()
monday()
tuesday()
wednesday()
thursday()
friday()
saturday()
Months
Month functions are available after calling a day function:
january()
february()
march()
april()
may()
june()
july()
august()
september()
october()
november()
december()
Also, shortcut making a call to of(year)
after it and specify the year in the month call, like august(2016)
.
Years
Last call specifies the year to function of(year)
and returns a Date instance.