Class: Prdigest::Clock

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

Defined Under Namespace

Classes: Window

Instance Method Summary collapse

Constructor Details

#initialize(timezone:, now: -> { Time.now }) ⇒ Clock

Returns a new instance of Clock.



19
20
21
22
# File 'lib/prdigest/clock.rb', line 19

def initialize(timezone:, now: -> { Time.now })
  @timezone = TZInfo::Timezone.get(timezone)
  @now = now
end

Instance Method Details

#window(local_date) ⇒ Object



28
29
30
31
# File 'lib/prdigest/clock.rb', line 28

def window(local_date)
  date = Date.iso8601(local_date.to_s)
  Window.new(date, resolve_midnight(date), resolve_midnight(date + 1))
end

#yesterdayObject



24
25
26
# File 'lib/prdigest/clock.rb', line 24

def yesterday
  (@timezone.to_local(@now.call.utc).to_date - 1)
end