Project

General

Profile

Actions

Bug #8885

closed

Incorrect time is created for time including leap seconds

Added by sawa (Tsuyoshi Sawada) over 10 years ago. Updated over 10 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
2.0
[ruby-core:57102]

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

Updated by no6v (Nobuhiro IMAI) over 10 years ago

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

RUBY_DESCRIPTION # => "ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-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

Updated by akr (Akira Tanaka) over 10 years ago

2013/9/10 sawa (Tsuyoshi Sawada) :

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

Updated by sawa (Tsuyoshi Sawada) over 10 years 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.

Updated by znz (Kazuhiro NISHIYAMA) over 10 years ago

  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0