Module: LogStash::PluginMixins::Jdbc::TimezoneProxy

Defined in:
lib/logstash/plugin_mixins/jdbc/timezone_proxy.rb

Overview

This ‘TimezoneProxy` allows timezone specs to include extensions indicating preference for ambiguous handling.

See Also:

  • TimezoneProxy::parse

Defined Under Namespace

Modules: JDBCTimezoneSpecValidator Classes: PeriodForLocalWithDSTPreference

Class Method Summary collapse

Class Method Details

.load(timezone_spec) ⇒ TZInfo::Timezone

Parameters:

  • timezone_spec (String)

    : a timezone spec, consisting of any valid timezone identifier followed by square-bracketed extensions. Currently-supported extensions are: ‘dst_enabled_on_overlap:(true|false)`: when encountering an ambiguous time

    due to daylight-savings transition,
    assume DST to be either enabled or
    disabled instead of raising an
    AmbiguousTime exception
    

Returns:

  • (TZInfo::Timezone)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/logstash/plugin_mixins/jdbc/timezone_proxy.rb', line 20

def self.load(timezone_spec)
  # re-load pass-through
  return timezone_spec if timezone_spec.kind_of?(::TZInfo::Timezone)

  parsed_spec = /\A(?<name>[^\[]+)(\[(?<extensions>[^\]]*)\])?\z/.match(timezone_spec)

  timezone = ::TZInfo::Timezone.get(parsed_spec[:name])
  return timezone unless parsed_spec[:extensions]

  parsed_spec[:extensions].split(';').each do |extension_spec|
    timezone = case extension_spec
               when 'dst_enabled_on_overlap:true'  then timezone.dup.extend(PeriodForLocalWithDSTPreference::ON)
               when 'dst_enabled_on_overlap:false' then timezone.dup.extend(PeriodForLocalWithDSTPreference::OFF)
               else fail(ArgumentError, "Invalid timezone extension `#{extension_spec}`")
               end
  end

  timezone
end