From: "nobu (Nobuyoshi Nakada) via ruby-core" Date: 2024-12-04T07:16:59+00:00 Subject: [ruby-core:120100] [Ruby master Bug#20929] TestTime have an assertion different from current implementation. Issue #20929 has been updated by nobu (Nobuyoshi Nakada). Description updated Indeed, that assertion is incorrect. But the locale is not the correct/expected encoding always on Windows. For instance, in Japanese edition, `tm_zone` is always CP932. ``` > chcp.com 932 ������������������ ���������: 932 > ruby -e "p Encoding.find('locale'), (z = Time.now.zone), z.encoding" # "\x{938C}\x{8B9E} (\x{9557}\x{8F80}\x{8E9E})" # ``` Even when locale (active codepage) is changed. ``` > chcp.com 437 Active code page: 437 > ruby -e "p Encoding.find('locale'), (z = Time.now.zone), z.encoding" # "\x93\x8C\x8B\x9E (\x95W\x8F\x80\x8E\x9E)" # ``` And of course regardless the internal encoding. ``` > ruby -Ecp932 -e "p Encoding.find('locale'), (z = Time.now.zone), z.encoding" # "\x93\x8C\x8B\x9E (\x95W\x8F\x80\x8E\x9E)" # ``` I don't think there is the API to obtain what codepage it is encoded. Maybe we should use the W API and encode it in UTF-8 ranter than the locale. @usa, what do you think? ---------------------------------------- Bug #20929: TestTime have an assertion different from current implementation. https://bugs.ruby-lang.org/issues/20929#change-110847 * Author: YO4 (Yoshinao Muramatsu) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- test/ruby/test_time.rb have following assersion function. ```ruby def assert_zone_encoding(time) zone = time.zone assert_predicate(zone, :valid_encoding?) if zone.ascii_only? assert_equal(Encoding::US_ASCII, zone.encoding) else enc = Encoding.default_internal || Encoding.find('locale') assert_equal(enc, zone.encoding) end end ``` In current implementation, Time#zone are returned in US_ASCII or locale encoding, which does not seem to take into account the default_internal. ``` C:\>ruby -e "puts Time.now.zone" ������ (���������) C:\>ruby -e "puts Time.now.zone.encoding" Windows-31J C:\>ruby -EWindows-31J:UTF-8 -e "puts Time.now.zone" ������ (���������) C:\>ruby -EWindows-31J:UTF-8 -e "puts Time.now.zone.encoding" Windows-31J ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/