Sha256: 5003c0969b27c067b321e4e36558cfdb4c578467082423d98eb1765476f27f01

Contents?: true

Size: 701 Bytes

Versions: 110

Compression:

Stored size: 701 Bytes

Contents

# frozen_string_literal: true

require 'active_support/core_ext/time/zones'
require 'eac_ruby_utils/envs'

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

    def local_time_zone
      local_time_zone_by_timedatectl || local_time_zone_by_offset
    end

    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

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

Version data entries

110 entries across 110 versions & 3 rubygems

Version Path
avm-tools-0.87.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
eac_ruby_utils-0.57.1 lib/eac_ruby_utils/patches/time/local_time_zone.rb
eac_ruby_utils-0.57.0 lib/eac_ruby_utils/patches/time/local_time_zone.rb
ehbrs-tools-0.17.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
avm-tools-0.86.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
avm-tools-0.85.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
eac_ruby_utils-0.56.2 lib/eac_ruby_utils/patches/time/local_time_zone.rb
avm-tools-0.85.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
eac_ruby_utils-0.56.1 lib/eac_ruby_utils/patches/time/local_time_zone.rb
ehbrs-tools-0.16.5 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
avm-tools-0.84.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
eac_ruby_utils-0.56.0 lib/eac_ruby_utils/patches/time/local_time_zone.rb
avm-tools-0.83.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
ehbrs-tools-0.16.4 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
avm-tools-0.82.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
avm-tools-0.82.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
avm-tools-0.81.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
ehbrs-tools-0.16.3 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
eac_ruby_utils-0.55.0 lib/eac_ruby_utils/patches/time/local_time_zone.rb
avm-tools-0.80.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb