Class: Nem::Unit::Time
- Inherits:
-
Object
- Object
- Nem::Unit::Time
- Defined in:
- lib/nem/unit/time.rb
Constant Summary collapse
- NEM_EPOCH =
::Time.utc(2015, 3, 29, 0, 6, 25, 0)
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
-
#initialize(value) ⇒ Time
constructor
A new instance of Time.
- #to_i ⇒ Object
- #to_time ⇒ Object
Constructor Details
#initialize(value) ⇒ Time
Returns a new instance of Time.
6 7 8 |
# File 'lib/nem/unit/time.rb', line 6 def initialize(value) @value = value end |
Class Method Details
.new_from_nemtime(nemtime) ⇒ Object
34 35 36 |
# File 'lib/nem/unit/time.rb', line 34 def self.new_from_nemtime(nemtime) new(NEM_EPOCH + nemtime) end |
.now ⇒ Object
30 31 32 |
# File 'lib/nem/unit/time.rb', line 30 def self.now new(::Time.now.utc) end |
.parse(datetime) ⇒ Object
26 27 28 |
# File 'lib/nem/unit/time.rb', line 26 def self.parse(datetime) new(::Time.parse(datetime)) end |
Instance Method Details
#+(other) ⇒ Object
10 11 12 |
# File 'lib/nem/unit/time.rb', line 10 def +(other) self.class.new(@value + other) end |
#-(other) ⇒ Object
14 15 16 |
# File 'lib/nem/unit/time.rb', line 14 def -(other) self.class.new(@value - other) end |
#to_i ⇒ Object
18 19 20 |
# File 'lib/nem/unit/time.rb', line 18 def to_i (@value - NEM_EPOCH).to_i end |
#to_time ⇒ Object
22 23 24 |
# File 'lib/nem/unit/time.rb', line 22 def to_time @value.to_time end |