From 16add7fe79c40898b7e89aee0af8be99e785e864 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Sun, 6 Dec 2020 11:47:03 +0700 Subject: [PATCH] Normalize strftime output in case of unsupported directive. Makes output on glibc and musl the same. --- pythainlp/util/strftime.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pythainlp/util/strftime.py b/pythainlp/util/strftime.py index 63a86ee35..bb2481e65 100644 --- a/pythainlp/util/strftime.py +++ b/pythainlp/util/strftime.py @@ -32,11 +32,10 @@ def _std_strftime(dt_obj: datetime, fmt_char: str) -> str: str_ = "" try: str_ = dt_obj.strftime(f"%{fmt_char}") - if str_ == f"%{fmt_char}": + if not str_ or str_ == "%{}".format(fmt_char): # normalize outputs for unsupported directives # in different platforms - # unsupported "%Q" in platform A may return "Q" - # unsupported "%Q" in platform A may return "%Q" + # "%Q" may result "%Q", "Q", or "", make it "Q" str_ = fmt_char except ValueError as err: # Unsupported directives may raise ValueError on Windows,