Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: make time conversion script platform-independent #373

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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.