mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 07:35:27 +03:00
Add function to convert seconds to human readable duration
This commit is contained in:
parent
ee8091ba91
commit
ed5f1e0ad2
@ -229,6 +229,23 @@ export const getDurationFromTimestamps = (
|
||||
return duration;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param seconds - number of seconds to convert into hours, minutes and seconds
|
||||
* @returns string - formatted duration in hours, minutes and seconds
|
||||
*/
|
||||
export const formatSecondsToDuration = (seconds: number): string => {
|
||||
if (isNaN(seconds) || seconds < 0) {
|
||||
return "Invalid duration";
|
||||
}
|
||||
|
||||
const duration = intervalToDuration({ start: 0, end: seconds * 1000 });
|
||||
return formatDuration(duration, {
|
||||
format: ["hours", "minutes", "seconds"],
|
||||
delimiter: ", ",
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Adapted from https://stackoverflow.com/a/29268535 this takes a timezone string and
|
||||
* returns the offset of that timezone from UTC in minutes.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user