0

I have the following function using moment which checks the difference in minutes from a given UNIX timestamp. actualStartTime is in unix format (for e.g 1599226113699)

const endTime = moment(offer.data.actualStartTime, "x")
  if (endTime.diff(now, "minutes") <= 15 && snapshot.key) {
    remindersSentKeys.push(snapshot.key)
}

Unix timestamp is stored in offer.data.actualStartTime. My problem is I need to add another field duration: number which adds hours in the endTime variable and return in the moment format.

const finalEndTime = moment(offer.data.actualStartTime, "x") + *offer.data.duration*

For e.g if duration is 4. The variable finalEndTime should add an additional 4 hours in the actualStartTime and then check the 15 min difference.

0xburned
  • 2,625
  • 8
  • 39
  • 69
  • That's not a Unix time- its a Javascript time. They have the same datum but the former counts in seconds and the latter in microseconds. – symcbean Sep 05 '20 at 16:06

1 Answers1

0

This will add duration hours to the existing time

moment().add({hours: duration})

For your case

const finalEndTime = moment(offer.data.actualStartTime, "x").add({hours: offer.data.duration});
aRvi
  • 2,203
  • 1
  • 14
  • 30