Created
April 14, 2023 18:20
-
-
Save WenderGalan/17e36938a6467a01434953aece96fa51 to your computer and use it in GitHub Desktop.
Calcular Tempo de Espera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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