Skip to content

Commit

Permalink
Merge pull request #77 from cowprotocol/use_utc_timezone
Browse files Browse the repository at this point in the history
Use utc timezone
  • Loading branch information
harisang authored Oct 14, 2024
2 parents eab8179 + e042d06 commit 7dd2e55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/helpers/database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from hexbytes import HexBytes
import psycopg
Expand Down Expand Up @@ -142,7 +142,9 @@ def write_transaction_timestamp(
query,
{
"tx_hash": bytes.fromhex(transaction_timestamp[0][2:]),
"time": datetime.fromtimestamp(transaction_timestamp[1]),
"time": datetime.fromtimestamp(
transaction_timestamp[1], tz=timezone.utc
),
},
)

Expand Down Expand Up @@ -175,7 +177,7 @@ def write_prices_new(self, prices: list[tuple[str, int, float, str]]) -> None:
query,
{
"token_address": bytes.fromhex(token_address[2:]),
"time": datetime.fromtimestamp(time),
"time": datetime.fromtimestamp(time, tz=timezone.utc),
"price": price,
"source": source,
},
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from hexbytes import HexBytes
from sqlalchemy import create_engine, text
Expand Down Expand Up @@ -31,7 +31,7 @@ def tests_write_transaction_timestamp():
"0x" + bytes(res[0]).hex()
== "0xb75e03b63d4f06c56549effd503e1e37f3ccfc3c00e6985a5aacc9b0534d7c5c"
)
assert res[1].timestamp() == 1728044411
assert res[1].replace(tzinfo=timezone.utc).timestamp() == 1728044411


def tests_write_transaction_tokens():
Expand Down

0 comments on commit 7dd2e55

Please sign in to comment.