Class: Karafka::Pro::ScheduledMessages::Day

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/pro/scheduled_messages/day.rb

Overview

Just a simple UTC day implementation. Since we operate on a scope of one day, this allows us to encapsulate when given day ends

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDay

Initializes a day representation for the current UTC day



47
48
49
50
51
52
53
54
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 47

def initialize
  @created_at = Time.now.to_i

  time = Time.at(@created_at).utc

  @starts_at = Time.utc(time.year, time.month, time.day).to_i
  @ends_at = @starts_at + 86_399
end

Instance Attribute Details

#created_atInteger (readonly)

Returns utc timestamp when this day object was created. Keep in mind, that this is not when the day started but when this object was created.

Returns:

  • (Integer)

    utc timestamp when this day object was created. Keep in mind, that this is not when the day started but when this object was created.



39
40
41
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 39

def created_at
  @created_at
end

#ends_atInteger (readonly)

Equal to 23:59:59.

Returns:

  • (Integer)

    utc timestamp when this day ends (last second of day).



42
43
44
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 42

def ends_at
  @ends_at
end

#starts_atInteger (readonly)

Returns utc timestamp when this day starts. Equal to 00:00:00.

Returns:

  • (Integer)

    utc timestamp when this day starts. Equal to 00:00:00



44
45
46
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 44

def starts_at
  @starts_at
end

Instance Method Details

#ended?Boolean

Returns did the current day we operate on ended.

Returns:

  • (Boolean)

    did the current day we operate on ended.



57
58
59
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 57

def ended?
  @ends_at < Time.now.to_i
end