The duration in seconds. Values under 30 seconds return undefined.
Optionaloptions: TimeDisplayUnits
Custom display units for the hours and minutes text.
The formatted time, such as "1 hr 30 min" or "45 min", or undefined if the duration is too short.
Rounding:
undefined.Formats:
To override the default units, use options or the global TomTomConfig.
// Basic usage
formatDuration(0); // undefined (too short)
formatDuration(20); // undefined (too short)
formatDuration(30); // "1 min"
formatDuration(60); // "1 min"
formatDuration(100); // "2 min"
formatDuration(1800); // "30 min"
formatDuration(3599); // "1 hr 00 min"
formatDuration(3660); // "1 hr 01 min"
formatDuration(7200); // "2 hr 00 min"
formatDuration(36120); // "10 hr 02 min"
// Custom units
formatDuration(3660, { hours: 'h', minutes: 'm' });
// Returns: "1 h 01 m"
// Route travel time
const route = await calculateRoute({ ... });
const travelTime = formatDuration(route.features[0].summary.travelTimeInSeconds);
console.log(`Estimated time: ${travelTime}`);
// Output: "Estimated time: 2 hr 15 min"
Formats a duration in seconds into a human-readable time string.
It shows hours and minutes, rounding and formatting by the duration's length.