Project

General

Profile

Actions

Bug #14034

closed

Time.parse does not handle timezone offsets with seconds

Added by jeremyevans0 (Jeremy Evans) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-10-19 trunk 60215) [x86_64-openbsd]
[ruby-core:83400]

Description

DateTime.parse handles them correctly, and DateTime.parse.to_time results in the correct time. Time.parse doesn't handle them correctly because Time.zone_offset uses a different regexp that only considers hours and minutes, not seconds.

Example:

DateTime.parse("1200-02-15 BC 14:13:20-00:00:00").to_time
# => -1199-02-15 14:13:20 +0000
Time.parse("1200-02-15 BC 14:13:20-00:00:00")
# => -1199-02-15 14:13:20 -0752
Time.parse("1200-02-15 BC 14:13:20-00:00")
# => -1199-02-15 14:13:20 UTC

The attached patch fixes the issue by having the Time.zone_offset regexp respect seconds if they are present.


Files

Actions #1

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r60216.


Make Time.parse respect timezone offset seconds

DateTime.parse handles them correctly, and DateTime.parse.to_time
results in the correct time. Time.parse doesn't handle them
correctly because Time.zone_offset uses a different regexp that
only considers hours and minutes, not seconds.
[ruby-core:83400] [Bug #14034]

From: Jeremy Evans

Actions

Also available in: Atom PDF

Like0
Like0