diff-ymd-package
diff-ymd-package provides api to difference dates in formatted ways(like (aYears bMonths cDays) or (aY bM cD), eg. age = 20Y 2M 23D or datesDifference = 2Years 11Months 20Days)
Installation
npm install my-api-package
Usage
const DatesYMD = require('diff-ymd-package');
const date1 = '2022-01-01';
const date2 = '2023-12-31';
const calculator = new DatesYMD(date1, date2);
const result = calculator.formattedYMD();
const resultArray = calculator.diffArray();
console.log(result);
console.log(resultArray);
API Documentation
DatesYMD
Represents a utility class for calculating the difference between two dates.
Create an instance of DatesYMD
:
const calculator = new DatesYMD(firstDate, secondDate);
firstDate
: The first date in the format 'yyyy-mm-dd' or 'yyyy/mm/dd' or 'yyyy.mm.dd'.secondDate
: The second date in the format 'yyyy-mm-dd' or 'yyyy/mm/dd' or 'yyyy.mm.dd'.
Methods:
diffArray
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 = calculator.diffArray();
Returns:
An array containing the calculated years, months, days, and the formatted difference.
formattedYMD()
Returns the formatted difference between two dates in aYears bMonths cDays(aY bM cD) format.
const result = calculator.formattedYMD();
Returns:
A string in the format 'aY bM cD'.
For more information, check out diff-ymd-package documentation
Contributing
If you find any issues or have suggestions for improvement, please open an issue or create a pull request on the GitHub repository.
License
- This project is licensed under the MIT License - see the LICENSE file for details.
License here
Additional Notes
Best Practices:
The code adheres to recommended practices for readability and maintainability, including:
- Meaningful variable and function names for clarity.
- Clear and concise comments to enhance understanding.
- Proper indentation and formatting for visual organization.
Important Links:
- For more details about what has changed in each version of this project, please see the CHANGELOG.
CHANGELOG here