1.0.6 • Published 10 months ago
@emzra/date-library v1.0.6
Your Date Lib
A custom date library.
Badges
Installation
npm install @emzra/date-library
Usage
Creating Dates
const D = require('@emzra/date-library');
// With no parameters
const d1 = new D();
console.log(d1.\_date); // Current date
// From a string
const d2 = new D('9/26/1965');
console.log(d2.\_date); // 1965-09-26T00:00:00.000Z
// From numbers
const d3 = new D(1970, 1, 1, 0, 0, 0);
console.log(d3.\_date); // 1970-02-01T00:00:00.000Z
// With a Date object
const d4 = new D(new Date());
console.log(d4.\_date); // Current date
Getters
const d = new D(2020, 0, 1, 12, 30, 45);
console.log(d.year); // 2020
console.log(d.shortYear); // 20
console.log(d.month); // 1
console.log(d.date); // 1
console.log(d.hour); // 12
console.log(d.minutes); // 30
console.log(d.seconds); // 45
console.log(d.dayOfWeek); // 3 (Wednesday)
console.log(d.fullDayOfWeek); // Wednesday
console.log(d.shortDayOfWeek); // Wed
console.log(d.ordinalSuffix); // st
Formatting Dates
const d = new D(2017, 0, 2, 3, 4, 5);
console.log(d.format()); // 2017 January 02
console.log(d.format('YY/Mon/D')); // 17/Jan/2
console.log(d.format('HH:mm:ss')); // 03:04:05
console.log(d.format('H:m:s')); // 3:4:5
console.log(d.format('YYYY-Month-DD H:mm:ss')); // 2017-January-02 3:04:05
Human-Readable Descriptions
const now = new Date();
const threeHoursFromNow = new Date(now.getTime() + 3 _ 60 _ 60 \* 1000);
const d = new D(
threeHoursFromNow.getFullYear(),
threeHoursFromNow.getMonth(),
threeHoursFromNow.getDate(),
threeHoursFromNow.getHours(),
threeHoursFromNow.getMinutes(),
threeHoursFromNow.getSeconds()
);
console.log(d.when()); // 3 hours from now
License
This project is licensed under the MIT License.