Class: Time

Inherits:
Object show all
Defined in:
lib/eac_ruby_utils/patches/time/local_time_zone.rb

Constant Summary collapse

TIMEDATECTL_TIMEZONE_LINE_PATTERN =
%r{\s*Time zone:\s*(\S+/\S+)\s}.freeze

Class Method Summary collapse

Class Method Details

.local_time_zoneObject



10
11
12
# File 'lib/eac_ruby_utils/patches/time/local_time_zone.rb', line 10

def local_time_zone
  local_time_zone_by_timedatectl || local_time_zone_by_offset
end

.local_time_zone_by_offsetObject



21
22
23
# File 'lib/eac_ruby_utils/patches/time/local_time_zone.rb', line 21

def local_time_zone_by_offset
  ::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset].name
end

.local_time_zone_by_timedatectlObject



14
15
16
17
18
19
# File 'lib/eac_ruby_utils/patches/time/local_time_zone.rb', line 14

def local_time_zone_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] }
end