class GovukError::GovukDataSync
Attributes
from[R]
to[R]
Public Class Methods
new(govuk_data_sync_period)
click to toggle source
# File lib/govuk_app_config/govuk_error/govuk_data_sync.rb, line 13 def initialize(govuk_data_sync_period) return if govuk_data_sync_period.nil? parts = govuk_data_sync_period.split("-") raise MalformedDataSyncPeriod, govuk_data_sync_period unless parts.count == 2 @from, @to = parts.map { |time| Time.parse(time) } rescue ArgumentError raise MalformedDataSyncPeriod, govuk_data_sync_period end
Public Instance Methods
in_progress?()
click to toggle source
# File lib/govuk_app_config/govuk_error/govuk_data_sync.rb, line 24 def in_progress? !from.nil? && !to.nil? && in_time_range?(from, to) end
Private Instance Methods
in_time_range?(from, to)
click to toggle source
`from`/`to` times are in relation to the local server time, which is expected to be in UTC as per: github.com/alphagov/govuk-puppet/blob/b588e4ade996e97b8975e69cb00800521fff4a48/modules/govuk_envsys/files/etc/environment#L3
# File lib/govuk_app_config/govuk_error/govuk_data_sync.rb, line 32 def in_time_range?(from, to) hour_is_in_range = Time.now.hour >= from.hour || Time.now.hour <= to.hour minute_is_in_range = if Time.now.hour == from.hour Time.now.min >= from.min elsif Time.now.hour == to.hour Time.now.min <= to.min else true end hour_is_in_range && minute_is_in_range end