diff-ymd-package Documentation

diff-ymd-package provides APIs for calculating the difference between two dates in formatted ways like (aY bM cD)(aYears bMonths cDays) or customized desired formats like aY-bM-cD or aYears-bMonths-cDays or kDays or mWeeks or nMonths etc.

Classes

DatesYMD(firstDate, secondDate)

Represents a utility class for calculating the difference between two dates in (aYears bMonths cDays)(aY bM cD) format.

Constructor

new DatesYMD(firstDate, secondDate)

Creates an instance of DatesYMD.
Parameters:
Name Type Description
firstDate string The first date in the format 'yyyy-mm-dd' or 'yyyy/mm/dd' or yyyy.mm.dd .
secondDate string The second date in the format 'yyyy-mm-dd' or 'yyyy/mm/dd'or yyyy.mm.dd .
Source:

Methods

customizeFormat(yearUnit, monthUnit, dayUnit, partSeparator) → {string}

Customizes the difference using specified units and separators like (a + yearUnit + partSeparator + b + monthUnit + partSeparator + c + dayUnit), eg. aYs-bMs-cDs etc.
Parameters:
Name Type Description
yearUnit string The unit for years.
monthUnit string The unit for months.
dayUnit string The unit for days.
partSeparator string The separator between year, month, and day parts.
Source:
Returns:
The customized formatted difference.
Type
string

diffArray() → {Array}

Calculates the difference between two dates and returns an array containing Y, M, D, and a formatted 'aY bM cD' difference string.
Source:
Returns:
An array containing the calculated years, months, days, and the formatted difference.
Type
Array

formattedYMD() → {string}

Returns the formatted difference between two dates.
Source:
Returns:
The formatted difference in the format 'aY bM cD'.
Type
string