fix issue #297: UnicodeEncodeError in date formatting for non-Chinese locale systems (issu #299
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes issue #297
Problem:
Running the application on systems with non-Chinese locales causes a UnicodeEncodeError during import. The application crashes immediately on startup before any functionality can be used. The strftime() function uses the system's locale encoding to process the format string. On systems without Chinese locale support (e.g., cp1252 on German Windows), the characters 年, 月, 日 cannot be encoded.
Error Message:
File "...\phone_agent\config\prompts_zh.py", line 8, in <module> formatted_date = today.strftime("%Y年%m月%d日") + " " + weekday ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: encoding errorFix:
Replaced strftime() with f-string formatting to avoid locale-dependent encoding
Changes:
old:
formatted_date = today.strftime("%Y年%m月%d日") + " " + weekday.
.
.
new:
formatted_date = f"{today.year}年{today.month:02d}月{today.day:02d}日 {weekday}"