Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time#getlocal should accept Fixnum as an argument #2438

Closed
dalizard opened this Issue Jan 7, 2015 · 6 comments

Comments

Projects
None yet
3 participants
@dalizard
Copy link

dalizard commented Jan 7, 2015

I will explain the problem briefly:

[25] pry(main)> `ruby -v`
=> "ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n"
[26] pry(main)> Time.new.getlocal(0)
=> 2015-01-07 20:55:12 +0000
[27] pry(main)> Time.new.getlocal(1)
=> 2015-01-07 20:55:15 +0000
[28] pry(main)> Time.new.getlocal(3000)
=> 2015-01-07 21:45:17 +0050
[29] pry(main)> Time.new.getlocal(-3000)
=> 2015-01-07 20:05:19 -0050
[4] pry(main)> `ruby -v`
=> "jruby 1.7.18 (2.0.0p598) 2014-12-22 625381c on Java HotSpot(TM) 64-Bit Server VM 1.7.0_71-b14 [darwin-x86_64]\n"
[5] pry(main)> Time.new.getlocal(0)
ArgumentError: "+HH:MM" or "-HH:MM" expected for utc_offset
from org/jruby/RubyTime.java:443:in `getlocal'
[6] pry(main)> Time.new.getlocal(1)
ArgumentError: "+HH:MM" or "-HH:MM" expected for utc_offset
from org/jruby/RubyTime.java:443:in `getlocal'
[7] pry(main)> Time.new.getlocal(3000)
ArgumentError: "+HH:MM" or "-HH:MM" expected for utc_offset
from org/jruby/RubyTime.java:443:in `getlocal'
[8] pry(main)> Time.new.getlocal(-3000)
ArgumentError: "+HH:MM" or "-HH:MM" expected for utc_offset
from org/jruby/RubyTime.java:443:in `getlocal'
[9] pry(main)> 

According to the documentation (MRI), Time#getlocal can accept an optional utc_offset parameter, which is a Fixnum (http://www.ruby-doc.org/core-2.1.5/Time.html#method-i-utc_offset).

@enebo

This comment has been minimized.

Copy link
Member

enebo commented Jan 7, 2015

Thanks for opening this. It should be fixed soon. I realized there are several numeric cases we don't have covered.

@dalizard

This comment has been minimized.

Copy link
Author

dalizard commented Jan 7, 2015

You are welcome! I would gladly submit a pull request for this, but I am not familiar with JRuby internals :(

@enebo

This comment has been minimized.

Copy link
Member

enebo commented Jan 7, 2015

Fixed in commit dbf58e6. This yielded a couple of other smaller fixes at the same time on both 1.7 and master. I did not try original snippet so the original reporter can reopen if somehow this is not correct.

@enebo enebo closed this Jan 7, 2015

@mjansing

This comment has been minimized.

Copy link

mjansing commented Jan 8, 2015

@enebo Great work. I will check the original snippet soon.

@mjansing

This comment has been minimized.

Copy link

mjansing commented Jan 8, 2015

The original snippet also works fine:

[1] pry(main)> `ruby -v`
=> "jruby 1.7.19-SNAPSHOT (1.9.3p551) 2015-01-08 dbf58e6 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_51-b13 [darwin-x86_64]\n"
[2] pry(main)> t = Time.zone.now
=> Thu, 08 Jan 2015 08:38:14 UTC +00:00
[3] pry(main)> I18n.l(t, :format => :short)
=> "08 Jan 08:38"
@enebo

This comment has been minimized.

Copy link
Member

enebo commented Jan 8, 2015

@mjansing great. Thanks for checking...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.