/** §7.7: YYYY-MM-DD HH:mm:ss */
export function formatDateTime(value) {
  if (!value) return '-'
  let iso
  if (value instanceof Date) {
    if (Number.isNaN(value.getTime())) return '-'
    iso = value.toISOString()
  } else {
    const d = new Date(value)
    if (Number.isNaN(d.getTime())) return String(value)
    iso = d.toISOString()
  }
  return iso.replace('T', ' ').slice(0, 19)
}

/** 图表 X 轴短标签 */
export function formatChartTime(date = new Date()) {
  const h = String(date.getHours()).padStart(2, '0')
  const m = String(date.getMinutes()).padStart(2, '0')
  const s = String(date.getSeconds()).padStart(2, '0')
  return `${h}:${m}:${s}`
}
