Module: Doing::ItemDates

Included in:
Item
Defined in:
lib/doing/item/dates.rb

Instance Method Summary collapse

Instance Method Details

#calculate_end_date(opt) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/doing/item/dates.rb', line 37

def calculate_end_date(opt)
  if opt[:took]
    if @date + opt[:took] > Time.now
      @date = Time.now - opt[:took]
      Time.now
    else
      @date + opt[:took]
    end
  elsif opt[:back]
    if opt[:back].is_a? Integer
      @date + opt[:back]
    else
      @date + (opt[:back] - @date)
    end
  else
    Time.now
  end
end

#durationObject

If the entry doesn't have a @done date, return the elapsed time



10
11
12
13
14
15
16
# File 'lib/doing/item/dates.rb', line 10

def duration
  return nil unless should_time? && should_finish?

  return nil if @title =~ /(?<=^| )@done\b/

  Time.now - @date
end

#end_dateTime

Get the value of the item's @done tag

Returns:

  • (Time)

    @done value



33
34
35
# File 'lib/doing/item/dates.rb', line 33

def end_date
  @end_date ||= Time.parse(Regexp.last_match(1)) if @title =~ /@done\((\d{4}-\d\d-\d\d \d\d:\d\d.*?)\)/
end

#expand_date_tags(additional_tags = nil) ⇒ Object

Updates the title of the Item by expanding natural language dates within configured date tags (tags whose value is expected to be a date)

Parameters:

  • additional_tags (defaults to: nil)

    An array of additional tag names to consider dates



96
97
98
# File 'lib/doing/item/dates.rb', line 96

def expand_date_tags(additional_tags = nil)
  @title.expand_date_tags(additional_tags)
end

#intervalObject

Get the difference between the item's start date and the value of its @done tag (if present)

Returns:

  • Interval in seconds



24
25
26
# File 'lib/doing/item/dates.rb', line 24

def interval
  @interval ||= calc_interval
end

#overlapping_time?(item_b) ⇒ Boolean

Test if the interval between start date and @done value overlaps with another item's

Parameters:

  • item_b (Item)

    The item to compare

Returns:

  • (Boolean)

    overlaps?



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/doing/item/dates.rb', line 75

def overlapping_time?(item_b)
  return true if same_time?(item_b)

  start_a = date
  a_interval = interval
  end_a = a_interval ? start_a + a_interval.to_i : start_a
  start_b = item_b.date
  b_interval = item_b.interval
  end_b = b_interval ? start_b + b_interval.to_i : start_b
  (start_a >= start_b && start_a <= end_b) || (end_a >= start_b && end_a <= end_b) || (start_a < start_b && end_a > end_b)
end

#same_time?(item_b) ⇒ Boolean

Test if two items occur at the same time (same start date and equal duration)

Parameters:

  • item_b (Item)

    The item to compare

Returns:

  • (Boolean)

    is equal?



63
64
65
# File 'lib/doing/item/dates.rb', line 63

def same_time?(item_b)
  date == item_b.date ? interval == item_b.interval : false
end