Bug #8173

2-arg form of Time.at can take a Time as either argument

Added by Hiro Asari about 1 year ago. Updated about 1 year ago.

[ruby-core:53764]
Status:Closed
Priority:Normal
Assignee:-
Category:-
Target version:-
ruby -v:ruby 2.1.0dev (2013-03-11 trunk 39724) [x86_64-darwin12.2.1] Backport:

Description

http://www.ruby-doc.org/core-2.0/Time.html#method-c-at shows 3 forms of invocation:

at(time) → time click to toggle source
at(secondswithfrac) → time
at(seconds, microsecondswithfrac) → time

But the last form can take a Time as either argument (and converts to a numeric value represented by the number of seconds since the Epoch). If a Time is used as the second argument, the numeric value is then converted to microseconds to return a Time. (I hope that I'm making sense.)

irb(main):001:0> RUBYDESCRIPTION
=> "ruby 2.1.0dev (2013-03-11 trunk 39724) [x86
64-darwin12.2.1]"
irb(main):002:0> t1=Time.at(10)
=> 1969-12-31 19:00:10 -0500
irb(main):003:0> t2=Time.at(t1,t1)
=> 1969-12-31 19:00:10 -0500
irb(main):004:0> t2.usec
=> 10

Is this intended behavior? If so, the documentation should be updated.

1.9.3 behaves the same way.


Related issues

Related to ruby-trunk - Bug #8180: Backport r39967 to 1.9.3 and 2.0.x Closed 03/28/2013
Related to Backport93 - Backport #8194: Backport r39967 Closed 04/01/2013
Related to Backport200 - Backport #8193: Backport r39967 Closed 04/01/2013

Associated revisions

Revision 39967
Added by Akira Tanaka about 1 year ago

  • time.c (numexact): use tor method only if to_int method is available. [Bug #8173] reported by Hiro Asari.

History

#1 Updated by Akira Tanaka about 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39967.
Hiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • time.c (numexact): use tor method only if to_int method is available. [Bug #8173] reported by Hiro Asari.

#2 Updated by Akira Tanaka about 1 year ago

2013/3/27 hasari (Hiro Asari) asari.ruby@gmail.com:

Bug #8173: 2-arg form of Time.at can take a Time as either argument
https://bugs.ruby-lang.org/issues/8173

http://www.ruby-doc.org/core-2.0/Time.html#method-c-at shows 3 forms of invocation:

at(time) → time click to toggle source
at(secondswithfrac) → time
at(seconds, microsecondswithfrac) → time

But the last form can take a Time as either argument (and converts to a numeric value represented by the number of seconds since the Epoch). If a Time is used as the second argument, the numeric value is then converted to microseconds to return a Time. (I hope that I'm making sense.)

irb(main):001:0> RUBYDESCRIPTION
=> "ruby 2.1.0dev (2013-03-11 trunk 39724) [x86
64-darwin12.2.1]"
irb(main):002:0> t1=Time.at(10)
=> 1969-12-31 19:00:10 -0500
irb(main):003:0> t2=Time.at(t1,t1)
=> 1969-12-31 19:00:10 -0500
irb(main):004:0> t2.usec
=> 10

Is this intended behavior? If so, the documentation should be updated.

It is a bug.
--
Tanaka Akira

#3 Updated by Hiro Asari about 1 year ago

Will this be backported to 1.9.x?

#4 Updated by Akira Tanaka about 1 year ago

2013/3/28 hasari (Hiro Asari) asari.ruby@gmail.com:

Issue #8173 has been updated by hasari (Hiro Asari).

Will this be backported to 1.9.x?

Currently I don't plan to request.
--
Tanaka Akira

#5 Updated by Hiro Asari about 1 year ago

What is the reason not to?

#6 Updated by Akira Tanaka about 1 year ago

2013/3/28 hasari (Hiro Asari) asari.ruby@gmail.com:

Issue #8173 has been updated by hasari (Hiro Asari).

What is the reason not to?

Usually I don't consider backport until someone request (someone have trouble).
--
Tanaka Akira

#7 Updated by Hiro Asari about 1 year ago

Can I request it? I would like to implement the intended, more correct behavior in JRuby.

#8 Updated by Akira Tanaka about 1 year ago

2013/3/28 hasari (Hiro Asari) asari.ruby@gmail.com:

Issue #8173 has been updated by hasari (Hiro Asari).

Can I request it? I would like to implement the intended, more correct behavior in JRuby.

You can.
See .
--
Tanaka Akira

Also available in: Atom PDF