isPast

A utility function to check if a given date is in the past compared to the current date and time.
> isPast(date: Date): boolean
Parameters
  • date: The date to compare with the current date and time.
  • Returns: `true` if the given date is in the past, `false` if the given date is in the future or if the date is invalid.

Example

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

// Check if the given date is in the past
const pastDate = new Date("2023-01-01");
console.log(isPast(pastDate)); // true

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

// Check with a future date
const futureDate = new Date("2025-01-01");
console.log(isPast(futureDate)); // false

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

Use Cases

  • Checking if a specific event or task date is in the past.
  • Filtering past records in data analysis or reporting.
  • Validating if a deadline or expiry date has already passed.