Correct rounding and carry of minutes in Vue.prototype.$elapsedPrettyExtended

-Add cypress tests for Vue.prototype.$elapsedPrettyExtended function
This commit is contained in:
Daniel Lauzon 2025-01-13 13:36:15 -05:00
parent 7001adb4dd
commit acda776e3e
2 changed files with 198 additions and 5 deletions

View file

@ -69,17 +69,22 @@ Vue.prototype.$elapsedPrettyExtended = (seconds, useDays = true, showSeconds = t
let hours = Math.floor(minutes / 60)
minutes -= hours * 60
// Handle rollovers before days calculation
if (minutes && seconds && !showSeconds) {
if (seconds >= 30) minutes++
if (minutes >= 60) {
hours++ // Increment hours if minutes roll over
minutes -= 60 // adjust minutes
}
}
// Now calculate days with the final hours value
let days = 0
if (useDays || Math.floor(hours / 24) >= 100) {
days = Math.floor(hours / 24)
hours -= days * 24
}
// If not showing seconds then round minutes up
if (minutes && seconds && !showSeconds) {
if (seconds >= 30) minutes++
}
const strs = []
if (days) strs.push(`${days}d`)
if (hours) strs.push(`${hours}h`)