Skip to content

Instantly share code, notes, and snippets.

@SeanRoberts
Created September 13, 2011 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanRoberts/1214834 to your computer and use it in GitHub Desktop.
Save SeanRoberts/1214834 to your computer and use it in GitHub Desktop.
task :parse_tournament_dates => :environment do
tournaments = Tournament.all
tournaments.each do |tournament|
dates = tournament.dates.split(' to ')
if dates.size == 2
begin
tournament.starts_on, tournament.ends_on = Time.parse(dates[0]), Time.parse(dates[1])
tournament.save
puts "Saved #{tournament.title} (#{tournament.starts_on}-#{tournament.ends_on})"
rescue
puts "Couldn't parse #{tournament.dates}"
end
end
end
end
# tournament.dates is a string that I'm trying to parse to find a start and end date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment