Bug #19106
closedTime - Hour 24 with tzinfo to_s bug
Description
There appears to be a bug when using Time with tzinfo and setting hour to 24. I contacted tzinfo on github where a repository contributor investigated and thought it was an issue with the Time module and not tzinfo. This person had some insight: https://github.com/tzinfo/tzinfo/issues/142
require 'time'
require 'tzinfo'
# Time without tzinfo
puts Time.new(2022, 11, 6, 24, 0, 0)
# => 2022-11-07 00:00:00 -0600
puts Time.new(2022, 11, 6, 24, 0, 0).strftime("%Y-%m-%d %H:%M:%S %z")
# => 2022-11-07 00:00:00 -0600
# Time with tzinfo
tz = TZInfo::Timezone.get("America/Chicago")
puts Time.new(2022, 11, 6, 24, 0, 0, tzinfo=tz)
# => 2022-11-06 23:00:00 -0600 <== bug, off by one hour
puts Time.new(2022, 11, 6, 24, 0, 0, tzinfo=tz).strftime("%Y-%m-%d %H:%M:%S %z")
# => 2022-11-07 00:00:00 -0600
I expect all the string outputs above should match (first two depends on your system timezone). The inconsistent issue appears to happen when using Time with hour = 24 and with tzinfo set and implied calling to_s versus strftime. Time addition appears to produce the correct result.
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]
tzinfo (2.0.5, 2.0.4)
tzinfo-data (1.2022.1)
Updated by nobu (Nobuyoshi Nakada) about 2 years ago
- Related to Bug #18922: Time at 24:00:00 UTC is not normalized added
Updated by nobu (Nobuyoshi Nakada) about 2 years ago
Updated by nobu (Nobuyoshi Nakada) about 2 years ago
- Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED
Updated by nobu (Nobuyoshi Nakada) about 2 years ago
- Status changed from Open to Closed
Applied in changeset git|011d4c57d21220249600dfb76db84840550da019.
[Bug #19106] Normalize time at 24:00:00 with a timezone object
Updated by nagachika (Tomoyuki Chikanaga) about 2 years ago
- Backport changed from 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE
ruby_3_1 728d9f18348bcffedb0880c67015f08a7c19665f merged revision(s) 011d4c57d21220249600dfb76db84840550da019.