Skip to content

Commit

Permalink
Maintenance: make time conversion script platform-independent (#373)
Browse files Browse the repository at this point in the history
SidestreamColdMelon authored Dec 12, 2023
1 parent 3d6ad2b commit 7400e91
Showing 3 changed files with 27 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ diff-archive-spell :; ./scripts/diff-archive-dssspell.sh "$(if $(date),$(date)
feed :; ./scripts/check-oracle-feed.sh $(pip)
feed-lp :; ./scripts/check-oracle-feed-lp.sh $(pip)
wards :; ./scripts/wards.sh $(target)
time :; ./scripts/time.sh date="$(date)" stamp="$(stamp)"
time :; ./scripts/time.py date="$(date)" stamp="$(stamp)"
exec-hash :; ./scripts/hash-exec-copy.sh "$(if $(date),$(date),$(shell date +'%Y-%m-%d'))"
opt-cost :; ./scripts/get-opt-relay-cost.sh $(spell)
arb-cost :; ./scripts/get-arb-relay-cost.sh $(spell)
26 changes: 26 additions & 0 deletions scripts/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /usr/bin/env python3

import argparse
from datetime import datetime, timezone

DATE_FORMAT="%Y-%m-%d %H:%M:%S";

# Parse positional arguments
parser=argparse.ArgumentParser()
parser.add_argument("date", help="Converts date to UTC timestamp")
parser.add_argument("stamp", help="Converts timestamp to UTC date")
parsed=parser.parse_args()

# Cleanup positional arguments
date = parsed.date.replace("date=", "").upper().replace(" UTC", "")
stamp = parsed.stamp.replace("stamp=", "")

# Convert provided input in UTC format into desired output in UTC as well
if date:
utc_date = datetime.fromisoformat(date).replace(tzinfo=timezone.utc)
print(utc_date)
print(int(utc_date.timestamp()))
if stamp:
utc_date = datetime.fromtimestamp(int(stamp), timezone.utc)
print(utc_date)
print(utc_date.strftime(DATE_FORMAT))
30 changes: 0 additions & 30 deletions scripts/time.sh

This file was deleted.

0 comments on commit 7400e91

Please sign in to comment.