Skip to content

Instantly share code, notes, and snippets.

@roelentless
roelentless / gist:5233676
Created March 24, 2013 21:44
A method to group time ranges into time-by-day percentages. Usefull for analysis of time ranges.
##
# Having two times, group the time by dates in percentages.
# Time and analysis will be done in the timezone the time is passed with.
# Result for time range D1-D5:
# D1 |-----D2------------D3------------D4------| D5
# 16.67% 32.34% 32.34% 16.67%
def date_range_group(start_time, end_time)
return nil unless start_time
return nil unless end_time > start_time
total = end_time - start_time