npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@orafavictor/date-difference-calculator

v1.0.0

Published

A library to calculate the time difference between the curretn date and a provided date.

Readme

Date Difference Calculator

Uma biblioteca leve e prática para calcular a diferença de tempo exata entre o momento atual e uma data futura. Ideal para criar contagens regressivas (countdowns), verificar prazos ou calcular tempo restante em dias, horas, minutos e segundos.

📋 Índice

🚀 Instalação

Para instalar este pacote no seu projeto, execute o seguinte comando no terminal:

npm install date-difference-calculator

💻 Como Usar
A biblioteca exporta uma função principal chamada calculateTimeDifference. Você deve importar a função e passar a data alvo (futura) como argumento.

Aqui está um exemplo básico de como implementar:

JavaScript
const { calculateTimeDifference } = require('date-difference-calculator');

// Defina uma data futura (Ex: Ano Novo de 2026)
// Recomendamos passar um objeto Date ou um timestamp
const targetDate = new Date('2026-01-01T00:00:00');

try {
    const timeRemaining = calculateTimeDifference(targetDate);
    
    // Verifica se houve erro de data no passado
    if (timeRemaining.error) {
        console.log("Atenção:", timeRemaining.error);
    } else {
        console.log(`Faltam: 
        ${timeRemaining.days} dias, 
        ${timeRemaining.hours} horas, 
        ${timeRemaining.minutes} minutos e 
        ${timeRemaining.seconds} segundos.`);
    }
} catch (err) {
    console.error("Erro na data:", err.message);
}
✨ Funcionalidades
Cálculo Preciso: Retorna a diferença quebrada em dias, horas, minutos e segundos.

Validação de Data: Verifica se a data fornecida é válida.

Verificação de Passado: Identifica se a data alvo já passou e retorna uma mensagem amigável ao invés de números negativos.

📚 API
calculateTimeDifference(targetDate)

Calcula o tempo restante até a targetDate.

Parâmetros

Parâmetro	Tipo	Descrição
targetDate	Date	Number
Retorno

Retorna um Objeto contendo os seguintes campos:

JavaScript
{
  days: number,    // Dias restantes
  hours: number,   // Horas restantes (0-23)
  minutes: number, // Minutos restantes (0-59)
  seconds: number  // Segundos restantes (0-59)
}
Caso a data seja no passado, o retorno será:

JavaScript
{
  error: 'Date provided is in the past'
}
⚠️ Tratamento de Erros
A função lançará um erro (throw Error) se o formato da data for inválido (por exemplo, algo que não seja uma data ou número). Recomenda-se envolver a chamada da função em um bloco try...catch ou garantir que o input seja um objeto Date válido.

👤 Autor
Rafael Victor

Sinta-se à vontade para contribuir ou reportar problemas!

📄 Licença
Este projeto está sob a licença ISC.


---

### 💡 Dica Técnica (Opcional)

Notei um detalhe interessante no seu código no arquivo `index.js`:

```javascript
if (isNaN(targetDate)){
    throw new Error("Invalid date format");
}
A função isNaN funciona bem para números e objetos Date, mas se o usuário tentar passar uma string diretamente (ex: "2025-12-25"), o isNaN retornará true e vai dar erro, mesmo a string sendo uma data válida.

Sugestão de melhoria para a versão 1.0.1: Se você quiser aceitar strings diretamente no futuro, você pode ajustar a validação para verificar a data depois de convertê-la:

JavaScript
// Exemplo de ajuste:
const futureDate = new Date(targetDate);

// Valida se a data criada é válida (Date inválido vira "Invalid Date", que é NaN em valor numérico)
if (isNaN(futureDate.getTime())) { 
    throw new Error("Invalid date format");
}