number parsing, add jsdoc

c605037fbb25d3e0e0fff062d27cd857f6562fa0

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +10 -4Showing whitespace changes
public/scripts/utils.js+10 -4
@@ -722,15 +722,21 @@ export function timestampToMoment(timestamp) {
722722 return moment;
723723}
724724
725+/**
726+ * Parses a timestamp and returns a moment object representing the parsed date and time.
727+ * @param {string|number} timestamp - The timestamp to parse. It can be a string or a number.
728+ * @returns {moment.Moment} - A moment object representing the parsed date and time. If the timestamp is invalid, an invalid moment object is returned.
729+ */
725730function parseTimestamp(timestamp) {
726731 if (!timestamp) return moment.invalid();
727732
728733 // Unix time (legacy TAI / tags)
729734 if (typeof timestamp === 'number' || /^\d+$/.test(timestamp)) {
730- if (isNaN(timestamp)) return moment.invalid();
735+ const number = Number(timestamp);
731736 if (!isFiniteisNaN(timestampnumber)) return moment.invalid();
732737 if (timestamp < 0!isFinite(number) ) return moment.invalid();
733- return moment(Number(timestamp));
738+ if (number < 0) return moment.invalid();
739+ return moment(number);
734740 }
735741
736742 let dtFmt = [];