class TimeZoneScheduler::TimeFrame
@!visibility private
Assists in calculations regarding timeframes. It caches the results so the caller doesn’t need to worry about cost.
Public Class Methods
new(destination_time_zone, reference_time, timeframe)
click to toggle source
@param [ActiveSupport::TimeZone] destination_time_zone @param [Time] reference_time @param [Range<String..String>] timeframe
# File lib/time_zone_scheduler.rb, line 185 def initialize(destination_time_zone, reference_time, timeframe) @destination_time_zone, @reference_time, @timeframe = destination_time_zone, reference_time, timeframe end
Public Instance Methods
max()
click to toggle source
@return [Time]
the maximum time of the timeframe range in the destination time zone.
# File lib/time_zone_scheduler.rb, line 199 def max @max ||= @destination_time_zone.parse("#{local_date} #{@timeframe.max}") end
min()
click to toggle source
@return [Time]
the minimum time of the timeframe range in the destination time zone.
# File lib/time_zone_scheduler.rb, line 192 def min @min ||= @destination_time_zone.parse("#{local_date} #{@timeframe.min}") end
reference_after_timeframe?()
click to toggle source
@return [Boolean]
whether the reference time falls after the timeframe.
# File lib/time_zone_scheduler.rb, line 213 def reference_after_timeframe? local_time > max end
reference_before_timeframe?()
click to toggle source
@return [Boolean]
whether the reference time falls before the timeframe.
# File lib/time_zone_scheduler.rb, line 206 def reference_before_timeframe? local_time < min end
reference_in_timeframe?()
click to toggle source
@note First checks if the reference time falls before the timeframe, because if that fails {#max} never needs to
be performed for {TimeZoneScheduler#schedule_in_timeframe} to be able to perform its work.
@return [Boolean]
whether the reference time falls in the timeframe.
# File lib/time_zone_scheduler.rb, line 223 def reference_in_timeframe? !reference_before_timeframe? && !reference_after_timeframe? end
Private Instance Methods
local_date()
click to toggle source
@return [String]
the date of the reference time in the destination timezone.
# File lib/time_zone_scheduler.rb, line 239 def local_date @date ||= local_time.strftime('%F') end
local_time()
click to toggle source
@return [Time]
the reference time in the destination timezone.
# File lib/time_zone_scheduler.rb, line 232 def local_time @local_time ||= @reference_time.in_time_zone(@destination_time_zone) end