Class: Necropsy::Clock

Inherits:
Object
  • Object
show all
Defined in:
lib/necropsy/clock.rb

Constant Summary collapse

SOURCE_DATE_EPOCH =
'SOURCE_DATE_EPOCH'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(as_of: nil, environment: ENV, now: nil) ⇒ Clock

Returns a new instance of Clock.



11
12
13
14
15
# File 'lib/necropsy/clock.rb', line 11

def initialize(as_of: nil, environment: ENV, now: nil)
  @time = resolve_time(as_of, environment, now).utc.freeze
rescue ArgumentError, TypeError, RangeError
  raise Error, 'as-of time and SOURCE_DATE_EPOCH must identify a valid date'
end

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



9
10
11
# File 'lib/necropsy/clock.rb', line 9

def time
  @time
end

Instance Method Details

#dateObject



17
18
19
# File 'lib/necropsy/clock.rb', line 17

def date
  time.to_date
end