Module: TimeKeeper::TimeSpanSupport
Instance Method Summary
collapse
#to_i_helper, #to_s_helper
Instance Method Details
#display ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/time_keeper/time_span_support.rb', line 4
def display
[
[
start_time_string,
(start_day.to_i > 0) ? "Next Day" : nil,
],
[
end_time_string,
(end_day.to_i > 0) ? "Next Day" : nil,
]
].map { |i| i.compact.join(" ") }.join(" to ")
end
|
#duration ⇒ Object
56
57
58
|
# File 'lib/time_keeper/time_span_support.rb', line 56
def duration
((end_day * 24 * 60) + end_time) - ((start_day * 24 * 60) + start_time)
end
|
#duration_string ⇒ Object
41
42
43
|
# File 'lib/time_keeper/time_span_support.rb', line 41
def duration_string
to_s_helper(duration)
end
|
#end_time_string ⇒ Object
29
30
31
|
# File 'lib/time_keeper/time_span_support.rb', line 29
def end_time_string
to_s_helper(self.end_time) unless self.end_time.nil?
end
|
#end_time_string=(v) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/time_keeper/time_span_support.rb', line 33
def end_time_string=(v)
begin
self.end_time = to_i_helper(v)
rescue ArgumentError => e
self.errors.add :end_time, e.message
end
end
|
#start_time_string ⇒ Object
17
18
19
|
# File 'lib/time_keeper/time_span_support.rb', line 17
def start_time_string
to_s_helper(self.start_time) unless self.start_time.nil?
end
|
#start_time_string=(v) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/time_keeper/time_span_support.rb', line 21
def start_time_string=(v)
begin
self.start_time = to_i_helper(v)
rescue ArgumentError => e
self.errors.add :start_time, e.message
end
end
|
#time_range(on) ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/time_keeper/time_span_support.rb', line 45
def time_range(on)
bak, ENV['TZ'] = ENV['TZ'], Time.zone.tzinfo.name
on = on.to_time
ENV['TZ'] = bak
st = on+start_day.days
en = on+end_day.days
stt = Time.zone.local(st.year, st.month, st.day, start_time/60, start_time % 60).in_time_zone
ent = Time.zone.local(en.year, en.month, en.day, end_time/60, end_time % 60).in_time_zone
stt..ent
end
|