| 722 | return moment; | 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 | function parseTimestamp(timestamp) { | 730 | function parseTimestamp(timestamp) { |
| 726 | if (!timestamp) return moment.invalid(); | 731 | if (!timestamp) return moment.invalid(); |
| 727 | | 732 | |
| 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 | } |
| 735 | | 741 | |
| 736 | let dtFmt = []; | 742 | let dtFmt = []; |