DateTimeRange

Ruby forge project | Acts as placed on timeline | Acts as placed on timeline API

Constants

BEGINNING_OF_TIME: The minimum supported DateTime value for the database.
END_OF_TIME: The maximum supported DateTime value for the database.

These values are used to simulate infinite ranges. The minimum and maximum values are defined by AAPOT in the ConnectionAdapter classes for each database type.

Class methods

new(args)
Creates a new range from the passed arguments. These can be in several formats:

Moments: Any object that responds to :to_date_time (String, Date, Time, DateTime)
Ranges: DateTimeRange or an array of two objects that respond to :to_date_time

An ArgumentError will be raised when the format cannot be parsed or if the range is invalid.

now
Returns a moment range for this second

future
Returns a range from now until the end of time.

past
Returns a range from the beginning of time until now.

whenever
Returns a range from the beginning of time until the end of time.

week(year,week)
Returns a range for the specified week.

month(year,month)
Returns a range for the specified month.

year(year)
Returns a range for the specified year.

previous_week|month|year(DateTime)
These functions will parse a DateTimeRange from the given DateTime that matches the request parameters.

current_week|month|year(DateTime)
These functions will parse a DateTimeRange from the given DateTime that matches the request parameters.

next_week|month|year(DateTime)
These functions will parse a DateTimeRange from the given DateTime that matches the request parameters.

Instance methods

to_a
Turns the range into an array by using the default step function of DateTime objects.

length
The amount of seconds in the range

==(DateTimeRange)
Determines if both ranges are equal

start, begin, first
The start of the range

stop, end, last
The stop of the range

next
If the range is a default format (like week, month or year) it will return the next week, month or year

previous
If the range is a default format (like week, month or year) it will return the previous week, month or year

overlap(DateTimeRange)
Determine the overlap type between two ranges. Possible return values are:

:equal: Both ranges are exactly the same.
:inside: This range is inside the given range
:before: This range is before the given range
:after: This range is after the given range
:starts_earlier: This range starts earlier but ends at the same time as the given range
:starts_later: This range starts later but ends at the same time as the given range
:ends_earlier: This range ends earlier but starts at the same time as the given range
:ends_later: This range ends later but starts at the same time as the given range
:around: This range is around (bigger) than the given range
:left_overlap: This range overlaps the given range on the left
:right_overlap: This range overlaps the given range on the right

Each of these has a specific check function that is named similarly.

equal?(DateTimeRange)
See the overlap method.

inside?(DateTimeRange)
See the overlap method.

before?(DateTimeRange)
See the overlap method.

after?(DateTimeRange)
See the overlap method.

starts_earlier?(DateTimeRange)
See the overlap method.

starts_later?(DateTimeRange)
See the overlap method.

ends_earlier?(DateTimeRange)
See the overlap method.

ends_later?(DateTimeRange)
See the overlap method.

around?(DateTimeRange)
See the overlap method.

left_overlap?(DateTimeRange)
See the overlap method.

right_overlap?(DateTimeRange)
See the overlap method.

to_s
Return string representation of the range

week?, month?, year?
Determines if the range is a default week, month or year range.

whenever?
Determines if the range is the whenever range (see DateTimeRange.whenever).

moment?
Determines if the range is a moment. (start == stop)

from_beginning_of_time?
Determines if the range is infinite in the past.

to_end_of_time?
Determines if the range is infinite in the future.