Skip to content

Instantly share code, notes, and snippets.

@dylanirlbeck
Created August 18, 2020 16:02
Show Gist options
  • Save dylanirlbeck/a08ae6eb717777b5a784b7551775039d to your computer and use it in GitHub Desktop.
Save dylanirlbeck/a08ae6eb717777b5a784b7551775039d to your computer and use it in GitHub Desktop.
field :turnaround_time, Int, null: true
def turnaround_time(inbound_delivery, outbound_delivery)
# If the outbound delivery hasn't departed, use the current time.
departure_time = outbound_delivery.departure_time || Time.zone.now
time_difference = departure_time - inbound_delivery.arrival_time
# Round to convert a datetime difference into hours
(time_difference / 1.hour).round
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment