Module: Duckling::TZInfoCapabilities

Defined in:
lib/duckling/tzinfo_capabilities.rb

Overview

Which tz database reference_zone: resolves against, for the unknown-identifier error message. Behavioral because neither datasource exposes a version. Internal. See docs/tz-database-axis.md.

Class Method Summary collapse

Class Method Details

.backward_compat_links?Boolean

DataSourceNotFound does not inherit from InvalidTimezoneIdentifier; name it explicitly. A host with no database answers false.

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/duckling/tzinfo_capabilities.rb', line 14

def backward_compat_links?
  TZInfo::Timezone.get("US/Eastern")
  true
rescue TZInfo::InvalidTimezoneIdentifier, TZInfo::DataSourceNotFound
  false
end

.datasource_descriptionObject

Zoneinfo is detected by capability (a caller may install a subclass), the gem by class (loaded is not answered). Must not raise: it builds failure messages.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/duckling/tzinfo_capabilities.rb', line 30

def datasource_description
  source = begin
    TZInfo::DataSource.get
  rescue TZInfo::DataSourceNotFound
    return "no tz datasource (no zoneinfo files, no tzinfo-data gem)"
  end

  return "system zoneinfo at #{source.zoneinfo_dir}" if source.respond_to?(:zoneinfo_dir)

  if defined?(TZInfo::DataSources::RubyDataSource) && source.is_a?(TZInfo::DataSources::RubyDataSource)
    version = " (tzdata #{TZInfo::Data::Version::TZDATA})" if defined?(TZInfo::Data::Version::TZDATA)
    return "the tzinfo-data gem#{version}"
  end

  "the #{source.class} tz datasource"
end

.identifier_countObject



21
22
23
24
25
# File 'lib/duckling/tzinfo_capabilities.rb', line 21

def identifier_count
  TZInfo::Timezone.all_identifiers.size
rescue TZInfo::DataSourceNotFound
  0
end

.unknown_identifier_diagnosisObject

The remedy is phrased as a condition: only the database is checked. See docs/tz-database-axis.md.



49
50
51
52
53
54
55
56
57
# File 'lib/duckling/tzinfo_capabilities.rb', line 49

def unknown_identifier_diagnosis
  diagnosis = "resolved against #{datasource_description}, " \
    "which provides #{identifier_count} identifiers"
  return diagnosis if backward_compat_links?

  "#{diagnosis}; this database has no backward-compat names (US/Eastern and ~100 others), " \
    "so if that is what this is, it needs either the tzinfo-data gem or the " \
    "tzdata-legacy system package"
end