class TaskJuggler::TimeInterval
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.
Attributes
end[RW]
start[RW]
Public Class Methods
new(*args)
click to toggle source
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)
Calls superclass method
TaskJuggler::Interval::new
# 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
duration()
click to toggle source
Return the duration of the TimeInterval
.
# File lib/taskjuggler/Interval.rb, line 146 def duration @end - @start end
to_s()
click to toggle source
Turn the TimeInterval
into a human readable form.
# File lib/taskjuggler/Interval.rb, line 151 def to_s @start.to_s + ' - ' + @end.to_s end