Skip to content

Instantly share code, notes, and snippets.

@WenderGalan
Created April 14, 2023 18:20
Show Gist options
  • Save WenderGalan/17e36938a6467a01434953aece96fa51 to your computer and use it in GitHub Desktop.
Save WenderGalan/17e36938a6467a01434953aece96fa51 to your computer and use it in GitHub Desktop.
Calcular Tempo de Espera
/**
* @param dataHoraEntrada
* @param dataHoraDiff
* @param seconds
* @returns {`${number}h ${string}m ${string}s`}
*/
export const calcularTempoEspera = (dataHoraEntrada, dataHoraDiff, seconds) => {
// start time and end time
let startTime = moment(dataHoraEntrada, 'DD/MM/YYY hh:mm:ss')
let endTime = moment(dataHoraDiff, 'DD/MM/YYY hh:mm:ss').add(seconds, 'seconds')
let totalHours = (endTime.diff(startTime, 'hours'))
let totalMinutes = endTime.diff(startTime, 'minutes')
let totalSeconds = endTime.diff(startTime, 'seconds')
let clearMinutes = totalMinutes % 60
let clearSecodns = (totalSeconds % 60) % 60
// let totalMinutesFormt = formatId(totalHours, 3)
let totalMinutesFormat = formatId(clearMinutes, 2)
let totalSecondsFormat = formatId(clearSecodns, 2)
return `${totalHours}h ${totalMinutesFormat}m ${totalSecondsFormat}s`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment