Skip to content

Instantly share code, notes, and snippets.

@LamberKeep
Last active December 10, 2022 17:37
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 LamberKeep/8d004d62d0fe67ed6eedea81c2c35f54 to your computer and use it in GitHub Desktop.
Save LamberKeep/8d004d62d0fe67ed6eedea81c2c35f54 to your computer and use it in GitHub Desktop.
Time to an emoji clock symbol conventer.
# by LamberKeep @ December 2022
import time
class TimeToEmoji:
def time2emoji(h: int, m: int):
"""Converts the time to an emoji clock symbol.
:param int h: Hours in 24-hour time format.
:param int m: Minutes.
:return: (str) Emoji clock character.
"""
index = h - 1
if h >= 12:
index -= 12
if index == -1:
index += 12
if m >= 30:
index += 12
return chr(int("1F550", 16) + index)
def timestamp2emoji(self: int):
"""Convert timestamp to emoji clock symbol with :func:`time2emoji<TimeToEmoji.time2emoji>`.
:param int self: Timestamp.
:return: (str) Emoji clock character.
"""
datetime = time.localtime(self)
return TimeToEmoji.time2emoji(datetime[3], datetime[4])
if __name__ == "__main__":
# From localtime
print(TimeToEmoji.timestamp2emoji(1)) # 🕝
# From timestamp
print(TimeToEmoji.timestamp2emoji(int(time.time())))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment