🐙
[bugs.ruby][Bug #20327] 不正な Time#utc_offset を返すバグ報告
[Bug #20327] Time.new behaves differently when passing a zone as timezone object
-
Time.new
に秒を Rational、タイムゾーンにタイムゾーンオブジェクトを渡すと不正なutc_offset
を返すというバグ報告
require "tzinfo"
# 以下は正しい値が返ってくる
puts Time.new(2024, 1, 1, 23, 59, 59.9r, "UTC").utc_offset
# => 0
puts Time.new(2024, 1, 1, 23, 59, 59.9r, "UTC").inspect
# => "2024-01-01 23:59:59.9 UTC"
# タイムゾーンオブジェクトを渡すと意図しない値が返ってくる
puts Time.new(2024, 1, 1, 23, 59, 59.9r, TZInfo::Timezone.get("Etc/UTC")).utc_offset
# => (9/10)
puts Time.new(2024, 1, 1, 23, 59, 59.9r, TZInfo::Timezone.get("Etc/UTC")).inspect
# => "2024-01-01 23:59:59.9 +000001"
- この問題は開発版の Ruby 3.4 で修正済みです
Discussion