Date

Methods

(static) addDays(daysToAddnon-null, dateopt) → {Date}

Returns the date with the sum of the days, by default the date is `new Date()`
Parameters:
Name Type Attributes Default Description
daysToAdd number The number of days to increase
date Date <optional>
new Date() The date to which days are added, by default is `new Date()`
Source:
Example
import { addDays } from 'main-fns';

const myDate = new Date(1996, 05, 26);
console.log(addDays(1, myDate)); // Date(1996, 05, 27)

(static) addMonths(monthsToAddnon-null, dateopt) → {Date}

Returns the date with the sum of the months, by default the date is `new Date()`
Parameters:
Name Type Attributes Default Description
monthsToAdd number The number of months to increase
date Date <optional>
new Date() The date to which months are added, by default is `new Date()`
Source:
Example
import { addMonths } from 'main-fns';

const myDate = new Date(1996, 04, 27)
console.log(addMonths(1, myDate)) // Date(1996, 05, 27)

(static) addYears(yearsToAddnon-null, dateopt) → {Date}

Returns the date with the sum of the years, by default the date is `new Date()`
Parameters:
Name Type Attributes Default Description
yearsToAdd number The number of years to increase
date Date <optional>
new Date() The date to which years are added, by default is `new Date()`
Source:
Example
import { addYears } from 'main-fns';

const myDate = new Date(1995, 05, 27);
console.log(addYears(1, myDate)); // Date(1996, 05, 27)

(static) dateToString(stringFormatnon-null, dateopt) → {string}

Return the date value as string format, by default the date is `new Date()`
Parameters:
Name Type Attributes Default Description
stringFormat DateStringFormat The format of string for date, DateStringFormat for more information.
date Date <optional>
new Date() The date to transform on string, by default is `new Date()`
Source:
See:
  • DateStringFormat
Example
import { dateToString } from 'main-fns';

const myDate = new Date(1996, 05, 27);
console.log(dateToString('dd-MM-yyyy', myDate)); // '27-06-1996'

(static) endOfDay(dateopt) → (non-null) {Date}

Get the date you pass with time to 23:59:59:999
Parameters:
Name Type Attributes Default Description
date Date <optional>
new Date() The date
Source:
Example
import { endOfDay } from 'main-fns';

const myDate = new Date(1996, 05, 27, 22, 10, 10, 345);
console.log(endOfDay(myDate)); // Date(1996, 05, 27, 23, 59, 59, 999)

(static) isAfter(datenon-null, dateToComparenon-null) → {boolean}

Check if the date is after the dateToCompare
Parameters:
Name Type Description
date Date The date
dateToCompare Date The date to compare
Source:
Example
import { isAfter } from 'main-fns';

const myDate = new Date(1996, 05, 27);
const otherDate = new Date(2001, 02, 01);
console.log(isAfter(myDate, otherDate)); // false
console.log(isAfter(otherDate, myDate)); // true

(static) isBefore(datenon-null, dateToComparenon-null) → {boolean}

Check if the date is before the dateToCompare
Parameters:
Name Type Description
date Date The date
dateToCompare Date The date to compare
Source:
Example
import { isBefore } from 'main-fns';

const myDate = new Date(1996, 05, 27);
const otherDate = new Date(2001, 02, 01);
console.log(isBefore(myDate, otherDate)); // true
console.log(isBefore(otherDate, myDate)); // false

(static) relativeTime(datenon-null, localeopt) → {string}

Returns the relative time from date
Parameters:
Name Type Attributes Default Description
date Date The date to compare relative time
locale Locale <optional>
'en-US' The locale to return string, by default is `'en-US'`
Source:
Example
import { relativeTime } from 'main-fns';

// if current date is new Date(1996, 05, 27)
const myDate = new Date(1996, 05, 26);
console.log(relativeTime(myDate)); // 'yesterday'

(static) startOfDay(dateopt) → (non-null) {Date}

Get the date you pass with time to 00:00:00:000
Parameters:
Name Type Attributes Default Description
date Date <optional>
new Date() The date
Source:
Example
import { startOfDay } from 'main-fns';

const myDate = new Date(1996, 05, 27, 22, 10, 10, 345)
console.log(startOfDay(myDate)) // Date(1996, 05, 27, 00, 00, 00, 000)

(static) subtractDays(daysToSubtractnon-null, dateopt) → {Date}

Returns the date with the subtract of the days, by default the date is `new Date()`
Parameters:
Name Type Attributes Default Description
daysToSubtract number The number of days to subtract
date Date <optional>
new Date() The date to which days are subtracted, by default is `new Date()`
Source:
Example
import { subtractDays } from 'main-fns';

const myDate = new Date(1996, 05, 28);
console.log(subtractDays(1, myDate)); // Date(1996, 05, 27)

(static) subtractMonths(monthsToSubtractnon-null, dateopt) → {Date}

Returns the date with the subtract of the months, by default the date is `new Date()`
Parameters:
Name Type Attributes Default Description
monthsToSubtract number The number of months to subtract
date Date <optional>
new Date() The date to which the months are subtracted, by default is `new Date()`
Source:
Example
import { subtractMonths } from 'main-fns';

const myDate = new Date(1996, 06, 27);
console.log(subtractMonths(1, myDate)); // Date(1996, 05, 27)

(static) subtractYears(yearsToSubtractnon-null, dateopt) → {Date}

Returns the date with the subtract of the years, by default the date is `new Date()`
Parameters:
Name Type Attributes Default Description
yearsToSubtract number The number of years to subtract
date Date <optional>
new Date() The date to which the years are subtracted, by default is `new Date()`
Source:
Example
import { subtractYears } from 'main-fns';

const myDate = new Date(1997, 05, 27);
console.log(subtractYears(1, myDate)); // Date(1996, 05, 27)