module EacRubyUtils::LocalTimeZone
def auto
-
(ActiveSupport::TimeZone)-
def auto %w[tz_env debian_config offset].lazy.map { |s| send("by_#{s}") }.find(&:present?) end
def auto_set
def auto_set ::Time.zone = auto end
def by_debian_config
-
(ActiveSupport::TimeZone)-
def by_debian_config path = ::Pathname.new(DEBIAN_CONFIG_PATH) path.exist? ? path.read.strip.if_present { |v| ::ActiveSupport::TimeZone[v] } : nil end
def by_offset
-
(ActiveSupport::TimeZone)-
def by_offset ::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset] end
def by_timedatectl
-
(ActiveSupport::TimeZone)-
def by_timedatectl executable = ::EacRubyUtils::Envs.local.executable('timedatectl', '--version') return nil unless executable.exist? TIMEDATECTL_TIMEZONE_LINE_PATTERN.if_match(executable.command.execute!) { |m| m[1] } .if_present { |v| ::ActiveSupport::TimeZone[v] } end
def by_tz_env
-
(ActiveSupport::TimeZone)-
def by_tz_env ENV['TZ'].presence end