addMinutes

A utility function to add or subtract a specified number of minutes to/from a given date.
> addMinutes(minutes: number, date: Date = new Date()): Date
Parameters
  • minutes (number): The number of minutes to add. Use a negative number to subtract minutes.
  • date (Date, optional): The base date to modify. Defaults to the current date (new Date()).
  • Returns: A new Date object with the specified number of minutes added.

Example

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

// Add 15 minutes to the current time
const laterToday = addMinutes(15);
console.log(laterToday); // e.g., 2024-11-22T14:15:00.000Z

// Subtract 30 minutes from a specific date
const earlierTime = addMinutes(-30, new Date("2024-11-22T14:00:00"));
console.log(earlierTime); // e.g., 2024-11-22T13:30:00.000Z

// Add 90 minutes to a custom date
const customDate = new Date("2000-01-01T08:00:00");
const result = addMinutes(90, customDate);
console.log(result); // e.g., 2000-01-01T09:30:00.000Z

Use Cases

  • Fine-tuning timestamps for scheduled events.
  • Working with time-sensitive calculations like countdowns or timers.
  • Handling adjustments for dynamic durations or intervals.