Skip to content

Instantly share code, notes, and snippets.

@hwayne

hwayne/Timezone.ahk

Created May 31, 2021
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@hwayne 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