Files
baby-tracker/apps/web/src/utils/format.ts
T
2026-09-26 01:09:06 +08:00

32 lines
945 B
TypeScript

export function formatTime(value?: string | null) {
if (!value) return '--'
const date = new Date(value)
return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
}
export function formatMinutes(minutes: number) {
const h = Math.floor(minutes / 60)
const m = minutes % 60
if (h <= 0) return `${m} 分钟`
if (m === 0) return `${h} 小时`
return `${h} 小时 ${m} 分钟`
}
export function recordLabel(type: string, sub?: string | null) {
if (type === 'feeding') {
const map: Record<string, string> = {
breastfeed: '亲喂',
bottle: '瓶喂',
formula: '配方奶',
mixed: '混合',
other: '其他'
}
return `喂奶 · ${map[sub || 'other'] || '其他'}`
}
if (type === 'sleep') return '睡眠'
if (type === 'excretion' && sub === 'pee') return '小便'
if (type === 'excretion' && sub === 'poop') return '大便'
return '记录'
}