Created
July 21, 2010 05:53
-
-
Save gumayunov/484129 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def to_time(h, m) | |
day, month, year = Time.now.to_a[3..5] | |
Time.mktime(year, month, day, h.to_i > 23 ? 0 : h, m).to_i | |
end | |
summ = 0 | |
Dir['*.txt'].each do |file_name| | |
new_lines = File.open(file_name) do |file| | |
file.lines.map do |line| | |
if line =~ /^\s*(?:\d+\.\d+[, ]+)(\d\d?)[:.](\d\d?)\s*-\s*(\d\d?)[:.](\d\d?)\s+(.+)$/ | |
diff = to_time($3, $4) - to_time($1, $2) | |
diff += 24*60*60 if diff < 0 | |
diff /= 60*60.0 | |
summ += diff | |
"%2.2f, %d:%d - %d:%d %s" % [diff, $1, $2, $3, $4, $5] | |
else | |
line | |
end | |
end | |
end | |
File.open(file_name, 'w').write new_lines.join("\n") | |
end | |
puts "%2.2f часов отработано" % [summ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment