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 =

Array of weekdays as symbols from ActiveSupport

DateAndTime::Calculations::DAYS_INTO_WEEK.keys
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_durationObject

Calculates the timestamp based on either timestamp or duration methods



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zenaton/traits/with_timestamp.rb', line 28

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