mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-01-12 08:34:23 +08:00
Co-authored-by: waynebruce0x <waynebruce0x@gmail.com>
This commit is contained in:
21
test.js
21
test.js
@@ -138,9 +138,26 @@ function validateHallmarks(hallmark) {
|
||||
|
||||
let unixTimestamp = Math.round(Date.now() / 1000) - 60;
|
||||
let chainBlocks = {}
|
||||
const passedTimestamp = process.argv[3] ? Math.floor(new Date(process.argv[3]) / 1000) : undefined
|
||||
|
||||
function parseTimestampArg(arg) {
|
||||
if (!arg) return undefined;
|
||||
// Accept pure numeric input as unix seconds or milliseconds
|
||||
if (/^\d+$/.test(arg)) {
|
||||
const num = Number(arg);
|
||||
if (!Number.isFinite(num)) return undefined;
|
||||
// 13+ digits -> milliseconds, else assume seconds
|
||||
return num > 1e12 ? Math.floor(num / 1000) : num;
|
||||
}
|
||||
// Fallback to Date string parsing (e.g., YYYY-MM-DD)
|
||||
const d = new Date(arg);
|
||||
const ms = d.getTime();
|
||||
if (!Number.isFinite(ms)) return undefined;
|
||||
return Math.floor(ms / 1000);
|
||||
}
|
||||
|
||||
const passedTimestamp = parseTimestampArg(process.argv[3]);
|
||||
if (passedTimestamp !== undefined) {
|
||||
unixTimestamp = Number(passedTimestamp)
|
||||
unixTimestamp = passedTimestamp
|
||||
|
||||
// other chains than evm will fail to get block at timestamp
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user