1.0.11 • Published 4 years ago

alegrify-date v1.0.11

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Alegrify Date

Pure JS Date library

Build Status NPM

Install

npm i alegrify-date

or

yarn i alegrify-date

How to use

const AlegrifyDate = require('alegrify-date');

const date = new AlegrifyDate();

// Set year to 2020
date.year = 2020;

// Set month to January
date.month = 'Jarnuary';

// Add one month
date.month++;

// Subtract 3 days
date.day -= 3;

// Add 5 minutes
date.minute = 5;

// Format the date
console.log(date.format('DD MMMM, HHhmm'));

API

Date.prototype

Alegrify Date extends from the Date Object, so every original Date method can be used such as getTime and toString

Property second

date.second = 22;
console.log(date.second);

Property minute

date.minute = 15;
console.log(date.minute);

Property minute

date.hour = 23;
console.log(date.hour);

Property day

date.day = 'Monday'; // Set to Monday in the same week
date.day = 16; // Set to the 16th day in the month
console.log(date.day);

Property month

date.month = 'Februrary'; // Set date to same day in February
date.month = 3; // Set date to same day in March
console.log(date.month);

Property year

date.year = 2017;
console.log(date.year);

Method format

Display the date in a certain format

const date = AlegrifyDate('2019-06-03T20:45:00');
return date.format('D MMMM YYYY HH[h]');
// Will return 3 June 2019 20h
ParamDescriptionExample
s1 digit second value1 2 12
ss2 digits second value01 02 12
m1 digit minute value1 2 12
mm2 digits minute value01 02 12
H1 digit hour value1 2 12
HH2 digits hour value01 02 12
D1 digit day value1 2 12
DD2 digits day value01 02 12
 DoFormat day with 'Xth'2nd 4th
d Weekday one digitMo = 1
dd Short weekday stringMo Tu
dddMedium weekday stringMon Tue
ddddFull weekday stringMonday
ddddFull weekday stringMonday
e Weekday one digitSu = 0
MMonth one digitJan = 1
MMMonth two digitsJan = 01
MMMMonth short nameJan Feb
MMMMMonth full nameJanuary
MoFormat month with 'Xth'Jan = 1st
YYShort code year2019 = 19
YYYYShort code year2018 2019
1.0.11

4 years ago

1.0.10

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago