number parsing, add jsdoc
This commit is contained in:
parent
d30fc5d165
commit
c605037fbb
|
@ -722,15 +722,21 @@ export function timestampToMoment(timestamp) {
|
||||||
return moment;
|
return moment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a timestamp and returns a moment object representing the parsed date and time.
|
||||||
|
* @param {string|number} timestamp - The timestamp to parse. It can be a string or a number.
|
||||||
|
* @returns {moment.Moment} - A moment object representing the parsed date and time. If the timestamp is invalid, an invalid moment object is returned.
|
||||||
|
*/
|
||||||
function parseTimestamp(timestamp) {
|
function parseTimestamp(timestamp) {
|
||||||
if (!timestamp) return moment.invalid();
|
if (!timestamp) return moment.invalid();
|
||||||
|
|
||||||
// Unix time (legacy TAI / tags)
|
// Unix time (legacy TAI / tags)
|
||||||
if (typeof timestamp === 'number' || /^\d+$/.test(timestamp)) {
|
if (typeof timestamp === 'number' || /^\d+$/.test(timestamp)) {
|
||||||
if (isNaN(timestamp)) return moment.invalid();
|
const number = Number(timestamp);
|
||||||
if (!isFinite(timestamp)) return moment.invalid();
|
if (isNaN(number)) return moment.invalid();
|
||||||
if (timestamp < 0) return moment.invalid();
|
if (!isFinite(number)) return moment.invalid();
|
||||||
return moment(Number(timestamp));
|
if (number < 0) return moment.invalid();
|
||||||
|
return moment(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
let dtFmt = [];
|
let dtFmt = [];
|
||||||
|
|
Loading…
Reference in New Issue