diff --git a/lib/chronic.rb b/lib/chronic.rb index d56641fd..64c2fe7b 100644 --- a/lib/chronic.rb +++ b/lib/chronic.rb @@ -95,6 +95,10 @@ def self.parse(text, options = {}) Parser.new(options).parse(text) end + def self.parse_array(items) + items.map { |item| parse(item[:text], item[:options]) } + end + # Construct a new time object determining possible month overflows # and leap years. # diff --git a/test/test_parsing.rb b/test/test_parsing.rb index 932b4d23..7cfa327a 100644 --- a/test/test_parsing.rb +++ b/test/test_parsing.rb @@ -47,6 +47,26 @@ def test_handle_generic assert_equal Time.new(Time.now.year, Time.now.month, 28), time end + def test_handle_array_generic + times = Chronic.parse_array([ + { + 'options': {}, + 'text': '2012-08-02T13:00:00' + }, + { + 'options': {}, + 'text': '2012-08-02T13:00:00+01:00' + }, + { + 'options': {}, + 'text': 'tomorrow' + } + ]) + + assert_equal Time.local(2012, 8, 2, 13), times[0] + assert_equal Time.utc(2012, 8, 2, 12), times[1] + end + def test_handle_rmn_sd time = parse_now("aug 3") assert_equal Time.local(2007, 8, 3, 12), time