Subject: bug#79296: 30.2; format-time-string returns wrongly encoded string in MS Windows Japanese with cp65001 beta config

From: Shingo Tanaka <[email-masked]>
Date: Sun, 24 Aug 2025 11:16:05 +0900

MS Windows has a utf-8 configuration with setting "Beta: Use Unicode UTF-8 for
worldwide language support" to on in its language settings.  In Japanese
environment, system coding is cp932 (MS version of Japanese SJIS) without the
setting but becomes cp65001 (utf-8) with the setting on.

Emacs looks like successfully detecting the change because locale-coding-system
gets from cp932 to cp65001 as expected, and working as expected overall.

However, I found a bug that format-time-string returns a day of the week string
encoded wrongly - with cp932 even in locale-coding-system is cp65001.

Conditions:
- Windows 11 Pro 24H2 with Japanese setting and "Beta: Use Unicode UTF-8
  for worldwide language support" on
- Emacs 30.2 (latest, https://ftp.gnu.org/gnu/emacs/windows/emacs-30/)

Here is how to reproduce.
1. Run Emacs with no-init-file
2. Go to *scratch* buffer and evaluate:
   (format-time-string "%y,%d,%m %A" (date-to-time (concat "2025,1,Jan")))
3. You will get below wrongly encoded string:
   "25,01,01 \220\205\227j\223\372"
4. evaluate:
   (decode-coding-string
    (format-time-string "%y,%d,%m %A" (date-to-time (concat "2025,1,Jan")))
    'cp932)
5. You will get below correctly decoded string:
   #("25,01,01 水曜日" 9 12 (charset cp932-2-byte))

This issue doesn't happen when "Beta: Use Unicode UTF-8 for worldwide language
support" off (locale-coding-system is cp932).

If you have any question or need further information, please let me know.

Regards,
Shingo