module EacRubyUtils::LocalTimeZone
Constants
- DEBIAN_CONFIG_PATH
- TIMEDATECTL_TIMEZONE_LINE_PATTERN
Public Class Methods
auto()
click to toggle source
@return [ActiveSupport::TimeZone]
# File lib/eac_ruby_utils/local_time_zone.rb, line 14 def auto %w[tz_env debian_config offset].lazy.map { |s| send("by_#{s}") }.find(&:present?) end
auto_set()
click to toggle source
# File lib/eac_ruby_utils/local_time_zone.rb, line 18 def auto_set ::Time.zone = auto end
by_debian_config()
click to toggle source
@return [ActiveSupport::TimeZone]
# File lib/eac_ruby_utils/local_time_zone.rb, line 23 def by_debian_config path = ::Pathname.new(DEBIAN_CONFIG_PATH) path.exist? ? path.read.strip.if_present { |v| ::ActiveSupport::TimeZone[v] } : nil end
by_offset()
click to toggle source
@return [ActiveSupport::TimeZone]
# File lib/eac_ruby_utils/local_time_zone.rb, line 29 def by_offset ::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset] end
by_timedatectl()
click to toggle source
@return [ActiveSupport::TimeZone]
# File lib/eac_ruby_utils/local_time_zone.rb, line 34 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
by_tz_env()
click to toggle source
@return [ActiveSupport::TimeZone]
# File lib/eac_ruby_utils/local_time_zone.rb, line 43 def by_tz_env ENV['TZ'].presence end