Class: TaskJuggler::TimeInterval

Inherits:
Interval show all
Defined in:
lib/taskjuggler/Interval.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Interval

#<=>, #==, #combine, #contains?, #intersection, #overlaps?

Constructor Details

#initialize(*args) ⇒ TimeInterval

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)



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/taskjuggler/Interval.rb', line 119

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

Instance Attribute Details

#endObject

Returns the value of attribute end.



109
110
111
# File 'lib/taskjuggler/Interval.rb', line 109

def end
  @end
end

#startObject

Returns the value of attribute start.



109
110
111
# File 'lib/taskjuggler/Interval.rb', line 109

def start
  @start
end

Instance Method Details

#durationObject

Return the duration of the TimeInterval.



147
148
149
# File 'lib/taskjuggler/Interval.rb', line 147

def duration
  @end - @start
end

#to_sObject

Turn the TimeInterval into a human readable form.



152
153
154
# File 'lib/taskjuggler/Interval.rb', line 152

def to_s
  @start.to_s + ' - ' + @end.to_s
end