Skip to content

Instantly share code, notes, and snippets.

@doug7410
Last active August 29, 2015 14:11
Show Gist options
  • Save doug7410/ab900c18319e4ee1ac4e to your computer and use it in GitHub Desktop.
Save doug7410/ab900c18319e4ee1ac4e to your computer and use it in GitHub Desktop.
method for calculating time, used in https://github.com/doug7410/punch-clock
def total_time_on_job
total = 0
self.punches.each do |punch|
if punch.punch_out
punch_in_time = punch.created_at
punch_out_time = punch.punch_out
total_time = punch_out_time - punch_in_time
total += total_time
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment