Skip to content

Commit 397d466

Browse files
committed
Move the constants to the class level and use them in the code
1 parent b2fc94a commit 397d466

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export default class JavaDate implements JavaSerializable {
77
// The serial version UID followed for 'java.util.Date'
88
static readonly SerialVersionUID = '7523967970034938905'
99

10+
// The maximum value for a Java long
11+
readonly JAVA_MAX_LONG = 9223372036854775807n // 2^63 - 1
12+
13+
// The maximum value for a two's complement long
14+
readonly TWO_COMPLEMENT_MAX_LONG = 18446744073709551616n // 2^64
15+
1016
time: bigint = 0n
1117

1218
readObject(stream: ObjectInputStream): void {
@@ -17,9 +23,9 @@ export default class JavaDate implements JavaSerializable {
1723
let timeValue: number
1824

1925
// Handle two's complement conversion for negative numbers
20-
if (this.time > 9223372036854775807n) {
26+
if (this.time > this.JAVA_MAX_LONG) {
2127
// If the number is larger than MAX_LONG, it's a negative number in two's complement
22-
timeValue = Number(this.time - 18446744073709551616n)
28+
timeValue = Number(this.time - this.TWO_COMPLEMENT_MAX_LONG)
2329
} else {
2430
timeValue = Number(this.time)
2531
}

0 commit comments

Comments
 (0)