Skip to content

Commit b2fc94a

Browse files
committed
Handle negative numbers properly to deserialize pre-1970 values
1 parent b14fdcc commit b2fc94a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

redisinsight/ui/src/utils/formatters/java-date.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ export default class JavaDate implements JavaSerializable {
1414
}
1515

1616
readResolve() {
17-
return new Date(Number(this.time))
17+
let timeValue: number
18+
19+
// Handle two's complement conversion for negative numbers
20+
if (this.time > 9223372036854775807n) {
21+
// If the number is larger than MAX_LONG, it's a negative number in two's complement
22+
timeValue = Number(this.time - 18446744073709551616n)
23+
} else {
24+
timeValue = Number(this.time)
25+
}
26+
27+
const date = new Date(timeValue)
28+
29+
// Validate the date
30+
if (Number.isNaN(date.getTime())) {
31+
throw new Error(`Invalid date value: ${timeValue} (original: ${this.time})`)
32+
}
33+
34+
return date
1835
}
1936
}

0 commit comments

Comments
 (0)