debian-mirror-gitlab/app/models/ci/freeze_period_status.rb

32 lines
792 B
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Ci
class FreezePeriodStatus
attr_reader :project
def initialize(project:)
@project = project
end
def execute
project.freeze_periods.any? { |period| within_freeze_period?(period) }
end
def within_freeze_period?(period)
2022-10-11 01:57:18 +05:30
start_freeze_cron = Gitlab::Ci::CronParser.new(period.freeze_start, period.cron_timezone)
end_freeze_cron = Gitlab::Ci::CronParser.new(period.freeze_end, period.cron_timezone)
2020-05-24 23:13:21 +05:30
2022-10-11 01:57:18 +05:30
start_freeze = start_freeze_cron.previous_time_from(time_zone_now)
end_freeze = end_freeze_cron.next_time_from(start_freeze)
2020-05-24 23:13:21 +05:30
2022-10-11 01:57:18 +05:30
start_freeze <= time_zone_now && time_zone_now <= end_freeze
2020-05-24 23:13:21 +05:30
end
2022-10-11 01:57:18 +05:30
private
2020-05-24 23:13:21 +05:30
def time_zone_now
@time_zone_now ||= Time.zone.now
end
end
end