<commit_before>module IceCube

  class WeeklyRule < ValidatedRule

    include Validations::WeeklyInterval

    attr_reader :week_start

    def initialize(interval = 1, week_start = :sunday)
      super(interval)
      interval(interval, week_start)
      schedule_lock(:wday, :hour, :min, :sec)
      reset
    end

    # Calculate the effective start time for when the given start time is later
    # in the week than one of the weekday validations, such that times could be
    # missed by a 7-day jump using the weekly interval, or when selecting from a
    # date that is misaligned from the schedule interval.
    #
    def realign(step_time, start_time)
      time = TimeUtil::TimeWrapper.new(start_time)
      offset = wday_offset(step_time, start_time)
      time.add(:day, offset) if offset
      time.to_time
    end

    def wday_offset(step_time, start_time)
      wday_validations = other_interval_validations.select { |v| v.type == :wday }
      return if wday_validations.none?

      days = (step_time - start_time).to_i / ONE_DAY
      interval = base_interval_validation.validate(step_time, start_time).to_i
      min_wday = TimeUtil.normalize_wday(wday_validations.min_by(&:day).day, week_start)
      step_wday = TimeUtil.normalize_wday(step_time.wday, week_start)

      days + interval - step_wday + min_wday
    end

  end

end<commit_msg>Refactor: depend on consistent type<commit_after>module IceCube

  class WeeklyRule < ValidatedRule

    include Validations::WeeklyInterval

    attr_reader :week_start

    def initialize(interval = 1, week_start = :sunday)
      super(interval)
      interval(interval, week_start)
      schedule_lock(:wday, :hour, :min, :sec)
      reset
    end

    # Calculate the effective start time for when the given start time is later
    # in the week than one of the weekday validations, such that times could be
    # missed by a 7-day jump using the weekly interval, or when selecting from a
    # date that is misaligned from the schedule interval.
    #
    def realign(step_time, start_time)
      time = TimeUtil::TimeWrapper.new(start_time)
      offset = wday_offset(step_time, start_time)
      time.add(:day, offset)
      time.to_time
    end

    def wday_offset(step_time, start_time)
      wday_validations = other_interval_validations.select { |v| v.type == :wday }
      return 0 if wday_validations.none?

      days = (step_time - start_time).to_i / ONE_DAY
      interval = base_interval_validation.validate(step_time, start_time).to_i
      min_wday = TimeUtil.normalize_wday(wday_validations.min_by(&:day).day, week_start)
      step_wday = TimeUtil.normalize_wday(step_time.wday, week_start)

      days + interval - step_wday + min_wday
    end

  end

end
{'fraction_non_alphanumeric': 0.07476294675419402, 'fraction_numerical': 0.0018234865061998542, 'mean_word_length': 3.3401898734177213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6592374', 'n_tokens_mistral': 879, 'n_tokens_neox': 849, 'n_words': 236}