Extract out date parsing in feature steps

This commit is contained in:
Parker Moore 2013-04-15 14:32:14 +02:00
parent 9c57fad430
commit 88e68e038a
2 changed files with 10 additions and 7 deletions

View File

@ -64,15 +64,14 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, dire
if "draft" == status if "draft" == status
path = File.join(before || '.', '_drafts', after || '.', "#{title}.#{ext}") path = File.join(before || '.', '_drafts', after || '.', "#{title}.#{ext}")
else else
date = if post['date'].split.size > 1 format = if has_time_component?(post['date'])
parsed_date = DateTime.strptime(post['date'], '%Y-%m-%d %H:%M %z') '%Y-%m-%d %H:%M %z'
post['date'] = parsed_date.to_s
parsed_date.strftime('%Y-%m-%d')
else else
parsed_date = Date.strptime(post['date'], '%m/%d/%Y') # WHY WOULD YOU EVER DO THIS '%m/%d/%Y' # why even
post['date'] = parsed_date.to_s
parsed_date.strftime('%Y-%m-%d')
end end
parsed_date = DateTime.strptime(post['date'], format)
post['date'] = parsed_date.to_s
date = parsed_date.strftime('%Y-%m-%d')
path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{ext}") path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{ext}")
end end

View File

@ -17,5 +17,9 @@ def run_jekyll(opts = {})
system command system command
end end
def has_time_component?(date_string)
date_string.split(" ").size > 1
end
# work around "invalid option: --format" cucumber bug (see #296) # work around "invalid option: --format" cucumber bug (see #296)
Test::Unit.run = true if RUBY_VERSION < '1.9' Test::Unit.run = true if RUBY_VERSION < '1.9'