Skip to content

Instantly share code, notes, and snippets.

@mogproject
Created September 27, 2021 00:06
Show Gist options
  • Save mogproject/b75a00ac4dff9c1451c31b077ff0bae1 to your computer and use it in GitHub Desktop.
Save mogproject/b75a00ac4dff9c1451c31b077ff0bae1 to your computer and use it in GitHub Desktop.
time_convert.py
#!/usr/bin/env python
import sys
import fileinput
import re
diff = -8
def repl(matched):
h = int(matched.group(1)) + diff
prefix = '↩︎ ' if h < 0 else '↪︎ ' if h >= 24 else ''
return f'{prefix}{h % 24:02d}:{matched.group(2)}'
for line in fileinput.input():
sys.stdout.write(re.sub(r'(\d+):(\d\d[^\d])', repl, line))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment