Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
require 'time'
# define the regular arrival time, that is used to detect a cycle
# maximum delay can be 23 hours 59 minutes (because of cycling times)
def average_time_of_day(arrivals)
# check for a cycle and convert arrival times into UNIX timestamps
arrivals.collect!{ |a|
a = Time.parse(a)
a += 60*60*24 if a < Time.parse(REGULAR_ARRIVAL_TIME)
# get the average timestamp
sum = arrivals.inject{ |sum,x| sum + x }
average_time = sum/arrivals.length
# convert the timestamp back and return it
average_time =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment