Skip to content

Commit

Permalink
Merge pull request #57 from aditiraveesh/master
Browse files Browse the repository at this point in the history
Fix for key mangling when using multiple dates
  • Loading branch information
greatuserongithub committed Dec 2, 2015
2 parents 7e2b953 + d5dd090 commit 0bde947
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/crack/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def self.format_dates(output, date_starts, date_ends)
if YAML.constants.include?('Syck')
(date_starts + date_ends).each { |i| output[i-1] = ' ' }
else
date_starts.each { |i| output[i-2] = '!!timestamp ' }
extra_chars_to_be_added = 0
date_starts.each do |i|
output[i-2+extra_chars_to_be_added] = '!!timestamp '
extra_chars_to_be_added += 10
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
%({"a": "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"},
%({"a": "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"},
%({"a": "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)},
%({"first_date": "2016-01-25", "second_date": "2014-01-26"}) => {'first_date' => Date.new(2016, 1, 25), 'second_date' => Date.new(2014, 1, 26)},
%({"first_date": "2016-01-25", "non_date": "Abc", "second_date": "2014-01-26"}) => {'first_date' => Date.new(2016, 1, 25), 'non_date' => 'Abc', 'second_date' => Date.new(2014, 1, 26)},
%({"a": "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)},
# Handle ISO 8601 date/time format http://en.wikipedia.org/wiki/ISO_8601
%({"a": "2007-01-01T01:12:34Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)},
Expand Down

0 comments on commit 0bde947

Please sign in to comment.