Bug #8885

Incorrect time is created for time including leap seconds

Added by Tsuyoshi Sawada 8 months ago. Updated 7 months ago.

[ruby-core:57102]
Status:Rejected
Priority:Normal
Assignee:-
Category:-
Target version:-
ruby -v:2.0 Backport:1.9.3: UNKNOWN, 2.0.0: UNKNOWN

Description

=begin
Time.new creates incorrect time when the time includes a leap second.

Time.new(2012, 6, 30, 23, 59, 60)
# => 2012-07-01 00:00:00 +0900 # Wrong. Should be 2012-06-30 23:59:60 +0900

Time.new(2012, 6, 30, 23, 59, 60) == Time.new(2012, 7, 1, 0, 0, 0)
# => true # Wrong. Should be `false`.

=end

History

#1 Updated by Nobuhiro IMAI 7 months ago

=begin
Which is your timezone? I guess it works correctly.

RUBYDESCRIPTION # => "ruby 2.0.0p247 (2013-06-27 revision 41674) [x8664-linux]"
ENV["TZ"] = "UTC"
Time.new(2012, 6, 30, 23, 59, 60) # => 2012-07-01 00:00:00 +0000
ENV["TZ"] = "right/UTC"
Time.new(2012, 6, 30, 23, 59, 60) # => 2012-06-30 23:59:60 +0000
ENV["TZ"] = "Japan"
Time.new(2012, 6, 30, 23, 59, 60) # => 2012-07-01 00:00:00 +0900
Time.new(2012, 7, 1, 8, 59, 60) # => 2012-07-01 09:00:00 +0900
ENV["TZ"] = "right/Japan"
Time.new(2012, 6, 30, 23, 59, 60) # => 2012-07-01 00:00:00 +0900
Time.new(2012, 7, 1, 8, 59, 60) # => 2012-07-01 08:59:60 +0900
=end

#2 Updated by Akira Tanaka 7 months ago

2013/9/10 sawa (Tsuyoshi Sawada) sawadatsuyoshi@gmail.com:

Bug #8885: Incorrect time is created for time including leap seconds
https://bugs.ruby-lang.org/issues/8885

ruby -v: 2.0

Time.new creates incorrect time when the time includes a leap second.

Time.new(2012, 6, 30, 23, 59, 60)
# => 2012-07-01 00:00:00 +0900 # Wrong. Should be 2012-06-30 23:59:60 +0900

Time.new(2012, 6, 30, 23, 59, 60) == Time.new(2012, 7, 1, 0, 0, 0)
# => true # Wrong. Should be `false`.

At first, please confirm your enviroment (OS and configuration)
supports leap seconds.
Ruby supports leap seconds only if your environment supports leap seconds.

What is your OS?
The command line, ruby -v, shows the ruby version including your OS.
But you didn't fill the entry of the form as the result of the command line.
("2.0" is not a proper result of ruby -v.)
Example:
% ruby -v
ruby 2.1.0dev (2013-08-16 trunk 42586) [x86_64-linux]

What is the value of TZ environment variable?
Some (Unix) environment sees TZ environment variable to determine to
support leap seconds or not.
(The value prefixed with "right/" may indicate leap seconds support.)

What the result of the following command?
% ruby -e '3.times {|i| p Time.at(78796799+i) }'

The command shows Time class behavior around the first leap second,
1972-06-30T23:59:60Z.

Environment which supports leap seconds:
% TZ=right/UTC ruby -e '3.times {|i| p Time.at(78796799+i) }'
1972-06-30 23:59:59 +0000
1972-06-30 23:59:60 +0000
1972-07-01 00:00:00 +0000

Environment which doesn't support leap seconds:
% TZ=UTC ruby -e '3.times {|i| p Time.at(78796799+i) }'
1972-06-30 23:59:59 +0000
1972-07-01 00:00:00 +0000
1972-07-01 00:00:01 +0000
--
Tanaka Akira

#3 Updated by Tsuyoshi Sawada 7 months ago

The Ruby version is ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]. I didn't have the timezone set to one that supports leap second. Once I attached "right/", it worked. Thank you for the help. I would like to withdraw this issue.

#4 Updated by Kazuhiro NISHIYAMA 7 months ago

  • Status changed from Open to Rejected

Also available in: Atom PDF