Skip to content

Commit

Permalink
Merge pull request #221 from andrew/date-parsing
Browse files Browse the repository at this point in the history
Use the parse_date function everywhere
  • Loading branch information
pengwynn committed Feb 10, 2013
2 parents 75904d2 + fbd06b8 commit fd930c6
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions lib/octokit/client/commits.rb
Expand Up @@ -206,14 +206,8 @@ def commits_before(repo, date, sha_or_branch="master", options={})
# @example
# Octokit.commits_on('pengwynn/octokit', '2012-10-01')
def commits_on(repo, date, sha_or_branch="master", options={})
begin
# defaults to 00:00:00
start_date = DateTime.parse(date)
# addition defaults to n days
end_date = start_date + 1
rescue ArgumentError
raise ArgumentError, "#{date} is not a valid date"
end
start_date = parse_date(date)
end_date = start_date + 1
params = { :since => iso8601(start_date), :until => iso8601(end_date) }
commits(repo, sha_or_branch, params.merge(options))
end
Expand All @@ -229,20 +223,8 @@ def commits_on(repo, date, sha_or_branch="master", options={})
# @example
# Octokit.commits_on('pengwynn/octokit', '2012-10-01', '2012-11-01')
def commits_between(repo, start_date, end_date, sha_or_branch="master", options={})
begin
# defaults to 00:00:00
# use a second var for the parsed date so error message is consistent
_start_date = DateTime.parse(start_date)
rescue ArgumentError
raise ArgumentError, "#{start_date} is not a valid date"
end
begin
# defaults to 00:00:00
# use a second var for the parsed date so error message is consistent
_end_date = DateTime.parse(end_date)
rescue ArgumentError
raise ArgumentError, "#{end_date} is not a valid date"
end
_start_date = parse_date(start_date)
_end_date = parse_date(end_date)
if _end_date < _start_date
raise ArgumentError, "Start date #{start_date} does not precede #{end_date}"
end
Expand All @@ -267,12 +249,11 @@ def iso8601(date)
# @param date [String] String representation of a date
# @return [DateTime]
def parse_date(date)
begin
date = DateTime.parse(date)
rescue ArgumentError
raise ArgumentError, "#{date} is not a valid date"
end
date = DateTime.parse(date)
rescue ArgumentError
raise ArgumentError, "#{date} is not a valid date"
end

end
end
end

0 comments on commit fd930c6

Please sign in to comment.