isFuture
A utility function to check if a given date is in the future compared to the current date and time.> isFuture(date: Date): boolean
- date: The date to compare with the current date and time.
- Returns: `true` if the given date is in the future, `false` if the given date is in the past or if the date is invalid.
Example
import { isFuture } from "@explita/daily-toolset";
// Check if the given date is in the future
const futureDate = new Date("2025-01-01");
console.log(isFuture(futureDate)); // true
// Check with today's date
const today = new Date();
console.log(isFuture(today)); // false
// Check with a past date
const pastDate = new Date("2023-01-01");
console.log(isFuture(pastDate)); // false
// Check with an invalid date
const invalidDate = new Date("invalid date string");
console.log(isFuture(invalidDate)); // false
Use Cases
- Checking if a specific event or task date is in the future.
- Filtering future records for upcoming events or tasks.
- Validating if a deadline or expiry date is still to come.