Skip to content
This repository

Time.new: the UTC offset is always negative #591

Closed
janaz opened this Issue March 18, 2013 · 2 comments

2 participants

Tomasz Janowski Hiro Asari
Tomasz Janowski
janaz commented March 18, 2013

Time.now in JRuby 1.7.3 is not working as expected.
When the UTC offset passed to the Time.new is a positive value (i.e. "+12:34"), it is converted to a negative offset("-12:34").

Here is an example where I compared outputs from MRI 1.9.2 and JRuby 1.7.3

Ruby 1.9.2:

1.9.2p320 :009 > RUBY_VERSION
=> "1.9.2"
1.9.2p320 :011 > Time.new(2012, 10, 19, nil, nil, nil, "+03:00").utc_offset
=> 10800

Jruby 1.7.3

irb(main):036:0> JRUBY_VERSION
=> "1.7.3"
irb(main):038:0> Time.new(2012, 10, 19, nil, nil, nil, "+03:00").utc_offset
=> -10800
Hiro Asari BanzaiMan closed this issue from a commit March 18, 2013
Hiro Asari Fix #591.
TZ_PATTERN's first group (`(\\D+?)`) grabbed `-`, leaving `""` for
the second group, which is later used for `sign`. This led to sign
inversion being unperformed.
1c2e4ce
Hiro Asari BanzaiMan closed this in 1c2e4ce March 18, 2013
Hiro Asari
Owner

Hmm. Not quite. The sign is inverted wrong.

Hiro Asari BanzaiMan reopened this March 18, 2013
Hiro Asari
Owner

Specs are here: rubyspec/rubysepc@f00b0b7

Hiro Asari BanzaiMan closed this issue from a commit March 24, 2013
Hiro Asari Fix #591.
Only when the UTC offset is given in the 7-args form to #new, we need to invert the offset that #gmt_offset and its aliases return.
There might be a cleaner way to do it, but I was unable to come up with one.
43d635d
Hiro Asari BanzaiMan closed this in 43d635d March 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.