Class: TZInfo::DataSources::ZoneinfoDataSource

Inherits:
TZInfo::DataSource show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb

Overview

A DataSource implementation that loads data from a ‘zoneinfo’ directory containing compiled “TZif” version 3 (or earlier) files in addition to iso3166.tab and zone1970.tab or zone.tab index files.

To have TZInfo load the system zoneinfo files, call TZInfo::DataSource.set as follows:

TZInfo::DataSource.set(:zoneinfo)

To load zoneinfo files from a particular directory, pass the directory to TZInfo::DataSource.set:

TZInfo::DataSource.set(:zoneinfo, directory)

To load zoneinfo files from a particular directory, but load the iso3166.tab index file from a separate location, pass the directory and path to the iso3166.tab file to TZInfo::DataSource.set:

TZInfo::DataSource.set(:zoneinfo, directory, iso3166_path)

Please note that versions of the ‘zic’ tool (used to build zoneinfo files) that were released prior to February 2006 created zoneinfo files that used 32-bit integers for transition timestamps. Later versions of zic produce zoneinfo files that use 64-bit integers. If you have 32-bit zoneinfo files on your system, then any queries falling outside of the range 1901-12-13 20:45:52 to 2038-01-19 03:14:07 may be inaccurate.

Most modern platforms include 64-bit zoneinfo files. However, Mac OS X (up to at least 10.8.4) still uses 32-bit zoneinfo files.

