Skip to content

Instantly share code, notes, and snippets.

@edavis
Last active August 29, 2015 14:04
Show Gist options
  • Save edavis/5003fe57aeb7288e3457 to your computer and use it in GitHub Desktop.
Save edavis/5003fe57aeb7288e3457 to your computer and use it in GitHub Desktop.
Display a UTC timestamp lookup table to quickly translate UTC timestamps to your local timezone.
#!/usr/bin/env python
"""
Display a UTC timestamp lookup table to quickly translate UTC
timestamps to your local timezone.
Displays the value of the local timestamp in both 12 and 24-hour
formats along with an asterisk next to the current hour.
arrow <http://crsmithdev.com/arrow/> must be present to run.
Example:
$ ~/bin/utc
+---------------+---------------+------------------+
| UTC | Local | Local (12h) |
+---------------+---------------+------------------+
| 00:00 (08/06) | 17:00 (08/05) | 05:00 PM (08/05) |
| 01:00 (08/06) | 18:00 (08/05) | 06:00 PM (08/05) |
| 02:00 (08/06) | 19:00 (08/05) | 07:00 PM (08/05) |
| 03:00 (08/06) | 20:00 (08/05) | 08:00 PM (08/05) |
| 04:00 (08/06) | 21:00 (08/05) | 09:00 PM (08/05) |
| 05:00 (08/06) | 22:00 (08/05) | 10:00 PM (08/05) |
| 06:00 (08/06) | 23:00 (08/05) | 11:00 PM (08/05) |
| 07:00 (08/06) | 00:00 (08/06) | 12:00 AM (08/06) |
| 08:00 (08/06) | 01:00 (08/06) | 01:00 AM (08/06) |
| 09:00 (08/06) | 02:00 (08/06) | 02:00 AM (08/06) |
| 10:00 (08/06) | 03:00 (08/06) | 03:00 AM (08/06) |
| 11:00 (08/06) | 04:00 (08/06) | 04:00 AM (08/06) |
| 12:00 (08/06) | 05:00 (08/06) | 05:00 AM (08/06) |
| 13:00 (08/06) | 06:00 (08/06) | 06:00 AM (08/06) |
| 14:00 (08/06) | 07:00 (08/06) | 07:00 AM (08/06) |
| 15:00 (08/06) | 08:00 (08/06) | 08:00 AM (08/06) | *
| 16:00 (08/06) | 09:00 (08/06) | 09:00 AM (08/06) |
| 17:00 (08/06) | 10:00 (08/06) | 10:00 AM (08/06) |
| 18:00 (08/06) | 11:00 (08/06) | 11:00 AM (08/06) |
| 19:00 (08/06) | 12:00 (08/06) | 12:00 PM (08/06) |
| 20:00 (08/06) | 13:00 (08/06) | 01:00 PM (08/06) |
| 21:00 (08/06) | 14:00 (08/06) | 02:00 PM (08/06) |
| 22:00 (08/06) | 15:00 (08/06) | 03:00 PM (08/06) |
| 23:00 (08/06) | 16:00 (08/06) | 04:00 PM (08/06) |
+---------------+---------------+------------------+
"""
import arrow
now = arrow.utcnow()
start = now.floor('day')
end = now.ceil('day')
fmt_24 = 'HH:mm (MM/DD)'
fmt_12 = 'hh:mm A (MM/DD)'
sep = '+%s+%s+%s+' % ('-' * 15, '-' * 15, '-' * 18)
print(sep)
print('| %-13s | %-13s | %-16s |' % ('UTC', 'Local', 'Local (12h)'))
print(sep)
for value, ceiling in arrow.Arrow.span_range('hour', start, end):
local = value.to('local')
params = (
value.format(fmt_24), local.format(fmt_24), local.format(fmt_12),
'*' if value < now < ceiling else '',
)
print('| %s | %s | %s | %s' % params)
print(sep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment