Class: RSMP::Clock
- Inherits:
-
Object
- Object
- RSMP::Clock
- Defined in:
- lib/rsmp/helpers/clock.rb
Overview
Get the current time in UTC, with optional adjustment. Conversion to string uses the RSMP format 2015-06-08T12:01:39.654Z Use ‘Clock.to_s` to format times in RSMP format.
Instance Attribute Summary collapse
-
#adjustment ⇒ Object
readonly
Returns the value of attribute adjustment.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Clock
constructor
A new instance of Clock.
- #now ⇒ Object
- #reset ⇒ Object
- #set(target) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Clock
Returns a new instance of Clock.
10 11 12 |
# File 'lib/rsmp/helpers/clock.rb', line 10 def initialize @adjustment = 0 end |
Instance Attribute Details
#adjustment ⇒ Object (readonly)
Returns the value of attribute adjustment.
8 9 10 |
# File 'lib/rsmp/helpers/clock.rb', line 8 def adjustment @adjustment end |
Class Method Details
.now ⇒ Object
30 31 32 |
# File 'lib/rsmp/helpers/clock.rb', line 30 def self.now Time.now.utc end |
.parse(str) ⇒ Object
38 39 40 |
# File 'lib/rsmp/helpers/clock.rb', line 38 def self.parse(str) Time.parse(str) end |
.to_s(time = nil) ⇒ Object
34 35 36 |
# File 'lib/rsmp/helpers/clock.rb', line 34 def self.to_s(time = nil) (time || now).strftime('%FT%T.%3NZ') end |
Instance Method Details
#now ⇒ Object
22 23 24 |
# File 'lib/rsmp/helpers/clock.rb', line 22 def now Time.now.utc + @adjustment end |
#reset ⇒ Object
18 19 20 |
# File 'lib/rsmp/helpers/clock.rb', line 18 def reset @adjustment = 0 end |
#set(target) ⇒ Object
14 15 16 |
# File 'lib/rsmp/helpers/clock.rb', line 14 def set(target) @adjustment = target - Time.now end |