use calamine::ExcelDateTime;
pub(super) fn format_excel_datetime(dt: &ExcelDateTime) -> String {
if dt.is_duration() {
let total_seconds = (dt.as_f64() * 86_400.0).round() as i64;
let sign = if total_seconds < 0 { "-" } else { "" };
let seconds = total_seconds.unsigned_abs();
return format!("{sign}{}:{:02}:{:02}", seconds / 3600, seconds / 60 % 60, seconds % 60);
}
let serial = dt.as_f64();
let (year, month, day, hour, min, sec, _milli) = dt.to_ymd_hms_milli();
if (0.0..1.0).contains(&serial) {
format!("{hour:02}:{min:02}:{sec:02}")
} else if serial.fract() == 0.0 {
format!("{year:04}-{month:02}-{day:02}")
} else {
format!("{year:04}-{month:02}-{day:02} {hour:02}:{min:02}:{sec:02}")
}
}