Module: Webhookdb::WindowsTZ

Defined in:
lib/webhookdb/windows_tz.rb

Overview

Map Windows Timezone names to IANA names (and ActiveSupport timezones). Outlook calendar uses these timezones.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

._win_to_tzObject

Returns the value of attribute _win_to_tz.



7
8
9
# File 'lib/webhookdb/windows_tz.rb', line 7

def _win_to_tz
  @_win_to_tz
end

Class Method Details

.windows_name_to_tzHash<String => ActiveSupport::TimeZone>

Returns:

  • (Hash<String => ActiveSupport::TimeZone>)

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/webhookdb/windows_tz.rb', line 10

def windows_name_to_tz
  return self._win_to_tz if self._win_to_tz
  win_to_tz = {}
  self._win_to_tz = win_to_tz

  all_win_names = Set.new
  File.open(Webhookdb::DATA_DIR + "windows_tz.txt").each do |line|
    line.strip!
    next if line.blank? || line.start_with?("#")
    iana, win = line.split(/\s/, 2)
    next if win_to_tz.include?(win)
    all_win_names.add(win)
    tz = ActiveSupport::TimeZone[iana]
    next if tz.nil?
    win_to_tz[win] = tz
  end
  win_to_tz.each_key { |k| all_win_names.delete(k) }
  raise Webhookdb::InvariantViolation, "unmapped windows timezones: #{all_win_names.join(', ')}" unless
    all_win_names.empty?
  return win_to_tz
end