Project

General

Profile

Actions

Bug #19106

closed

Time - Hour 24 with tzinfo to_s bug

Added by ruby-gregor (Greg Lindstrom) about 2 years ago. Updated about 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]
[ruby-core:110627]

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)


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #18922: Time at 24:00:00 UTC is not normalizedClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0