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

Previous Next

Package: emacs;

Reported by: Shingo Tanaka <shingo.fg8 <at> gmail.com>

Date: Sun, 24 Aug 2025 02:17:02 UTC

Severity: normal

Found in version 30.2

Done: Eli Zaretskii <eliz <at> gnu.org>

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#79296: closed (30.2; format-time-string returns wrongly
 encoded string in MS Windows Japanese with cp65001 beta config)
Date: Sat, 30 Aug 2025 09:26:01 +0000
[Message part 1 (text/plain, inline)]
Your message dated Sat, 30 Aug 2025 12:25:09 +0300
with message-id <863499qhze.fsf <at> gnu.org>
and subject line Re: bug#79296: 30.2; format-time-string returns wrongly encoded string in MS Windows Japanese with cp65001 beta config
has caused the debbugs.gnu.org bug report #79296,
regarding 30.2; format-time-string returns wrongly encoded string in MS Windows Japanese with cp65001 beta config
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
79296: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79296
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Shingo Tanaka <shingo.fg8 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.2; format-time-string returns wrongly encoded string in MS Windows
 Japanese with cp65001 beta config
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


[Message part 3 (message/rfc822, inline)]
From: Eli Zaretskii <eliz <at> gnu.org>
To: Shingo Tanaka <shingo.fg8 <at> gmail.com>
Cc: 79296-done <at> debbugs.gnu.org, shingo.fg8 <at> gmail.com, corwin <at> bru.st,
 bruno <at> clisp.org, eggert <at> cs.ucla.edu
Subject: Re: bug#79296: 30.2;
 format-time-string returns wrongly encoded string in MS Windows
 Japanese with cp65001 beta config
Date: Sat, 30 Aug 2025 12:25:09 +0300
> Date: Wed, 27 Aug 2025 22:54:30 +0900
> From: Shingo Tanaka <shingo.fg8 <at> gmail.com>
> Cc: Eli Zaretskii <eliz <at> gnu.org>,
> 	corwin <at> bru.st,
> 	shingo.fg8 <at> gmail.com,
> 	eggert <at> cs.ucla.edu,
> 	79296 <at> debbugs.gnu.org
> 
> On Wed, 27 Aug 2025 18:05:42 +0900,
> Bruno Haible wrote:
> > 
> > For producing such binaries with only Free Software (no MSVC compiler,
> > no MSVC header files) one can use MSYS2. For a year or two already
> > it supports two target environments:
> >   - mingw-w64 with MSVCRT,
> >   - mingw-w64 with UCRT.
> > These two development environments are very similar, which means that
> > the Makefile will need very few adapations.
> 
> I've just installed MSYS2 Emacs of UCRT version and run it with no init file. 
> 
> ~> pacman -S mingw-w64-ucrt-x86_64-emacs
> ~> /ucrt64/bin/runemacs --no-init-file
> 
> And confirmed the issue I reported doesn't happen even with
> "Beta: Use Unicode UTF-8 for worldwide language support" on.
> 
> In *scratch* buffer:
> 
> (format-time-string "%y,%d,%m %A" (date-to-time (concat "2025,1,Jan")))
> "25,01,01 水曜日"
> 
> w32-system-coding-system
> cp65001
> 
> w32-multibyte-code-page
> 0
> 
> w32-ansi-code-page
> 65001
> 
> (w32-get-current-locale-id)
> 1041
> 
> (w32-get-locale-info (w32-get-current-locale-id))
> "JPN"
> 
> (w32-get-default-locale-id)
> 1041
> 
> (w32-get-locale-info (w32-get-default-locale-id))
> "JPN"
> 
> (w32-get-console-codepage)
> 65001
> 
> (w32-get-console-output-codepage)
> 65001

Thanks.  I've now added a new section to the Emacs w32 FAQ about these
issues, and I'm therefore closing this bug.


This bug report was last modified 21 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.