days-minutes-diff-calculator
v1.0.0
Published
A library that calculates time difference between the current
Readme
Date Difference Calculator
This is a Node.js library used to calculate the time difference between the current date and a date specified in days, hours and minutes. (If the given date is in the past, the function will throw an error)
Intalling
The library can be installed via npm:
npm install days-minutes-diff-calculatorUsage
Example of usage of the function:
const {calculateTimeDifference} = require('days-minutes-diff-calculator');
try {
const result = calculateTimeDifference('2026-10-01T00:00:00');
if(result.error){
console.error(result.error);
}
else{
console.log(`Days: ${result.days}, Hours: ${result.hours}, Minutes: ${result.minutes}`);
}
} catch (error){
console.error(error.nessage);
}CalculateTimeDifference(targetDate)
Calculates the difference between the current date and the given date.
Parameters
targetDate(string): Target date in a format accepted by javascript'sDateconstructor.
Return
- Object with the difference in days, hours and minutes, or an error message if the given date is in the past.
Return Examples
If the date is in the future
{
"days": 10,
"hours": 5,
"minutes": 30
}If the date is in the past
{
"error": "The date must not be in the past"
}Author
Guilherme Junkes
