Class: VORuby::CoordinateSystems::StandardTime
- Inherits:
-
SpaceTime::TemporalPosition
- Object
- SpaceTime::TemporalPosition
- VORuby::CoordinateSystems::StandardTime
- Defined in:
- lib/voruby/spacetime/spacetime.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from SpaceTime::TemporalPosition
Instance Method Summary collapse
-
#+(time_s) ⇒ Object
Returns a StandardTime object projected forward the specified amount of time.
-
#-(time_s) ⇒ Object
Returns a StandardTime object projected backward the specified amount of time.
-
#<=>(time) ⇒ Object
Compare two StandardTimes.
- #==(time) ⇒ Object
-
#decrement(seconds) ⇒ Object
Subtract the specified number of seconds to the time.
-
#increment(seconds) ⇒ Object
Add the specified number of seconds to the time.
-
#initialize(time) ⇒ StandardTime
constructor
Create a StandardTime object from Ruby’s core Time object.
-
#to_local_s ⇒ Object
Returns an ISO 8601 compliant string representing the local time.
- #to_s ⇒ Object
-
#to_utc_s ⇒ Object
Returns an ISO 8601 compliant string representing the UTC time.
Constructor Details
#initialize(time) ⇒ StandardTime
Create a StandardTime object from Ruby’s core Time object.
87 88 89 90 91 |
# File 'lib/voruby/spacetime/spacetime.rb', line 87 def initialize(time) self.value = time super(self.value) end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
84 85 86 |
# File 'lib/voruby/spacetime/spacetime.rb', line 84 def value @value end |
Instance Method Details
#+(time_s) ⇒ Object
Returns a StandardTime object projected forward the specified amount of time. Input maybe be: 1) a decimal number of seconds 2) a string with a decimal number followed by a modifier specifying the unit.
The unit may be s = seconds, m = minutes, h = hours, d = days
i.e. 12.3h for 12.3 hours
135 136 137 138 139 |
# File 'lib/voruby/spacetime/spacetime.rb', line 135 def +(time_s) new_time = nil (time_s.kind_of?(Numeric))? new_time = self.value + time_s: new_time = self.value + extract_time(time_s) return StandardTime.new(new_time) end |
#-(time_s) ⇒ Object
Returns a StandardTime object projected backward the specified amount of time. Input maybe be: 1) a decimal number of seconds 2) a string with a decimal number followed by a modifier specifying the unit.
The unit may be s = seconds, m = minutes, h = hours, d = days
i.e. '12.3h' for 12.3 hours
152 153 154 155 156 |
# File 'lib/voruby/spacetime/spacetime.rb', line 152 def -(time_s) new_time = nil (time_s.kind_of?(Numeric))? new_time = self.value + time_s: new_time = self.value - extract_time(time_s) return StandardTime.new(new_time) end |
#<=>(time) ⇒ Object
Compare two StandardTimes. if timeA before timeB, returns -1 if timeA == timeB, returns 0 if timeA after timeB, returns 1
167 168 169 |
# File 'lib/voruby/spacetime/spacetime.rb', line 167 def <=>(time) self.value <=> time.value end |
#==(time) ⇒ Object
171 172 173 |
# File 'lib/voruby/spacetime/spacetime.rb', line 171 def ==(time) self.value.eql?(time.value) end |
#decrement(seconds) ⇒ Object
Subtract the specified number of seconds to the time.
159 160 161 |
# File 'lib/voruby/spacetime/spacetime.rb', line 159 def decrement(seconds) self.value = (self - seconds).value end |
#increment(seconds) ⇒ Object
Add the specified number of seconds to the time.
142 143 144 |
# File 'lib/voruby/spacetime/spacetime.rb', line 142 def increment(seconds) self.value = (self + seconds).value end |
#to_local_s ⇒ Object
Returns an ISO 8601 compliant string representing the local time.
104 105 106 107 108 109 110 |
# File 'lib/voruby/spacetime/spacetime.rb', line 104 def to_local_s utc_offset_hrs = self.value.getlocal.utc_offset / (60.0 * 60.0) utc_offset_min = ((utc_offset_hrs - utc_offset_hrs.floor) * 60.0).to_i utc_offset = sprintf("%+03d:%02d", utc_offset_hrs.floor, utc_offset_min) self.value.getlocal.strftime("%Y-%m-%dT%H:%M:%S#{utc_offset}") end |
#to_s ⇒ Object
175 176 177 |
# File 'lib/voruby/spacetime/spacetime.rb', line 175 def to_s self.to_utc_s end |
#to_utc_s ⇒ Object
Returns an ISO 8601 compliant string representing the UTC time.
99 100 101 |
# File 'lib/voruby/spacetime/spacetime.rb', line 99 def to_utc_s self.value.getutc.strftime("%Y-%m-%dT%H:%M:%SZ") end |