Created
May 31, 2021 01:41
-
-
Save hwayne/61dacc2d66dac20cfb0ef7bb9bab7498 to your computer and use it in GitHub Desktop.
Timezone message box
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
""" | |
Using %#I comes from https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?view=msvc-160 | |
see also https://dateutil.readthedocs.io/en/stable/tz.html | |
""" | |
import click | |
from dateutil.parser import parse | |
from dateutil.tz import gettz, tzlocal, UTC | |
# TODO: load this from a fixture | |
tzinfos = { | |
"CST": gettz("America/Chicago"), | |
"EST": gettz("America/New_York"), | |
"PST": gettz("America/Los_Angeles"), | |
"PDT": gettz("America/Los_Angeles"), | |
"CEST": gettz("Europe/Berlin") | |
} | |
@click.command() | |
@click.option('--date') | |
# TODO add option for inputting a target timezone | |
# Shouldn't hardcode CST and UTC, at least it's just a prototype | |
def timeshim(date): | |
out = parse(date, tzinfos=tzinfos, fuzzy=True) | |
cst = out.astimezone(tzinfos["CST"]) | |
utc = out.astimezone(UTC) | |
fmt = "%#I:%M %p %Z" # h:mm PM Timezone | |
print(utc.strftime(fmt)) | |
print(cst.strftime(fmt)) | |
if __name__ == "__main__": | |
timeshim() |
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
get_timezone() { | |
clipboard := "" | |
Send ^c | |
ClipWait, 2 | |
timeshim := A_WorkingDir . "\Lib\Aux-Scripts\timeshim.py" ; TODO use A_ScriptDir somehow | |
cliptime := clipboard | |
cmd := "pythonw.exe " . timeshim . " --date=""" . cliptime . """ | clip" | |
runwait, %ComSpec% /c "%cmd%", ,Hide | |
out := clipboard | |
return out | |
} | |
#`:: ; todo make this into a mode somehow | |
get_timezone() | |
timestr := clipboard | |
MsgBox %timestr% | |
SetTimer, RemoveToolTip, -700 | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example runs