number parsing, add jsdoc

c605037fbb25d3e0e0fff062d27cd857f6562fa0

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +10 -4Ignore whitespace
public/scripts/utils.js+10 -4
@@ -722,15 +722,21 @@ export function timestampToMoment(timestamp) {
722 return moment;722 return moment;
723}723}
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 */
725function parseTimestamp(timestamp) {730function parseTimestamp(timestamp) {
726 if (!timestamp) return moment.invalid();731 if (!timestamp) return moment.invalid();
727732
728 // Unix time (legacy TAI / tags)733 // Unix time (legacy TAI / tags)
729 if (typeof timestamp === 'number' || /^\d+$/.test(timestamp)) {734 if (typeof timestamp === 'number' || /^\d+$/.test(timestamp)) {
730 if (isNaN(timestamp)) return moment.invalid();735 const number = Number(timestamp);
731 if (!isFinite(timestamp)) return moment.invalid();736 if (isNaN(number)) return moment.invalid();
732 if (timestamp < 0) return moment.invalid();737 if (!isFinite(number)) return moment.invalid();
733 return moment(Number(timestamp));738 if (number < 0) return moment.invalid();
739 return moment(number);
734 }740 }
735741
736 let dtFmt = [];742 let dtFmt = [];