abbott-methods
Version:
abbott,methods,method,functions,function
39 lines (38 loc) • 1.06 kB
text/typescript
/**
* @description 秒牌
* @param {number} seconds 秒数
* @returns {string}
*/
export const timeSecondBar = (seconds: number): { is: boolean; days: string; hours: string; minutes: string; seconds: string } => {
let isPositive = true
if (seconds < 0) {
isPositive = false
}
seconds = Math.abs(seconds)
let showMinutes = 0
let showHours = 0
let showDays = 0
const showSeconds = ~~(+seconds % 60)
if (seconds > 59) {
showMinutes = ~~(+seconds / 60)
}
if (showMinutes > 59) {
showHours = ~~(showMinutes / 60)
}
showMinutes = ~~(showMinutes % 60)
if (showHours > 59) {
showDays = ~~(showHours / 24)
}
showHours = ~~(showHours % 24)
const showDaysStr = String(showDays).padStart(2, '0')
const showHoursStr = String(showHours).padStart(2, '0')
const showMinutesStr = String(showMinutes).padStart(2, '0')
const showSecondsStr = String(showSeconds).padStart(2, '0')
return {
is: isPositive,
days: showDaysStr,
hours: showHoursStr,
minutes: showMinutesStr,
seconds: showSecondsStr
}
}