rDate is javascript library for manipulate date
const { duration } = require('rdate');
const duration = require('rdate/duration');
or
import { duration } from 'rdate';
import duration from 'rdate/duration';
- addition
- daysInMonth
- duration
- format
- isEarlier
- isLater
- isToday
- parseDate
- sub
- isValidDate
- timeToString
addition(date, { day, hour, minute, second, milisecond})
options:
- date - date in javaScript (
new Date()
) - day - number
- hour - number
- minute - number
- second - number
- milisecond - number
Sample:
addition(new Date('1990/01/11'),{day: 2})
// 1990-01-12T23:00:00.000Z
result: new date with addition days/hours/minutes/seconds/miliseconds
daysInMonth(year, month);
options:
- year - number
- month - number
Sample:
daysInMonth(2019, 2);
// 28
result: numbers of days in month and year
format(date, format);
options:
- date - date in javaScript (
new Date()
) - format
'MM'
- months'DD'
- days'YYYY'
/'YY'
- years'hh'
- hours'mm'
- minutes'ss'
- seconds
Sample:
format(new Date('1990/01/17 12:30:45'), 'MM-DD-YY hh:mm:ss');
// 01-17-90 12:30:45
Check if first parametr is earlier than second. When second parameter is not defined then function check if first parameter is earlier than today.
isEarlier(firstDate, secondDate);
isEarlier(firstDate);
options:
- firstDate - date in javaScript (
new Date()
) - secondDate - date in javaScript (
new Date()
) [optional]
Sample:
isEarlier(new Date(1990, 10, 17), new Date(1990, 12, 17));
// true
isEarlier(new Date(1990, 1, 17));
// false
Check if first parametr is later than second. When second parameter is not defined then function check if first parameter is later than today.
isLater(firstDate, secondDate);
isLater(firstDate);
options:
- firstDate - date in javaScript (
new Date()
) - secondDate - date in javaScript (
new Date()
) [optional]
Sample:
isLater(new Date(1990, 12, 17), new Date(1990, 10, 17));
// true
isLater(new Date(1990, 1, 17));
// false
Parse string to date
parseDate(date);
options:
- date - string (format: 'YYYY/MM/DD', 'DD/MM/YYYY', 'YYYY-MM-DD', 'DD-MM-YYYY')
Sample:
parseDate('2010/10/20');
sub(firstDate, secondDate);
options:
- firstDate - date in javaScript (
new Date()
) - secondDate - date in javaScript (
new Date()
)
Sample:
sub(new Date(1990, 12, 10), new Date(1990, 12, 10));
// 0
sub(new Date(1990, 12, 11), new Date(1990, 12, 10));
// 86400000
result: number in miliseconds
isToday(date);
options:
- date - date in text in format
'YYYY/MM/DD'
Sample:
isToday('1990/01/17');
// false
result: true or false
isValidDate(date);
options:
- date - date in text in format
'YYYY/MM/DD'
Sample:
isValidDate('1990/01/17');
// true
isValidDate('1990-01-17');
// false
isValidDate('2020/03/32');
// false
result: true or false
duration(msValue, date);
options:
- msValue - value in miliseconds
- date - date in javaScript (
new Date()
) [optional]
Sample:
duration(360000);
//{ day: 0, hour: 0, min: 6, sec: 0, ms: 0 }
duration(360000, new Date('1990/01/17 10:00'));
//{ day: 0, hour: 0, min: 6, sec: 0, ms: 0, year: 0, month: 0 }
result: object with value of days, months, years, minutes, hours, seconds and miliseconds
timeToString(time, lang);
options:
- time - string in
format: HH:MM
- lang - string [optional]
Supported languages:
CODE | language |
---|---|
pl | Polish |
Sample:
timeToString('11:29');
//godzina jedynasta minut dwadzieścia dziewięć
result: string
A) github npm
- Zalogowac sie do npm login --scope=luk1790 --registry=https://npm.pkg.github.com przy pomocy username i tokena z ~/.npmrc
- package.json: "name": "@luk1790/rdate", "publishConfig": { "registry": "https://npm.pkg.github.com" },
- npm publish
B) npm
- Logowanie sie do npm login - login i haslo do npm
- package.json: "name": "rdate", "publishConfig": { "registry": "https://registry.npmjs.org/" },
- npm publish