Class: Karafka::Pro::ScheduledMessages::Day
- Inherits:
-
Object
- Object
- Karafka::Pro::ScheduledMessages::Day
- 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
-
#created_at ⇒ Integer
readonly
Utc timestamp when this day object was created.
-
#ends_at ⇒ Integer
readonly
Equal to 23:59:59.
-
#starts_at ⇒ Integer
readonly
Utc timestamp when this day starts.
Instance Method Summary collapse
-
#ended? ⇒ Boolean
Did the current day we operate on ended.
-
#initialize ⇒ Day
constructor
A new instance of Day.
Constructor Details
#initialize ⇒ Day
Returns a new instance of Day.
29 30 31 32 33 34 35 36 |
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 29 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_at ⇒ Integer (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.
22 23 24 |
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 22 def created_at @created_at end |
#ends_at ⇒ Integer (readonly)
Equal to 23:59:59.
25 26 27 |
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 25 def ends_at @ends_at end |
#starts_at ⇒ Integer (readonly)
Returns utc timestamp when this day starts. Equal to 00:00:00.
27 28 29 |
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 27 def starts_at @starts_at end |
Instance Method Details
#ended? ⇒ Boolean
Returns did the current day we operate on ended.
39 40 41 |
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 39 def ended? @ends_at < Time.now.to_i end |