Class: DynamicTimeZone::TimeZoneDataSource

Inherits:
TZInfo::DataSources::ZoneinfoDataSource
  • Object
show all
Defined in:
lib/dynamic_time_zone/time_zone_data_source.rb

Instance Method Summary collapse

Instance Method Details

#load_timezone_info(identifier) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dynamic_time_zone/time_zone_data_source.rb', line 5

def load_timezone_info(identifier)
  return super unless DynamicTimeZone.enabled

  pattern_matches = identifier.scan(DynamicTimeZone::REGEX_PATTERN).last
  return super if pattern_matches.nil?

  sign, offset_amount = pattern_matches
  offset_amount = offset_amount.to_i
  offset_amount = 0 - offset_amount if sign == '-'

  offset = TZInfo::TimezoneOffset.new(offset_amount, 0, 'DynamicTimeZone')
  timezone_info = TZInfo::DataSources::ConstantOffsetDataTimezoneInfo.new(identifier, offset)
  timezone_info
end