Extract out date parsing in feature steps
This commit is contained in:
parent
9c57fad430
commit
88e68e038a
|
@ -64,15 +64,14 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, dire
|
|||
if "draft" == status
|
||||
path = File.join(before || '.', '_drafts', after || '.', "#{title}.#{ext}")
|
||||
else
|
||||
date = if post['date'].split.size > 1
|
||||
parsed_date = DateTime.strptime(post['date'], '%Y-%m-%d %H:%M %z')
|
||||
post['date'] = parsed_date.to_s
|
||||
parsed_date.strftime('%Y-%m-%d')
|
||||
format = if has_time_component?(post['date'])
|
||||
'%Y-%m-%d %H:%M %z'
|
||||
else
|
||||
parsed_date = Date.strptime(post['date'], '%m/%d/%Y') # WHY WOULD YOU EVER DO THIS
|
||||
post['date'] = parsed_date.to_s
|
||||
parsed_date.strftime('%Y-%m-%d')
|
||||
'%m/%d/%Y' # why even
|
||||
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}")
|
||||
end
|
||||
|
||||
|
|
|
@ -17,5 +17,9 @@ def run_jekyll(opts = {})
|
|||
system command
|
||||
end
|
||||
|
||||
def has_time_component?(date_string)
|
||||
date_string.split(" ").size > 1
|
||||
end
|
||||
|
||||
# work around "invalid option: --format" cucumber bug (see #296)
|
||||
Test::Unit.run = true if RUBY_VERSION < '1.9'
|
||||
|
|
Loading…
Reference in New Issue