Permalink
Browse files

Using Time.parse to ensure date format is valid

  • Loading branch information...
1 parent 02e2f86 commit 2d629f296120ffd42c3ed5f4a1b94fff15b3204d Andrea Schiavini committed with plusjade Feb 13, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 Rakefile
View
@@ -45,7 +45,7 @@ task :post do
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
title = ENV["title"] || "new-post"
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
- date = ENV['date'] || Time.now.strftime('%Y-%m-%d')
+ date = (Time.parse(ENV['date']) || Time.now).strftime('%Y-%m-%d')
filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}")
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'

0 comments on commit 2d629f2

Please sign in to comment.