Class TaskJuggler::TimeInterval
In: lib/taskjuggler/Interval.rb
Parent: Interval

The TimeInterval class provides objects that model a time interval. The start end end time are represented as seconds after Jan 1, 1970. The start is part of the interval, the end is not.

Methods

duration   new   to_s  

Attributes

end  [RW] 
start  [RW] 

Public Class methods

Create a new TimeInterval. args can be three different kind of arguments.

a and b should be TjTime objects.

TimeInterval.new(a, b) | -> Interval(a, b) TimeInterval.new(a) | -> Interval(a, a) TimeInterval.new(iv) | -> Interval(iv.start, iv.end)

[Source]

# File lib/taskjuggler/Interval.rb, line 118
    def initialize(*args)
      if args.length == 1
        if args[0].is_a?(TjTime)
          # Just one argument, a date
          super(args[0], args[0])
        elsif args[0].is_a?(TimeInterval)
          # Just one argument, a TimeInterval
          super(args[0].start, args[0].end)
        else
          raise ArgumentError, "Illegal argument 1: #{args[0].class}"
        end
      elsif args.length == 2
        # Two arguments, a start and end date
        unless args[0].is_a?(TjTime)
          raise ArgumentError, "Interval start must be a date, not a " +
                "#{args[0].class}"
        end
        unless args[1].is_a?(TjTime)
          raise ArgumentError, "Interval end must be a date, not a" +
                "#{args[1].class}"
        end
        super(args[0], args[1])
      else
        raise ArgumentError, "Too many arguments: #{args.length}"
      end
    end

Public Instance methods

Return the duration of the TimeInterval.

[Source]

# File lib/taskjuggler/Interval.rb, line 146
    def duration
      @end - @start
    end

Turn the TimeInterval into a human readable form.

[Source]

# File lib/taskjuggler/Interval.rb, line 151
    def to_s
      @start.to_s + ' - ' + @end.to_s
    end

[Validate]