-
-
Notifications
You must be signed in to change notification settings - Fork 11
diff‐ymd‐package API Documentation
Welcome to the diff-ymd-package wiki👋
Represents a utility class for calculating the formatted and desired customized difference between two dates in all cases.
const Formatter = new DatesYMD(firstDate, secondDate);
//const DatesYMD = require('@farhan7reza7/diff-ymd-package'); or
const DatesYMD = require('diff-ymd-package');
const Formatter = DatesYMD.diffDates(firstDate, secondDate); // can use any
-
firstDate
: The first date in the format 'yyyy-mm-dd' or 'yyyy/mm/dd' or 'yyyy.mm.dd' or dateString or dateObject or Timestamp(epoch). -
secondDate
: The second date in the format 'yyyy-mm-dd' or 'yyyy/mm/dd' or 'yyyy.mm.dd' or dateString or dateObject or Timestamp(epoch). -
Special case: empty string("" or '') is by default to current-date(today) for the parameters
-
Returns:
An instance of DatesYMD class.
Calculates the difference between two dates and returns an array containing Y(years), M(months), D(days), and a formatted 'aY bM cD' difference string.
const result = Formatter.diffArray();
Returns:
An array containing the calculated years, months, days, and the formatted difference.
Returns the formatted difference between two dates in aY bM cD(aYears bMonths cDays) format.
const result = Formatter.formattedYMD();
Returns:
A string in the format 'aY bM cD'.
Customizes the difference using specified units and separators
const result = Formatter.customizeFormat(
yearUnit,
monthUnit,
dayUnit,
partSeparator,
);
Returns:
A customized formatted difference string of form (a + yearUnit + partSeparator + b + monthUnit + partSeparator + c + dayUnit), eg. aYs-bMs-cDs etc.
Calculates the difference in months between two dates.
const monthsDifference = Formatter.diffInMonths();
Returns: The difference in months.
Calculates the difference in weeks between two dates.
const weeksDifference = Formatter.diffInWeeks();
Returns: The difference in weeks.
Calculates the difference in days between two dates.
const daysDifference = Formatter.diffInDays();
Returns: The difference in days.
Calculates the difference in years between two dates.
const yearsDifference = Formatter.diffInYears();
Returns: The difference in years.
Calculates the difference in hours between two dates.
const hoursDifference = Formatter.diffInHours();
Returns: The difference in hours.
Calculates the difference in minutes between two dates.
const minutesDifference = Formatter.diffInMinutes();
Returns: The difference in minutes.
Calculates the difference in seconds between two dates.
const secondsDifference = Formatter.diffInSeconds();
Returns: The difference in seconds.