Skip to content

Commit

Permalink
Merge pull request #77 from kiskoza/parse-dates
Browse files Browse the repository at this point in the history
Fix parse issue with consecutive dates
  • Loading branch information
kiskoza authored Jan 26, 2024
2 parents bae8238 + caf5b1c commit f690844
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/crack/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ def self.format_dates(output, date_starts, date_ends)
(date_starts + date_ends).each { |i| output[i-1] = ' ' }
else
extra_chars_to_be_added = 0
timestamp_marker = '!!timestamp '
timestamp_marker_size = timestamp_marker.size

date_starts.each do |i|
output[i-2+extra_chars_to_be_added] = '!!timestamp '
extra_chars_to_be_added += 10
output[i-2+extra_chars_to_be_added] = timestamp_marker
extra_chars_to_be_added += timestamp_marker_size - 1
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
%({"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", "second_date": "2014-01-26", "third_date": "2024-01-02"}) => {'first_date' => Date.new(2016, 1, 25), 'second_date' => Date.new(2014, 1, 26), 'third_date' => Date.new(2024, 1, 2)},
%({"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
Expand Down

0 comments on commit f690844

Please sign in to comment.