From caf5b1ca1faf51efac2d00dce534166d698edaa9 Mon Sep 17 00:00:00 2001 From: Koza Date: Tue, 2 Jan 2024 14:10:22 +0100 Subject: [PATCH] Fix parse issue with consecutive dates --- lib/crack/json.rb | 7 +++++-- test/json_test.rb | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/crack/json.rb b/lib/crack/json.rb index 4c5ac81..42f39e1 100644 --- a/lib/crack/json.rb +++ b/lib/crack/json.rb @@ -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 diff --git a/test/json_test.rb b/test/json_test.rb index d5590b0..74db077 100644 --- a/test/json_test.rb +++ b/test/json_test.rb @@ -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