daychange v1.0.4
A small and simple Node.js module that will allow for you to easily add or subtract days against your Node environment's current UTC date, with options to format the returned string or to simply receive a date object.
Why daychange?
I created this module after working with several APIs that rely on date values and/or return date values (along with other data). At times, I want to ensure that my application is only returning or handling content within a particular date range, usually a range that spans the current date back to a set number of days, weeks, months, years, etc.
After creating a few helper functions for this task, I realized that they could serve as a great module for the Node.js community.
Getting Started
npm install daychange
Examples
Adding Days
const dayChange = require('daychange');
dayChange.add(365);
// returns 2017-09-08T03:16:57.732Z
dayChange.add(30, 'long');
// returns Sat Oct 08 2016 03:16:57 GMT+0000 (UTC)
Subtracting Days
const dayChange = require('daychange');
dayChange.sub(14, 'short');
// returns 8/25/2016
dayChange.sub(90, 'iso');
// returns 2016-06-10T03:18:54.092Z
Usage
###dayChange.add(number, string);
###dayChange.sub(number, string);
Each method accepts up to two arguments: days and format.
Days
Type: number
Required: yes
Days is a required argument and must be a number equal to or greater than zero.
Format
Type: string
Choices: 'iso'
, json
, 'long'
, short
Required: no
Format is an optional argument that must be a string. Without passing a format argument, daychange
will return a typical date object.
License
The MIT License (MIT)
Copyright (c) 2016 John Foderaro
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.