date-difference-calculator-jv
v1.0.0
Published
A library to calculate the time difference between the curent date and a provided date.
Downloads
5
Maintainers
Readme
Time Difference Calculator
A simple JavaScript library to calculate the time difference between the current date and a target future date.
Installation
You can install the library via npm:
npm install time-difference-calculator
Usage
To use the calculateTimeDifference
function, import it into your project:
const { calculateTimeDifference } = require("time-difference-calculator");
Function Signature
calculateTimeDifference(targetDate);
Parameters
targetDate
(string or Date): The future date you want to calculate the difference from the current date. It must be in a valid date format.
Returns
The function returns an object with the following properties:
days
(number): The number of days until the target date.hours
(number): The number of hours remaining after accounting for the days.minutes
(number): The number of minutes remaining after accounting for the hours.
If the target date is in the past, it returns an error object:
{
error: "The date provided is in the past";
}
If the provided date format is invalid, it throws an error:
throw new Error("Invalid date format");
Example
Here’s an example of how to use the calculateTimeDifference
function:
try {
const targetDate = "2024-12-31T23:59:59Z";
const timeDifference = calculateTimeDifference(targetDate);
console.log(
`Days: ${timeDifference.days}, Hours: ${timeDifference.hours}, Minutes: ${timeDifference.minutes}`
);
} catch (error) {
console.error(error.message);
}
License
This project is licensed under the MIT License. See the LICENSE file for details.
## Autor
João Victor Medina
## Agradecimentos
Obrigado por usar `date-difference-calculator-jv`! Se você tiver alguma dúvida ou precisar de ajuda, entre em contato.