Module: Zenaton::Traits::WithTimestamp

Extended by:
ActiveSupport::Concern
Includes:
WithDuration
Included in:
Zenaton::Tasks::Wait
Defined in:
lib/zenaton/traits/with_timestamp.rb

Overview

Module to calculate unix timestamps for events

Constant Summary collapse

WEEKDAYS =
%i[monday
tuesday
wednesday
thursday
friday
saturday
sunday].freeze
MODE_AT =

When specifying a time

'AT'
MODE_WEEK_DAY =

When specifying a day of the week

'WEEK_DAY'
MODE_MONTH_DAY =

When specifying a day of the month

'MONTH_DAY'
MODE_TIMESTAMP =

When specifying a unix timestamp

'TIMESTAMP'

Instance Method Summary collapse

Methods included from WithDuration

#_get_duration

Instance Method Details

#_get_timestamp_or_durationArray<Integer, NilClass>

Calculates the timestamp based on either timestamp or duration methods

Returns:

  • (Array<Integer, NilClass>)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/zenaton/traits/with_timestamp.rb', line 33

def _get_timestamp_or_duration
  return [nil, nil] unless @buffer

  now, now_dup = _init_now_then
  @_mode = nil
  @buffer.each do |time_unit, time_value|
    now_dup = _apply(time_unit, time_value, now, now_dup)
  end
  return [nil, diff_in_seconds(now, now_dup)] if @_mode.nil?

  [now_dup.to_i, nil]
end