fix(task): time+download bug
This commit is contained in:
41
components/label/utils/time.ts
Normal file
41
components/label/utils/time.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
function normalizeDurationSeconds(value: unknown) {
|
||||
const totalSeconds = Number(value ?? 0)
|
||||
if (!Number.isFinite(totalSeconds) || totalSeconds <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return Math.floor(totalSeconds)
|
||||
}
|
||||
|
||||
export function formatWorkTime(value: unknown) {
|
||||
const normalizedSeconds = normalizeDurationSeconds(value)
|
||||
if (!normalizedSeconds) {
|
||||
return "00:00:00"
|
||||
}
|
||||
|
||||
const hours = Math.floor(normalizedSeconds / 3600)
|
||||
const minutes = Math.floor((normalizedSeconds % 3600) / 60)
|
||||
const seconds = normalizedSeconds % 60
|
||||
|
||||
return [hours, minutes, seconds]
|
||||
.map((part) => String(part).padStart(2, "0"))
|
||||
.join(":")
|
||||
}
|
||||
|
||||
export function formatWorkTimeHoursMinutes(value: unknown) {
|
||||
const normalizedSeconds = normalizeDurationSeconds(value)
|
||||
if (!normalizedSeconds) {
|
||||
return "-"
|
||||
}
|
||||
|
||||
const hours = Math.floor(normalizedSeconds / 3600)
|
||||
const minutes = Math.floor((normalizedSeconds % 3600) / 60)
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours}小时${minutes}分钟`
|
||||
}
|
||||
if (minutes > 0) {
|
||||
return `${minutes}分钟`
|
||||
}
|
||||
return "-"
|
||||
}
|
||||
Reference in New Issue
Block a user