Skip to content

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

@frsyuki

Description

@frsyuki

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions