Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RaRBJFZKSTA7naHGuQHfnQ
24 lines
868 B
JavaScript
24 lines
868 B
JavaScript
// The Lucia project.
|
|
// Copyright 2023-2026 DSP, inc. All rights reserved.
|
|
// Authors:
|
|
// chiayin.kuo@dsp.im (chiayin), 2023/1/31
|
|
// imacat.yang@dsp.im (imacat), 2023/9/23
|
|
// cindy.chang@dsp.im (Cindy Chang), 2024/5/30
|
|
/** @module abbreviateNumber Duration abbreviation formatting. */
|
|
|
|
import formatDuration from "./formatDuration.js";
|
|
|
|
/**
|
|
* Converts a total number of seconds into a human-readable abbreviated
|
|
* duration string using days, hours, minutes, and seconds.
|
|
*
|
|
* @param {number} totalSeconds - The total number of seconds to convert.
|
|
* @returns {string} The abbreviated duration string (e.g. "2d 3h 15m 30s"),
|
|
* or "0" if totalSeconds is zero.
|
|
*/
|
|
export default function abbreviateNumber(totalSeconds) {
|
|
const parsed = Number.parseInt(totalSeconds);
|
|
if (parsed === 0) return "0";
|
|
return formatDuration(parsed, { separator: " " });
|
|
}
|