Skip to content

Commit

Permalink
DateTime.iso8601 fails with an error if a second fraction is present
Browse files Browse the repository at this point in the history
Fixes #2883
  • Loading branch information
azolotko authored and kares committed May 22, 2015
1 parent 1956dfb commit 4e822a1
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ruby/1.9/date/format.rb
Original file line number Diff line number Diff line change
@@ -937,7 +937,7 @@ def self._iso8601(str) # :nodoc:
h[:sec] = i sec if sec
end

h[:sec_fraction] = sec_fraction if sec_fraction
h[:sec_fraction] = Rational(sec_fraction.to_i, 10**sec_fraction.size) if sec_fraction
set_zone(h, zone)

elsif /\A\s*
@@ -979,7 +979,7 @@ def self._iso8601(str) # :nodoc:
h[:sec] = i sec if sec
end

h[:sec_fraction] = sec_fraction if sec_fraction
h[:sec_fraction] = Rational(sec_fraction.to_i, 10**sec_fraction.size) if sec_fraction
set_zone(h, zone)

elsif /\A\s*
@@ -1002,7 +1002,7 @@ def self._iso8601(str) # :nodoc:
h[:hour] = i hour
h[:min] = i min
h[:sec] = i sec if sec
h[:sec_fraction] = i sec_fraction if sec_fraction
h[:sec_fraction] = Rational(sec_fraction.to_i, 10**sec_fraction.size) if sec_fraction
set_zone(h, zone)
end
h
14 changes: 14 additions & 0 deletions spec/regression/GH-2883_date_sec_fraction_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'rspec'
require 'date'

# https://github.com/jruby/jruby/issues/2883

if RUBY_VERSION > '1.9'
describe 'DateTime.iso8601' do
it 'correctly parses fraction of a second' do
date = DateTime.iso8601('2014-07-08T17:51:36.013Z')
date.sec_fraction.should == Rational(13, 1000)
date.second_fraction.should == Rational(13, 1000)
end
end
end

0 comments on commit 4e822a1

Please sign in to comment.