ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:120089] [Ruby master Bug#20929] TestTime have an assertion different from current implementation.
@ 2024-12-03 15:33 YO4 (Yoshinao Muramatsu) via ruby-core
  2024-12-04  7:16 ` [ruby-core:120100] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: YO4 (Yoshinao Muramatsu) via ruby-core @ 2024-12-03 15:33 UTC (permalink / raw)
  To: ruby-core; +Cc: YO4 (Yoshinao Muramatsu)

Issue #20929 has been reported by YO4 (Yoshinao Muramatsu).

----------------------------------------
Bug #20929: TestTime have an assertion different from current implementation.
https://bugs.ruby-lang.org/issues/20929

* 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.
```
  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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:120100] [Ruby master Bug#20929] TestTime have an assertion different from current implementation.
  2024-12-03 15:33 [ruby-core:120089] [Ruby master Bug#20929] TestTime have an assertion different from current implementation YO4 (Yoshinao Muramatsu) via ruby-core
@ 2024-12-04  7:16 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-12-05  9:25 ` [ruby-core:120111] " usa (Usaku NAKAMURA) via ruby-core
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-12-04  7:16 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

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"
#<Encoding:Windows-31J>
"\x{938C}\x{8B9E} (\x{9557}\x{8F80}\x{8E9E})"
#<Encoding:Windows-31J>
```

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"
#<Encoding:IBM437>
"\x93\x8C\x8B\x9E (\x95W\x8F\x80\x8E\x9E)"
#<Encoding:IBM437>
```

And of course regardless the internal encoding.

```
> ruby -Ecp932 -e "p Encoding.find('locale'), (z = Time.now.zone), z.encoding"
#<Encoding:IBM437>
"\x93\x8C\x8B\x9E (\x95W\x8F\x80\x8E\x9E)"
#<Encoding:IBM437>
```

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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:120111] [Ruby master Bug#20929] TestTime have an assertion different from current implementation.
  2024-12-03 15:33 [ruby-core:120089] [Ruby master Bug#20929] TestTime have an assertion different from current implementation YO4 (Yoshinao Muramatsu) via ruby-core
  2024-12-04  7:16 ` [ruby-core:120100] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-12-05  9:25 ` usa (Usaku NAKAMURA) via ruby-core
  2024-12-06 10:19 ` [ruby-core:120117] " YO4 (Yoshinao Muramatsu) via ruby-core
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: usa (Usaku NAKAMURA) via ruby-core @ 2024-12-05  9:25 UTC (permalink / raw)
  To: ruby-core; +Cc: usa (Usaku NAKAMURA)

Issue #20929 has been updated by usa (Usaku NAKAMURA).


> Maybe we should use the W API and encode it in UTF-8 ranter than the locale.

agreed.

----------------------------------------
Bug #20929: TestTime have an assertion different from current implementation.
https://bugs.ruby-lang.org/issues/20929#change-110859

* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:120117] [Ruby master Bug#20929] TestTime have an assertion different from current implementation.
  2024-12-03 15:33 [ruby-core:120089] [Ruby master Bug#20929] TestTime have an assertion different from current implementation YO4 (Yoshinao Muramatsu) via ruby-core
  2024-12-04  7:16 ` [ruby-core:120100] " nobu (Nobuyoshi Nakada) via ruby-core
  2024-12-05  9:25 ` [ruby-core:120111] " usa (Usaku NAKAMURA) via ruby-core
@ 2024-12-06 10:19 ` YO4 (Yoshinao Muramatsu) via ruby-core
  2024-12-20 10:42 ` [ruby-core:120345] " YO4 (Yoshinao Muramatsu) via ruby-core
  2024-12-24  4:03 ` [ruby-core:120386] " nobu (Nobuyoshi Nakada) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: YO4 (Yoshinao Muramatsu) via ruby-core @ 2024-12-06 10:19 UTC (permalink / raw)
  To: ruby-core; +Cc: YO4 (Yoshinao Muramatsu)

Issue #20929 has been updated by YO4 (Yoshinao Muramatsu).


Thank you for your response.

Regarding Time#zone encoding, I am experimenting with it in my branch https://github.com/YO4/ruby/tree/tzname_utf8.
I found this issue in my research for that.

At present, the change to utf-8 causes the following error.
```
>ruby -e 'puts "タイムゾーン:#{Time.now.zone}"'
-e:1:in '<main>': incompatible character encodings: Windows-31J and UTF-8 (Encoding::CompatibilityError)
```
To resolve this, other strings must also be in UTF-8 encoding.
I think it would be preferred that strings with Unicode code ranges also have UTF-8 encoding. OS-derived strings, excluding I/O content, seem to meet that requirement.

Of course, this matter should be discussed in another issue.
Thanks.

----------------------------------------
Bug #20929: TestTime have an assertion different from current implementation.
https://bugs.ruby-lang.org/issues/20929#change-110869

* Author: YO4 (Yoshinao Muramatsu)
* Status: Closed
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:120345] [Ruby master Bug#20929] TestTime have an assertion different from current implementation.
  2024-12-03 15:33 [ruby-core:120089] [Ruby master Bug#20929] TestTime have an assertion different from current implementation YO4 (Yoshinao Muramatsu) via ruby-core
                   ` (2 preceding siblings ...)
  2024-12-06 10:19 ` [ruby-core:120117] " YO4 (Yoshinao Muramatsu) via ruby-core
@ 2024-12-20 10:42 ` YO4 (Yoshinao Muramatsu) via ruby-core
  2024-12-24  4:03 ` [ruby-core:120386] " nobu (Nobuyoshi Nakada) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: YO4 (Yoshinao Muramatsu) via ruby-core @ 2024-12-20 10:42 UTC (permalink / raw)
  To: ruby-core; +Cc: YO4 (Yoshinao Muramatsu)

Issue #20929 has been updated by YO4 (Yoshinao Muramatsu).


We have changed Time#zone encoding test code to not consider internal_encoding at 78762b5,
but a document of Encoding.default_internal explicitly stated that Time#zone was affected by it.
Do we need to reconsider?

Github PR#12409 is the change for Time#zone to respect Encoding.default_internal.

[78762b5](https://github.com/ruby/ruby/commit/78762b52185aa80ee55c0d49b495aceed863dce2)
[Document(3.3)](https://docs.ruby-lang.org/en/3.3/Encoding.html#method-c-default_internal)
[Document(master)](https://docs.ruby-lang.org/en/master/Encoding.html#method-c-default_internal)
[Github PR#12409](https://github.com/ruby/ruby/pull/12409)

----------------------------------------
Bug #20929: TestTime have an assertion different from current implementation.
https://bugs.ruby-lang.org/issues/20929#change-111119

* Author: YO4 (Yoshinao Muramatsu)
* Status: Closed
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:120386] [Ruby master Bug#20929] TestTime have an assertion different from current implementation.
  2024-12-03 15:33 [ruby-core:120089] [Ruby master Bug#20929] TestTime have an assertion different from current implementation YO4 (Yoshinao Muramatsu) via ruby-core
                   ` (3 preceding siblings ...)
  2024-12-20 10:42 ` [ruby-core:120345] " YO4 (Yoshinao Muramatsu) via ruby-core
@ 2024-12-24  4:03 ` nobu (Nobuyoshi Nakada) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-12-24  4:03 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20929 has been updated by nobu (Nobuyoshi Nakada).


We defer this change after 3.4 release.
https://github.com/ruby/ruby/pull/12448

----------------------------------------
Bug #20929: TestTime have an assertion different from current implementation.
https://bugs.ruby-lang.org/issues/20929#change-111165

* Author: YO4 (Yoshinao Muramatsu)
* Status: Closed
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-12-24  4:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-03 15:33 [ruby-core:120089] [Ruby master Bug#20929] TestTime have an assertion different from current implementation YO4 (Yoshinao Muramatsu) via ruby-core
2024-12-04  7:16 ` [ruby-core:120100] " nobu (Nobuyoshi Nakada) via ruby-core
2024-12-05  9:25 ` [ruby-core:120111] " usa (Usaku NAKAMURA) via ruby-core
2024-12-06 10:19 ` [ruby-core:120117] " YO4 (Yoshinao Muramatsu) via ruby-core
2024-12-20 10:42 ` [ruby-core:120345] " YO4 (Yoshinao Muramatsu) via ruby-core
2024-12-24  4:03 ` [ruby-core:120386] " nobu (Nobuyoshi Nakada) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).