Skip to content

Instantly share code, notes, and snippets.

@hwayne
Created May 31, 2021 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hwayne/61dacc2d66dac20cfb0ef7bb9bab7498 to your computer and use it in GitHub Desktop.
Save hwayne/61dacc2d66dac20cfb0ef7bb9bab7498 to your computer and use it in GitHub Desktop.
Timezone message box
"""
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()
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
@hwayne
Copy link
Author

hwayne commented May 31, 2021

Example runs

6 PM CEST

14:30 GMT+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment