Class: Kaal::SchedulerTimeZoneResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/kaal/config/scheduler_time_zone_resolver.rb,
sig/kaal/config/scheduler_time_zone_resolver.rbs

Overview

Resolves the configured scheduler time zone, preferring explicit config.

Constant Summary collapse

DEFAULT_TIME_ZONE =

Returns:

  • ("UTC")
'UTC'

Instance Method Summary collapse

Constructor Details

#initialize(configuration:) ⇒ SchedulerTimeZoneResolver

Returns a new instance of SchedulerTimeZoneResolver.

Parameters:

  • configuration: (Kaal::rbs_any)


14
15
16
# File 'lib/kaal/config/scheduler_time_zone_resolver.rb', line 14

def initialize(configuration:)
  @configuration = configuration
end

Instance Method Details

#configured_time_zone ⇒ Kaal::rbs_any

Returns:

  • (Kaal::rbs_any)


29
30
31
32
33
34
35
36
37
# File 'lib/kaal/config/scheduler_time_zone_resolver.rb', line 29

def configured_time_zone
  value = normalized_time_zone_value
  return nil if value.empty?

  TZInfo::Timezone.get(value)
  value
rescue TZInfo::InvalidTimezoneIdentifier
  raise ConfigurationError, "Invalid time_zone configuration: #{raw_time_zone_value.inspect} (normalized: #{value.inspect})"
end

#normalized_time_zone_value ⇒ Kaal::rbs_any

Returns:

  • (Kaal::rbs_any)


39
40
41
42
43
44
# File 'lib/kaal/config/scheduler_time_zone_resolver.rb', line 39

def normalized_time_zone_value
  value = raw_time_zone_value
  return DEFAULT_TIME_ZONE if value.casecmp?(DEFAULT_TIME_ZONE)

  value
end

#raw_time_zone_value ⇒ Kaal::rbs_any

Returns:

  • (Kaal::rbs_any)


46
47
48
# File 'lib/kaal/config/scheduler_time_zone_resolver.rb', line 46

def raw_time_zone_value
  @configuration.time_zone.to_s.strip
end

#time_zone_identifier ⇒ Kaal::rbs_any

Returns:

  • (Kaal::rbs_any)


18
19
20
21
22
23
24
25
# File 'lib/kaal/config/scheduler_time_zone_resolver.rb', line 18

def time_zone_identifier
  zone = begin
    Time.zone
  rescue NoMethodError
    nil
  end
  configured_time_zone || zone&.tzinfo&.identifier || DEFAULT_TIME_ZONE
end