rdate v2.0.7
rDate 
rDate is javascript library for manipulate date
Example Usage
const { duration } = require('rdate');
const duration = require('rdate/duration');or
import { duration } from 'rdate';
import duration from 'rdate/duration';List of functions:
Functions
- addition()
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.000Zresult: new date with addition days/hours/minutes/seconds/miliseconds
- daysInMonth()
daysInMonth(year, month);options:
- year - number
- month - number
Sample:
daysInMonth(2019, 2);
// 28result: numbers of days in month and year
- format()
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- isEarlier()
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- isLater()
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- parseDate()
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()
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));
// 86400000result: number in miliseconds
- isToday()
isToday(date);options:
- date - date in text in format
'YYYY/MM/DD'
Sample:
isToday('1990/01/17');
// falseresult: true or false
- isValidDate()
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');
// falseresult: true or false
- duration()
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()
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