Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array of dates #395

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/chronic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def self.parse(text, options = {})
Parser.new(options).parse(text)
end

def self.parse_array(array)
edumoreira1506 marked this conversation as resolved.
Show resolved Hide resolved
@array_dates = []

array.each { |item| @array_dates.push(Parser.new(item[:options]).parse(item[:text])) }

@array_dates
end

# Construct a new time object determining possible month overflows
# and leap years.
#
Expand Down
20 changes: 20 additions & 0 deletions test/test_parsing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down