daysUntil

A utility function to calculate the number of days until a given date.
> daysUntil(date: Date): number
Parameters
  • date: The future date to calculate the number of days until.
  • Returns: The number of days remaining until the given date. If the date is today or in the past, it returns `0`. If the date is invalid, it also returns `0`.

Example

import { daysUntil } from "@explita/daily-toolset";

// Calculate the number of days until a future date
const futureDate = new Date("2025-01-01");
console.log(daysUntil(futureDate)); // Number of days until January 1st, 2025

// Check with today's date
const today = new Date();
console.log(daysUntil(today)); // 0

// Check with a past date
const pastDate = new Date("2023-01-01");
console.log(daysUntil(pastDate)); // 0

// Check with an invalid date
const invalidDate = new Date("invalid date string");
console.log(daysUntil(invalidDate)); // 0

Use Cases

  • Calculating the time remaining before an event or deadline.
  • Tracking the number of days left for a countdown or expiration date.
  • Managing tasks or projects with time-sensitive milestones or due dates.