-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintenance: make time conversion script platform-independent (#373)
1 parent
3d6ad2b
commit 7400e91
Showing
3 changed files
with
27 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file was deleted.
Oops, something went wrong.