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;
custom: string;
dashapps: string;
/** a strftime format string */
date: string;
/** a strftime format string */
time?: string;
hot: string;
max: string;
@@ -42,10 +44,10 @@ interface Notify {
plugin: string;
docker_notify: 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';
/**
* Time format:
* @deprecated (will remove in future release). Time format:
* - `hi: A` => 12 hr
* - `H:i` => 24 hr (default)
*/

View File

@@ -700,9 +700,11 @@ export class NotificationsService {
}
private parseNotificationDateToIsoDate(unixStringSeconds: string | undefined): Date | null {
if (unixStringSeconds && !isNaN(Number(unixStringSeconds))) {
return new Date(Number(unixStringSeconds) * 1_000);
const timeStamp = Number(unixStringSeconds)
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;
}

View File

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