| 722 | 722 | return moment; |
| 723 | 723 | } |
| 724 | 724 | |
| 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 | + */ |
| 725 | 730 | function parseTimestamp(timestamp) { |
| 726 | 731 | if (!timestamp) return moment.invalid(); |
| 727 | 732 | |
| 728 | 733 | // Unix time (legacy TAI / tags) |
| 729 | 734 | if (typeof timestamp === 'number' || /^\d+$/.test(timestamp)) { |
| 730 | | - if (isNaN(timestamp)) return moment.invalid(); |
| 735 | + const number = Number(timestamp); |
| 731 | 736 | if (!isFiniteisNaN(timestampnumber)) return moment.invalid(); |
| 732 | 737 | if (timestamp < 0!isFinite(number) ) return moment.invalid(); |
| 733 | | - return moment(Number(timestamp)); |
| 738 | + if (number < 0) return moment.invalid(); |
| 739 | + return moment(number); |
| 734 | 740 | } |
| 735 | 741 | |
| 736 | 742 | let dtFmt = []; |