Module: Plansheet::TimeUtils

Included in:
Project, WeeklyLaTeXSheet
Defined in:
lib/plansheet/time.rb

Instance Method Summary collapse

Instance Method Details

#build_time_duration(minutes) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/plansheet/time.rb', line 23

def build_time_duration(minutes)
  if minutes > 59
    if (minutes % 60).zero?
      "#{minutes / 60}h"
    else
      "#{minutes / 60}h #{minutes % 60}m"
    end
  else
    "#{minutes}m"
  end
end

#parse_date_duration(str) ⇒ Object



5
6
7
8
9
10
# File 'lib/plansheet/time.rb', line 5

def parse_date_duration(str)
  return Regexp.last_match(1).to_i if str.strip.match(/(\d+)[dD]/)
  return (Regexp.last_match(1).to_i * 7) if str.strip.match(/(\d+)[wW]/)

  raise "Can't parse time duration string #{str}"
end

#parse_time_duration(str) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/plansheet/time.rb', line 12

def parse_time_duration(str)
  if str.match(/(\d+h) (\d+m)/)
    return (parse_time_duration(Regexp.last_match(1)) + parse_time_duration(Regexp.last_match(2)))
  end

  return Regexp.last_match(1).to_i if str.strip.match(/(\d+)m/)
  return (Regexp.last_match(1).to_f * 60).to_i if str.strip.match(/(\d+\.?\d*)h/)

  raise "Can't parse time duration string #{str}"
end