Issue #12190 has been updated by Naotoshi Seo.


I verified that new codes cover all ZoneOffset which covered before with test codes https://github.com/ruby/ruby/pull/1297/files#diff-0bc90ed869793fffc539dfe705fa8facR443
This change should not break existing codes.

(Of course, if someone expects that `Time.parse('2000-01-01T00:00:00 CET')` returns UTC timezone, such codes will be broken. But, I think such codes are already broken)

----------------------------------------
Bug #12190: DateTime.strptime and Time.strptime does not have compatibility in terms of parsing timezone
https://bugs.ruby-lang.org/issues/12190#change-58147

* Author: Naotoshi Seo
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin13]
* Backport: 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED
----------------------------------------
For CET, only DateTime.strptime successfully parsed timezone

```
irb(main):003:0> DateTime.strptime('2015-11-12 CET', '%Y-%m-%d %Z')
=> #<DateTime: 2015-11-12T00:00:00+01:00 ((2457338j,82800s,0n),+3600s,2299161j)>
irb(main):004:0> Time.strptime('2015-11-12 CET', '%Y-%m-%d %Z')
=> 2015-11-12 00:00:00 +0900
```

For JST also, only DateTime worked.

```
irb(main):005:0> ENV['TZ'] = 'UTC'
=> "UTC"
irb(main):006:0> DateTime.strptime('2015-11-12 JST', '%Y-%m-%d %Z')
=> #<DateTime: 2015-11-12T00:00:00+09:00 ((2457338j,54000s,0n),+32400s,2299161j)>
irb(main):007:0> Time.strptime('2015-11-12 JST', '%Y-%m-%d %Z')
=> 2015-11-12 00:00:00 +0000
```

For PST, both worked.

```
irb(main):004:0> DateTime.strptime('2015-11-12 PST', '%Y-%m-%d %Z')
=> #<DateTime: 2015-11-12T00:00:00-08:00 ((2457339j,28800s,0n),-28800s,2299161j)>
irb(main):003:0> Time.strptime('2015-11-12 PST', '%Y-%m-%d %Z')
=> 2015-11-12 00:00:00 -0800
```

I felt DateTime.strptime and Time.strptime should have compatibility.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>