Skip to content

Commit 92f529e

Browse files
authored
Merge pull request #48 from wimglenn/v0.9.7
make blocker datefmt work on windows
2 parents 097cfff + c19c3fb commit 92f529e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

aocd/utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _ensure_intermediate_dirs(fname):
2323
raise
2424

2525

26-
def blocker(quiet=False, dt=0.1, datefmt="%-I:%M %p", until=None):
26+
def blocker(quiet=False, dt=0.1, datefmt=None, until=None):
2727
"""
2828
This function just blocks until the next puzzle unlocks.
2929
Pass `quiet=True` to disable the spinner etc.
@@ -48,13 +48,18 @@ def blocker(quiet=False, dt=0.1, datefmt="%-I:%M %p", until=None):
4848
return
4949
spinner = cycle(r"\|/-")
5050
localzone = tzlocal.get_localzone()
51+
local_unlock = unlock.astimezone(tz=localzone)
52+
if datefmt is None:
53+
# %-I does not work on Windows, strip leading zeros manually
54+
local_unlock = local_unlock.strftime("%I:%M %p").lstrip("0")
55+
else:
56+
local_unlock = local_unlock.strftime(datefmt)
57+
msg = "{} Unlock day %s at %s ({} remaining)" % (unlock.day, local_unlock)
5158
while datetime.now(tz=AOC_TZ) < unlock:
52-
local_unlock = unlock.astimezone(tz=localzone)
53-
msg = "{} Unlock day {} at {:%s} ({} remaining)" % datefmt
5459
remaining = unlock - datetime.now(tz=AOC_TZ)
5560
remaining = str(remaining).split(".")[0] # trim microseconds
5661
if not quiet:
57-
sys.stdout.write(msg.format(next(spinner), unlock.day, local_unlock, remaining))
62+
sys.stdout.write(msg.format(next(spinner), remaining))
5863
sys.stdout.flush()
5964
time.sleep(dt)
6065
if not quiet:

aocd/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.9.6"
1+
__version__ = "0.9.7"

0 commit comments

Comments
 (0)