feat(api): omit tz from sys time date format by default

This commit is contained in:
Pujit Mehrotra
2024-11-22 12:12:41 -05:00
parent 0f3bebf859
commit c36082e82b
3 changed files with 16 additions and 14 deletions

View File

@@ -11,7 +11,9 @@ interface Display {
critical: string; critical: string;
custom: string; custom: string;
dashapps: string; dashapps: string;
/** a strftime format string */
date: string; date: string;
/** a strftime format string */
time?: string; time?: string;
hot: string; hot: string;
max: string; max: string;
@@ -42,10 +44,10 @@ interface Notify {
plugin: string; plugin: string;
docker_notify: string; docker_notify: string;
report: string; report: string;
/** Date format: DD-MM-YYYY, MM-DD-YYY, or YYYY-MM-DD */ /** @deprecated (will remove in future release). Date format: DD-MM-YYYY, MM-DD-YYY, or YYYY-MM-DD */
date: 'd-m-Y' | 'm-d-Y' | 'Y-m-d'; date: 'd-m-Y' | 'm-d-Y' | 'Y-m-d';
/** /**
* Time format: * @deprecated (will remove in future release). Time format:
* - `hi: A` => 12 hr * - `hi: A` => 12 hr
* - `H:i` => 24 hr (default) * - `H:i` => 24 hr (default)
*/ */

View File

@@ -700,9 +700,11 @@ export class NotificationsService {
} }
private parseNotificationDateToIsoDate(unixStringSeconds: string | undefined): Date | null { private parseNotificationDateToIsoDate(unixStringSeconds: string | undefined): Date | null {
if (unixStringSeconds && !isNaN(Number(unixStringSeconds))) { const timeStamp = Number(unixStringSeconds)
return new Date(Number(unixStringSeconds) * 1_000); if (unixStringSeconds && !Number.isNaN(timeStamp)) {
return new Date(timeStamp * 1_000);
} }
// i.e. if unixStringSeconds is an empty string or represents a non-numberS
return null; return null;
} }

View File

@@ -138,18 +138,16 @@ export function formatDatetime(
if (dateFormat === '%c') { if (dateFormat === '%c') {
/**---------------------------------------------- /**----------------------------------------------
* Omit Timezone * Omit Timezone
*
* we omit trailing tz by only keeping the first 6 parts * We omit the trailing tz `%Z` from systime's format
* of sys time (can't omit last x parts bc tz isn't always 3 words). * which expands to '%a %d %b %Y %X %Z' in strftime's
* * implementation. For reference, sys time looks like
* the magic number 6 comes from the sys time string, which * 'Wed 20 Nov 2024 06:39:39 AM Pacific Standard Time'
* looks like 'Wed 20 Nov 2024 06:39:39 AM Pacific Standard Time' *
*
* note: this may not work with right-to-left locales
* (where tz may be in first 6 parts)
*---------------------------------------------**/ *---------------------------------------------**/
if (omitTimezone) { if (omitTimezone) {
formatted = formatted.split(' ').slice(0, 6).join(' '); const timezoneFreeFormat = '%a %d %b %Y %I:%M:%S %p';
formatted = strftime(timezoneFreeFormat, date);
} }
} else { } else {
/**---------------------------------------------- /**----------------------------------------------