API Reference

Returns a date in the future or past of a starting date based on a duration

function dateFromDuration(
  duration: Partial<Duration>,
  startDate: Date = new Date(),
)

// Example:

const fromDate = new Date("Jan 1, 2024 12:00:00AM")

dateFromDuration({hours: 2, minutes: 3, seconds: 4}, fromDate)
//=> Date: "Jan 1, 2024 02:03:04 AM"

dateFromDuration({days: -1, hours: -2, minutes: -3, seconds: -4}, fromDate)
//=> Date: "Dec 30, 2023 9:57:56 PM"

NOTE: To get a date in the past of your provided startDate, use negative numbers in your duration.