forked from Minecraft/minecraft_manager
30 lines
696 B
Python
30 lines
696 B
Python
|
from enum import Enum
|
||
|
from datetime import datetime
|
||
|
from typing import Union
|
||
|
|
||
|
|
||
|
class TimestampStyle(Enum):
|
||
|
SHORT_TIME = "t"
|
||
|
"""16:20"""
|
||
|
LONG_TIME = "T"
|
||
|
"""16:20:30"""
|
||
|
SHORT_DATE = "d"
|
||
|
"""20/04/2021"""
|
||
|
LONG_DATE = "D"
|
||
|
"""20 April 2021"""
|
||
|
SHORT_DATETIME = "f"
|
||
|
"""20 April 2021 16:20"""
|
||
|
LONG_DATETIME = "F"
|
||
|
"""Tuesday, 20 April 2021 16:20"""
|
||
|
RELATIVE = "R"
|
||
|
"""2 months ago"""
|
||
|
|
||
|
|
||
|
def format_timestamp(unix: Union[int, datetime], style: TimestampStyle = TimestampStyle.SHORT_DATETIME) -> str:
|
||
|
t = 0
|
||
|
if isinstance(unix, int):
|
||
|
t = unix
|
||
|
elif isinstance(unix, datetime):
|
||
|
t = unix.timestamp()
|
||
|
return f"<t:{t}:{style}>"
|