Skip to content

Commit 4285309

Browse files
authored
Normalize strftime output in case of unsupported directive. Makes output on glibc and musl the same. (#490)
1 parent df5e5ae commit 4285309

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

pythainlp/util/strftime.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ def _std_strftime(dt_obj: datetime, fmt_char: str) -> str:
3232
str_ = ""
3333
try:
3434
str_ = dt_obj.strftime(f"%{fmt_char}")
35-
if str_ == f"%{fmt_char}":
35+
if not str_ or str_ == "%{}".format(fmt_char):
3636
# normalize outputs for unsupported directives
3737
# in different platforms
38-
# unsupported "%Q" in platform A may return "Q"
39-
# unsupported "%Q" in platform A may return "%Q"
38+
# "%Q" may result "%Q", "Q", or "", make it "Q"
4039
str_ = fmt_char
4140
except ValueError as err:
4241
# Unsupported directives may raise ValueError on Windows,

0 commit comments

Comments
 (0)