Sha256: de6eb9dfdf526ed7d6008cb6092ea03c33349306db50a5f57377e455c6b89b70
Contents?: true
Size: 1.22 KB
Versions: 6
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module Facter module Resolvers module Windows class Timezone < BaseResolver init_resolver class << self private def post_resolve(fact_name, _options) @fact_list.fetch(fact_name) { determine_timezone } end def determine_timezone timezone = Time.now.zone @fact_list[:timezone] = timezone.force_encoding("CP#{codepage}").encode('UTF-8', invalid: :replace) rescue ArgumentError @fact_list[:timezone] = timezone end def codepage result = codepage_from_api result&.empty? ? codepage_from_registry : result end def codepage_from_registry require 'win32/registry' ::Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Nls\CodePage')['ACP'] end def codepage_from_api require_relative '../../../facter/resolvers/windows/ffi/winnls_ffi' WinnlsFFI.GetACP.to_s rescue LoadError => e log = Facter::Log.new(self) log.debug("Could not retrieve codepage: #{e}") end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems