Last active
December 10, 2022 17:37
-
-
Save LamberKeep/8d004d62d0fe67ed6eedea81c2c35f54 to your computer and use it in GitHub Desktop.
Time to an emoji clock symbol conventer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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