From 3f0b6803f7290f7291dddc0030338e65bc6cc394 Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Fri, 31 May 2024 17:52:14 +0200 Subject: [PATCH] fix parseTimestamp number fixes: https://github.com/pinax-network/substreams-sink-csv/issues/32 --- README.md | 1 + package.json | 2 +- src/applyReservedFields.ts | 11 ++++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index efb2c0d..f1a84b6 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ Additionally, `*.clock`, `*.session` & `*.cursor` files are generated to keep tr eth.substreams.pinax.network-3b180e1d2390afef1f22651581304e04245ba001-graph_out-block_meta.csv eth.substreams.pinax.network-3b180e1d2390afef1f22651581304e04245ba001-graph_out.clock eth.substreams.pinax.network-3b180e1d2390afef1f22651581304e04245ba001-graph_out.cursor +eth.substreams.pinax.network-3b180e1d2390afef1f22651581304e04245ba001-graph_out.session ``` ### CLI Help diff --git a/package.json b/package.json index 9324c49..5610165 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.3.1", + "version": "0.3.2", "name": "substreams-sink-csv", "description": "Substreams Sink CSV", "type": "module", diff --git a/src/applyReservedFields.ts b/src/applyReservedFields.ts index 5e27a2a..a180ab1 100644 --- a/src/applyReservedFields.ts +++ b/src/applyReservedFields.ts @@ -30,8 +30,17 @@ export function applyReservedFields( values: Record, meta: Meta if ( !values["timestamp"] ) values["timestamp"] = timestamp; // exception parsing timestamp - if ( values["timestamp"] ) values["timestamp"] = parseTimestamp(Timestamp.fromDate(new Date(values["timestamp"] as string))); + if ( values["timestamp"] ) { + // parse UTC string to timestamp + if ( !isNumber(values["timestamp"]) ) { + values["timestamp"] = parseTimestamp(Timestamp.fromDate(new Date(values["timestamp"] as string))); + } + } else values["timestamp"] = timestamp; return values; +} + +function isNumber(value: unknown): value is number { + return !isNaN(Number(value)); } \ No newline at end of file