To check whether your zoneinfo files contain 32-bit or 64-bit transition data, you can run the following code (substituting the identifier of the zone you want to test for ‘zone_identifier`):

TZInfo::DataSource.set(:zoneinfo)
dir = TZInfo::DataSource.get.zoneinfo_dir
File.open(File.join(dir, zone_identifier), 'r') {|f| f.read(5) }

If the last line returns ‘“TZif\x00”`, then you have a 32-bit zoneinfo file. If it returns `“TZif2”` or `“TZif3”` then you have a 64-bit zoneinfo file.

It is also worth noting that as of the 2017c release of the IANA Time Zone Database, 64-bit zoneinfo files only include future transitions up to 2038-01-19 03:14:07. Any queries falling after this time may be inaccurate.

Constant Summary collapse

@@search_path =

Paths to be checked to find the system zoneinfo directory.

DEFAULT_SEARCH_PATH.dup
@@alternate_iso3166_tab_search_path =

Paths to possible alternate iso3166.tab files (used to locate the system-wide iso3166.tab files on FreeBSD and OpenBSD).

DEFAULT_ALTERNATE_ISO3166_TAB_SEARCH_PATH.dup

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TZInfo::DataSource

#eager_load!, get, #get_country_info, #get_timezone_info, set, #timezone_identifiers

Constructor Details

#initialize(zoneinfo_dir = nil, alternate_iso3166_tab_path = nil) ⇒ ZoneinfoDataSource

Initializes a new TZInfo::DataSources::ZoneinfoDataSource.

If ‘zoneinfo_dir` is specified, it will be checked and used as the source of zoneinfo files.

The directory must contain a file named iso3166.tab and a file named either zone1970.tab or zone.tab. These may either be included in the root of the directory or in a ‘tab’ sub-directory and named country.tab and zone_sun.tab respectively (as is the case on Solaris).

Additionally, the path to iso3166.tab can be overridden using the ‘alternate_iso3166_tab_path` parameter.

If ‘zoneinfo_dir` is not specified or `nil`, the paths referenced in search_path are searched in order to find a valid zoneinfo directory (one that contains zone1970.tab or zone.tab and iso3166.tab files as above).

The paths referenced in alternate_iso3166_tab_search_path are also searched to find an iso3166.tab file if one of the searched zoneinfo directories doesn’t contain an iso3166.tab file.

Parameters:

  • zoneinfo_dir (String) (defaults to: nil)

    an optional path to a directory to use as the source of zoneinfo files.

  • alternate_iso3166_tab_path (String) (defaults to: nil)

    an optional path to the iso3166.tab file.

Raises:

  • (InvalidZoneinfoDirectory)

    if the iso3166.tab and zone1970.tab or zone.tab files cannot be found using the ‘zoneinfo_dir` and `alternate_iso3166_tab_path` parameters.

  • (ZoneinfoDirectoryNotFound)

    if no valid directory can be found by searching.



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 241

def initialize(zoneinfo_dir = nil, alternate_iso3166_tab_path = nil)
  super()

  if zoneinfo_dir
    iso3166_tab_path, zone_tab_path = validate_zoneinfo_dir(zoneinfo_dir, alternate_iso3166_tab_path)

    unless iso3166_tab_path && zone_tab_path
      raise InvalidZoneinfoDirectory, "#{zoneinfo_dir} is not a directory or doesn't contain a iso3166.tab file and a zone1970.tab or zone.tab file."
    end

    @zoneinfo_dir = zoneinfo_dir
  else
    @zoneinfo_dir, iso3166_tab_path, zone_tab_path = find_zoneinfo_dir

    unless @zoneinfo_dir && iso3166_tab_path && zone_tab_path
      raise ZoneinfoDirectoryNotFound, "None of the paths included in #{self.class.name}.search_path are valid zoneinfo directories."
    end
  end

  @zoneinfo_dir = File.expand_path(@zoneinfo_dir).freeze
  @timezone_identifiers = load_timezone_identifiers.freeze
  @countries = load_countries(iso3166_tab_path, zone_tab_path).freeze
  @country_codes = @countries.keys.sort!.freeze

  string_deduper = ConcurrentStringDeduper.new
  posix_tz_parser = PosixTimeZoneParser.new(string_deduper)
  @zoneinfo_reader = ZoneinfoReader.new(posix_tz_parser, string_deduper)
end

Instance Attribute Details

#country_codesArray<String> (readonly)

Returns a frozen ‘Array` of all the available ISO 3166-1 alpha-2 country codes. The identifiers are sorted according to `String#<=>`.

Returns:

  • (Array<String>)

    a frozen ‘Array` of all the available ISO 3166-1 alpha-2 country codes.



208
209
210
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 208

def country_codes
  @country_codes
end

#zoneinfo_dirString (readonly)

Returns the zoneinfo directory being used.

Returns:

  • (String)

    the zoneinfo directory being used.



205
206
207
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 205

def zoneinfo_dir
  @zoneinfo_dir
end

Class Method Details

.alternate_iso3166_tab_search_pathArray<String>

An ‘Array` of paths that will be checked to find an alternate iso3166.tab file if one was not included in the zoneinfo directory (for example, on FreeBSD and OpenBSD systems).

Paths are checked in the order they appear in the ‘Array`.

The default value is ‘[’/usr/share/misc/iso3166.tab’, ‘/usr/share/misc/iso3166’]‘.

Returns:

  • (Array<String>)

    an ‘Array` of paths to check in order to locate an iso3166.tab file.



160
161
162
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 160

def alternate_iso3166_tab_search_path
  @@alternate_iso3166_tab_search_path
end

.alternate_iso3166_tab_search_path=(alternate_iso3166_tab_search_path) ⇒ Object

Sets the paths to check to locate an alternate iso3166.tab file if one was not included in the zoneinfo directory.

Can be set to an ‘Array` of paths or a `String` containing paths separated with `File::PATH_SEPARATOR`.

Paths are checked in the order they appear in the array.

Set to ‘nil` to revert to the default paths.

Parameters:

  • alternate_iso3166_tab_search_path (Object)

    either ‘nil` or a list of paths to check as either an `Array` of `String` or a `File::PATH_SEPARATOR` separated `String`.



177
178
179
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 177

def alternate_iso3166_tab_search_path=(alternate_iso3166_tab_search_path)
  @@alternate_iso3166_tab_search_path = process_search_path(alternate_iso3166_tab_search_path, DEFAULT_ALTERNATE_ISO3166_TAB_SEARCH_PATH)
end

.search_pathArray<String>

An ‘Array` of directories that will be checked to find the system zoneinfo directory.

Directories are checked in the order they appear in the ‘Array`.

The default value is ‘[’/usr/share/zoneinfo’, ‘/usr/share/lib/zoneinfo’, ‘/etc/zoneinfo’]‘.

Returns:

  • (Array<String>)

    an ‘Array` of directories to check in order to find the system zoneinfo directory.



127
128
129
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 127

def search_path
  @@search_path
end

.search_path=(search_path) ⇒ Object

Sets the directories to be checked when locating the system zoneinfo directory.

Can be set to an ‘Array` of directories or a `String` containing directories separated with `File::PATH_SEPARATOR`.

Directories are checked in the order they appear in the ‘Array` or `String`.

Set to ‘nil` to revert to the default paths.

Parameters:

  • search_path (Object)

    either ‘nil` or a list of directories to check as either an `Array` of `String` or a `File::PATH_SEPARATOR` separated `String`.



145
146
147
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 145

def search_path=(search_path)
  @@search_path = process_search_path(search_path, DEFAULT_SEARCH_PATH)
end

Instance Method Details

#data_timezone_identifiersArray<String>

Returns a frozen ‘Array` of all the available time zone identifiers. The identifiers are sorted according to `String#<=>`.

Returns:

  • (Array<String>)

    a frozen ‘Array` of all the available time zone identifiers.



275
276
277
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 275

def data_timezone_identifiers
  @timezone_identifiers
end

#inspectString

Returns the internal object state as a programmer-readable ‘String`.

Returns:

  • (String)

    the internal object state as a programmer-readable ‘String`.



294
295
296
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 294

def inspect
  "#<#{self.class}: #{@zoneinfo_dir}>"
end

#linked_timezone_identifiersArray<String>

Returns an empty ‘Array`. There is no information about linked/aliased time zones in the zoneinfo files. When using TZInfo::DataSources::ZoneinfoDataSource, every time zone will be returned as a TZInfo::DataTimezone.

Returns:



284
285
286
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 284

def linked_timezone_identifiers
  [].freeze
end

#to_sString

Returns a description of the TZInfo::DataSource.

Returns:



289
290
291
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/zoneinfo_data_source.rb', line 289

def to_s
  "Zoneinfo DataSource: #{@zoneinfo_dir}"
end