1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-20 21:54:58 -04:00

Convert Date utilties to TypeScript

This commit is contained in:
Mark McDowall
2025-01-08 21:04:52 -08:00
parent 782af002d6
commit 8482f3da1a
24 changed files with 228 additions and 158 deletions
+25
View File
@@ -0,0 +1,25 @@
import moment, { MomentInput } from 'moment';
function formatTime(
date: MomentInput,
timeFormat: string,
{ includeMinuteZero = false, includeSeconds = false } = {}
) {
if (!date) {
return '';
}
const time = moment(date);
if (includeSeconds) {
timeFormat = timeFormat.replace(/\(?:mm\)?/, ':mm:ss');
} else if (includeMinuteZero || time.minute() !== 0) {
timeFormat = timeFormat.replace('(:mm)', ':mm');
} else {
timeFormat = timeFormat.replace('(:mm)', '');
}
return time.format(timeFormat);
}
export default formatTime;