Skip to content

Commit

Permalink
The temporal utility mod must not throw an error to take down infoj p…
Browse files Browse the repository at this point in the history
…rocess without return and parse integer values.
  • Loading branch information
dbauszus-glx committed Feb 3, 2025
1 parent bd850f6 commit 5c8eae1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/utils/temporal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Safely converts Unix timestamp to JavaScript Date object
*/
function toJSDate(unixTimestamp) {
if (!Number.isInteger(unixTimestamp)) {
throw new Error('Invalid timestamp: must be an integer');
console.error('unixTimestamp must be integer for Date conversion');
return;
}

return new Date(unixTimestamp * MILLISECONDS_IN_SECOND);
Expand All @@ -34,11 +35,9 @@ Formats a Unix timestamp into a localized date string. If not explicit in the pa
function dateString(params) {
params.locale ??= mapp.user?.language || DEFAULT_LOCALE;

if (!params.value && !params.newValue) {
throw new Error('Either value or newValue must be provided');
}
// The timestamp must be parsed as Integer.
const timestamp = parseInt(params.newValue || params.value);

const timestamp = params.newValue || params.value;
const date = toJSDate(timestamp);

return new Intl.DateTimeFormat(params.locale, params.options).format(date);
Expand All @@ -54,7 +53,8 @@ function dateToUnixEpoch(dateStr) {
const date = dateStr ? new Date(dateStr) : new Date();

if (isNaN(date.getTime())) {
throw new Error('Invalid date string provided');
console.error('Invalid date string provided');
return;
}

return Math.floor(date.getTime() / MILLISECONDS_IN_SECOND);
Expand Down

0 comments on commit 5c8eae1

Please sign in to comment.