Class: RelativeTime
- Inherits:
-
Object
- Object
- RelativeTime
- Defined in:
- lib/classad.rb
Overview
Wrapper for Ruby “seconds” variable so ClassAd knows this is a relTime and can write the xml appropriately
Instance Method Summary collapse
-
#initialize(t) ⇒ RelativeTime
constructor
A new instance of RelativeTime.
- #to_s ⇒ Object
Constructor Details
#initialize(t) ⇒ RelativeTime
Returns a new instance of RelativeTime.
29 30 31 |
# File 'lib/classad.rb', line 29 def initialize(t) @time = t end |
Instance Method Details
#to_s ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/classad.rb', line 33 def to_s str = '' nonzero = false left = @time if @time < 0 str << '-' left = -@time end days = (left / (24*60*60)).to_i left = left % (24*60*60) unless days.zero? str << days.to_i.to_s << '+' nonzero = true end hours = (left / (60*60)).to_i left = left % (60*60) if (not hours.zero?) or nonzero if nonzero and (hours < 10) str << "0" end str << hours.to_i.to_s << ':' nonzero = true end minutes = (left / 60).to_i left = left % 60 if (not minutes.zero?) or nonzero if nonzero and (minutes < 10) str << "0" end str << minutes.to_i.to_s << ":" nonzero = true end seconds = left.to_i mseconds = ((left - seconds) * 1000).to_i if nonzero and (seconds < 10) str << "0" end str << seconds.to_s unless mseconds.zero? str << "." if mseconds < 100 str << "0" if mseconds < 10 str << "0" end end str << mseconds.to_s end return str end |