Skip to content

Instantly share code, notes, and snippets.

@naush
Created January 12, 2012 13:20
Show Gist options
  • Save naush/1600483 to your computer and use it in GitHub Desktop.
Save naush/1600483 to your computer and use it in GitHub Desktop.
Process time table data for vane.
lines = File.open('time_table.csv', 'rb') { |file| file.read }
require 'time'
File.open('result_time_table.csv', 'w') do |csv|
lines.each do |line|
tokens = line.chomp.split(",")
if tokens[1] == ":"
csv.puts tokens.join(",")
next
end
date = tokens[0]
time = tokens[1]
start_time = Time.parse("#{date} 08:30")
end_time = Time.parse("#{date} #{time}")
tokens[2] = (end_time - start_time) / 60
time = tokens[3]
start_time = Time.parse("#{date} 18:00")
end_time = Time.parse("#{date} #{time}")
tokens[4] = (end_time - start_time) / 60
csv.puts tokens.join(",")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment