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

JRuby 9.0.5.0: %Z behavior is incompatible between strptime and strftime #3702

Closed
frsyuki opened this issue Feb 26, 2016 · 5 comments
Closed

Comments

@frsyuki
Copy link
Contributor

frsyuki commented Feb 26, 2016

And its behavior is different from CRuby.

Environment

On Mac OS X, using System Preference.app, I set system timezone to JST (+0900).

Actual Behavior

JRuby 9.0.5.0:

irb(main):003:0> require 'time'
=> true
irb(main):002:0> Time.strptime('2016-08-01 00:00:00 PDT', '%Y-%m-%d %H:%M:%S %Z').strftime('%Y-%m-%d %H:%M:%S %Z')
=> "2016-08-01 00:00:00 UTC+7"
irb(main):003:0> Time.strptime('2016-08-01 00:00:00 UTC+7', '%Y-%m-%d %H:%M:%S %Z').strftime('%Y-%m-%d %H:%M:%S %Z')
=> "2016-08-01 00:00:00 JST"
irb(main):004:0> Time.strptime('2016-08-01 00:00:00 UTC+7', '%Y-%m-%d %H:%M:%S %z').strftime('%Y-%m-%d %H:%M:%S %Z')
=> "2016-08-01 00:00:00 JST"

JRuby's strftime with %Z outputs UTC+7, and strptime doesn't understand it (with neither %z or %Z).

CRuby 2.3.0:

irb(main):028:0> require 'time'
=> false
irb(main):029:0> Time.strptime('2016-08-01 00:00:00 PDT', '%Y-%m-%d %H:%M:%S %Z').strftime('%Y-%m-%d %H:%M:%S %Z')
=> "2016-08-01 00:00:00 "
irb(main):030:0> Time.strptime('2016-08-01 00:00:00 UTC+7', '%Y-%m-%d %H:%M:%S %Z').strftime('%Y-%m-%d %H:%M:%S %Z')
=> "2016-08-01 00:00:00 JST"
irb(main):031:0> Time.strptime('2016-08-01 00:00:00 UTC+7', '%Y-%m-%d %H:%M:%S %z').strftime('%Y-%m-%d %H:%M:%S %Z')
=> "2016-08-01 00:00:00 JST"

CRuby's strftime with %Z outputs (one space), and of course,strptime doesn't understand it.

Expected Behavior

  • a) JRuby 9.0.5.0 behaves exactly same with CRuby, or
  • b) JRuby 9.0.5.0's strptime can parse UTC+7 using %Z% (and improve CRuby as well), or
  • c) JRuby 9.0.5.0's strftime outputs PDT or +0700 using %Z% (and improve CRuby as well)

Although it's behavior is different from CRuby, JRuby 9.0.5.0's improvement is good, I think. So, I prefer b) or c).

@nurse
Copy link
Contributor

nurse commented Feb 27, 2016

In this case, it's not a matter of strftime. Because the receiver, created by strptime, doesn't have timezone name.

So this is an issue of strptime, "How should strptime handle %Z?". The string is system/local dependent. For example Ruby on Windows, it is "Pacific Standard Time" or "日本標準時". Maybe it can be used for display, it can't be used for timezone information. glibc says simple answer for this.

People must get the offset with "%z".

@frsyuki
Copy link
Contributor Author

frsyuki commented Mar 4, 2016

@nurse do you mean that applications shouldn't use starptime with %Z? Then, Expected Behavior "a)" sounds the right approach because actual behavior doesn't matter.

frsyuki added a commit to embulk/embulk that referenced this issue Mar 4, 2016
Guessed value should always be %z.
See jruby/jruby#3702 for the discussion.
@nurse
Copy link
Contributor

nurse commented Mar 4, 2016

Yeah, application shouldn't use %Z. They must get time offset or IANA timezone name, which can get from %z or ... something else.

I don't have any opinion about JRuby's strptime(%Z).

@maclover7
Copy link

Should this issue be closed since #3758 was merged in?

@kares kares closed this as completed Jan 18, 2017
@kares
Copy link
Member

kares commented Jan 18, 2017

was fixed for 9.1.0.0 to match up with MRI

@kares kares added this to the JRuby 9.1.0.0 milestone Jan 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants