Aggregate time functions for ActiveRecord