D - A Date Utility Class
The D
class is a utility class for working with dates in JavaScript. It provides several convenient methods and properties for getting and formatting dates.
Installation
npm install @gramsay7/date-lib
Usage
First, import the D
class from the package:
import D from '@gramsay7/date-lib';
Then, you can create a new D
object:
const d = new D(2017, 8, 2, 3, 4, 5);
You can use the getters to get various parts of the date:
console.log(d.year);
console.log(d.yr);
console.log(d.month);
console.log(d.mon);
console.log(d.day);
console.log(d.dy);
console.log(d.date);
console.log(d.hours);
console.log(d.mins);
console.log(d.secs);
console.log(d.ordinal);
You can use the format
method to format the date:
console.log(d.format('Y-M-D h:i:s'));
You can use the when
method to get a human-readable description of when the date will occur:
console.log(d.when());
Tests
To run the tests for the D
class, use the following command:
npm test