Fix timestamp capping for storage service

This commit is contained in:
Fedor Indutny
2025-01-30 11:00:20 -08:00
committed by GitHub
parent 96f731270f
commit 24391af642
5 changed files with 141 additions and 7 deletions

View File

@@ -19,7 +19,10 @@ export function getSafeLongFromTimestamp(
return Long.fromNumber(timestamp);
}
export function getTimestampFromLong(value?: Long | null): number {
export function getTimestampFromLong(
value?: Long | null,
maxValue = MAX_SAFE_DATE
): number {
if (!value || value.isNegative()) {
return 0;
}
@@ -27,7 +30,7 @@ export function getTimestampFromLong(value?: Long | null): number {
const num = value.toNumber();
if (num > MAX_SAFE_DATE) {
return MAX_SAFE_DATE;
return maxValue;
}
return num;