refactor: discord_timestamp delegates to discord.utils.format_dt
T3-21: the hand-rolled <t:unix:style> markup duplicated discord.py's format_dt. style validation stays (dpy_commons' ValueError contract). output is byte-identical for all 7 styles across naive (incl. DST fold/gap), aware, pre-epoch and sub-second datetimes in three timezones. Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
1 parent
4c1244de88
commit
67f9995152
1 file changed
+3
-3
@@ -7,6 +7,8 @@ import re
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional, Sequence
|
from typing import Optional, Sequence
|
||||||
|
|
||||||
|
from discord.utils import format_dt
|
||||||
|
|
||||||
from .limits import MSG_LIMIT
|
from .limits import MSG_LIMIT
|
||||||
|
|
||||||
_ELLIPSIS = "…"
|
_ELLIPSIS = "…"
|
||||||
@@ -108,9 +110,7 @@ def discord_timestamp(dt: datetime, style: str = "f") -> str:
|
|||||||
aware dt if the source is UTC; raises ValueError on an invalid style (one of t/T/d/D/f/F/R)"""
|
aware dt if the source is UTC; raises ValueError on an invalid style (one of t/T/d/D/f/F/R)"""
|
||||||
if style not in _TIMESTAMP_STYLES:
|
if style not in _TIMESTAMP_STYLES:
|
||||||
raise ValueError(f"invalid timestamp style '{style}'; expected one of {_TIMESTAMP_STYLES}")
|
raise ValueError(f"invalid timestamp style '{style}'; expected one of {_TIMESTAMP_STYLES}")
|
||||||
if dt.tzinfo is None:
|
return format_dt(dt, style)
|
||||||
dt = dt.astimezone()
|
|
||||||
return f"<t:{int(dt.timestamp())}:{style}>"
|
|
||||||
|
|
||||||
|
|
||||||
def humanize_delta(seconds: float) -> str:
|
def humanize_delta(seconds: float) -> str:
|
||||||
|
|||||||
Reference in new issue
Block a user