Class IceCube::Occurrence
In: lib/ice_cube/occurrence.rb
Parent: SimpleDelegator

Wraps start_time and end_time in a single concept concerning the duration. This delegates to the enclosed start_time so it behaves like a normal Time in almost all situations, however:

Without ActiveSupport, it‘s necessary to cast the occurrence using +to_time+ before doing arithmetic, else Time will try to subtract it using +to_i+ and return a new time instead.

    Time.now - Occurrence.new(start_time) # => 1970-01-01 01:00:00
    Time.now - Occurrence.new(start_time).to_time # => 3600

When ActiveSupport::Time core extensions are loaded, it‘s possible to subtract an Occurrence object directly from a Time to get the difference:

    Time.now - Occurrence.new(start_time) # => 3600

Methods

<=>   comparable_time   cover?   duration   include?   intersects?   is_a?   kind_of?   name   new   overnight?   to_i   to_range   to_s   to_time  

Included Modules

Comparable

External Aliases

start_time -> first
end_time -> last

Attributes

end_time  [R] 
start_time  [R] 

Public Class methods

Report class name as ‘Time’ to thwart type checking.

Public Instance methods

include?(other)

Alias for cover?

kind_of?(klass)

Alias for is_a?

Shows both the start and end time if there is a duration. Optional format argument (e.g. :long, :short) supports Rails time formats and is only used when ActiveSupport is available.

[Validate]