Sha256: a96ec1eada834f9d94301babaafc67a36272176502e8e3f57b2e964c06f824c4

Contents?: true

Size: 654 Bytes

Versions: 1

Compression:

Stored size: 654 Bytes

Contents

class ClockTime::Span
  attr_reader :from, :to

  class << self
    def parse(from_string, to_string)
      from = ClockTime.parse(from_string)
      to = ClockTime.parse(to_string)
      new(from, to)
    end
  end

  def initialize(from, to)
    if !from.is_a?(ClockTime) || !to.is_a?(ClockTime)
      raise ArgumentError, 'invalid span'
    end
    @from = from
    @to = to
  end

  def duration
    return @to - @from + 24.hours if @to < @from
    @to - @from
  end

  def to_times(date)
    from_t = from.to_time(date)
    to_t = to.next_time(from_t)
    return [from_t, to_t]
  end

  def ==(span)
    from == span.from && to == span.to
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clock_time-0.1.0 lib/clock_time/span.rb