Module: RichUnits::Times::TimeClass

Included in:
Time
Defined in:
lib/richunits/times.rb

Overview

Time Metaclass Extensions

Instance Method Summary collapse

Instance Method Details

#days_extrema(time1, time2 = nil) ⇒ Object

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 George Moschovitis


410
411
412
413
414
415
416
# File 'lib/richunits/times.rb', line 410

def days_extrema(time1, time2=nil)
  time2 = time1 if (not time2.valid? Time)
  time2 = NEVER if (time2 <= time1)
  start_time = time1.start_of_day #start_of_day(time1)
  end_time   = time2.end_of_day #end_of_day(time2)
  return (start_time..end_time)
end