module Abstractive::TimeSpans::Methods
Constants
- DAY
- HOUR
- MINUTE
Public Instance Methods
day_decimal(span)
click to toggle source
# File lib/abstractive/timespans.rb, line 25 def day_decimal(span) span = time_spans(span) if span.is_a? Fixnum hms = span[1]*HOUR+span[2]*MINUTE+span[3] span[0].to_f + (hms.to_f/DAY.to_f) end
duration(start, finish)
click to toggle source
# File lib/abstractive/timespans.rb, line 59 def duration(start, finish) finish.to_i - start.to_i end
minus_span(base, sub)
click to toggle source
# File lib/abstractive/timespans.rb, line 53 def minus_span(base, sub) sub = day_decimal(sub) unless sub.is_a?(Float) _ = DateTime.jd(base.to_datetime.jd - sub) DateTime.strptime(_.strftime('%FT%T')+base.strftime('%:z')) end
notated_time_length(span)
click to toggle source
# File lib/abstractive/timespans.rb, line 13 def notated_time_length(span) span = time_spans(span) unless span.is_a? Array length = "" length += "#{span[0]}d " if span[0] > 0 length += "#{span[1]}h " if span[1] > 0 length += "#{span[2]}m " if span[2] > 0 length += "#{span[3]}s " length += "#{span[2]}ms " if span[3] > 0 length.strip end
Also aliased as: readable_duration
plus_span(base, add)
click to toggle source
# File lib/abstractive/timespans.rb, line 47 def plus_span(base, add) add = day_decimal(add) unless add.is_a?(Float) _ = DateTime.jd(base.to_datetime.jd + add) DateTime.strptime(_.strftime('%FT%T')+base.strftime('%:z')) end
time_spans(length)
click to toggle source
# File lib/abstractive/timespans.rb, line 31 def time_spans(length) milliseconds = nil if length.is_a?(Float) milliseconds = ((length - length.floor) * 100).to_i length = length.to_i end days = (length / DAY).floor length = length % DAY if days > 0 hours = (length / HOUR).floor length = length % HOUR if hours > 0 minutes = (length / MINUTE).floor length = length % MINUTE if minutes > 0 seconds = length [days, hours, minutes, seconds, milliseconds] end