hoursSince

A utility function to calculate the number of hours that have passed since a given date.
> hoursSince(date: Date): number
Parameters
  • date: The past date to calculate the number of hours that have passed.
  • Returns: The number of hours that have passed since the given date. If the date is today or in the future, it returns `0`. If the date is invalid, it also returns `0`.

Example

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

// Calculate the number of hours since a past date
const pastDate = new Date("2023-01-01T10:00:00");
console.log(hoursSince(pastDate)); // Number of hours since January 1st, 2023 at 10 AM

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

// Check with a future date
const futureDate = new Date("2025-01-01T10:00:00");
console.log(hoursSince(futureDate)); // 0

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

Use Cases

  • Tracking how many hours have passed since a specific event or action.
  • Measuring time intervals between tasks or milestones.
  • Determining elapsed time for time-sensitive processes or transactions.