# frozen_string_literal: true # @api private # @since 0.1.0 class Sidekiq::Portal::Timeline require_relative 'timeline/builder' # @param initial_time [Time] # @param timezoner [ActiveSupport::TimeZone] # @param time_plan [Fugit::Duration, Fugit::Cron] # @return [void] # # @api private # @since 0.1.0 def initialize(initial_time, timezoner, time_plan) @timezoner = timezoner @time_plan = time_plan @internal_time = initial_time @lock = Sidekiq::Portal::Lock.new end # @return [void] # # @api private # @since 0.1.0 def actualize_time! @internal_time = next_time_point end # @return [Time] # # @api private # @since 0.1.0 def current_time_point thread_safe { timezoner.at(internal_time) } end # @return [Time] # # @api private # @since 0.1.0 def next_time_point thread_safe { timezoner.at(time_plan.next_time(current_time_point).seconds) } end # @param target_time [Time] # @return [Array