Skip to content

Commit 8de0601

Browse files
committed
Method to get an event time stamp as milliseconds since the Unix epoch to avoid time zone calculations
1 parent d27d01a commit 8de0601

File tree

1 file changed

+6
-4
lines changed
  • src/main/java/io/api/etherscan/model

1 file changed

+6
-4
lines changed

src/main/java/io/api/etherscan/model/Log.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,18 @@ public LocalDateTime getTimeStamp() {
6767
}
6868

6969
/**
70-
*
71-
* @return
70+
* Return the "timeStamp" field of the event record as a long-int representing the milliseconds
71+
* since the Unix epoch (1970-01-01 00:00:00).
72+
* @return milliseconds between Unix epoch and `timeStamp`. If field is empty or null, returns null
7273
*/
7374
public Long getTimeStampAsMillis() {
7475
if (BasicUtils.isEmpty(timeStamp)) {
7576
return null;
7677
}
77-
return (timeStamp.charAt(0) == '0' && timeStamp.charAt(1) == 'x')
78+
long tsSecs = (timeStamp.charAt(0) == '0' && timeStamp.charAt(1) == 'x')
7879
? BasicUtils.parseHex(timeStamp).longValue()
79-
: Long.parseLong(timeStamp) * 1000;
80+
: Long.parseLong(timeStamp);
81+
return tsSecs * 1000;
8082
}
8183

8284
public String getData() {

0 commit comments

Comments
 (0)