From: "ruby-gregor (Greg Lindstrom)" Date: 2022-11-05T20:05:49+00:00 Subject: [ruby-core:110627] [Ruby master Bug#19106] Time - Hour 24 with tzinfo to_s bug Issue #19106 has been reported by ruby-gregor (Greg Lindstrom). ---------------------------------------- Bug #19106: Time - Hour 24 with tzinfo to_s bug https://bugs.ruby-lang.org/issues/19106 * Author: ruby-gregor (Greg Lindstrom) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- 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 ```ruby 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) -- https://bugs.ruby-lang.org/ Unsubscribe: