# This method calculates the days extrema given two time objects.
# start time is the given time1 at 00:00:00
# end time is the given time2 at 23:59:59:999
#
# Input:
# - the two times (if only time1 is provided then you get an extrema
#   of exactly one day extrema.
#
# Output:
# - the time range. you can get the start/end times using
#   range methods.
#
#--
# Credit goes to George Moschovitis
#++
def Time.days_extrema(time1, time2=nil)
  time2 = time1 if (not time2.valid? Time)
  time2 = NEVER if (time2 <= time1)
  start_time = Time.self.start_of_day(time1)
  end_time = self.end_of_day(time2)
  return (start_time..end_time)
end
