TimezoneParser 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ require 'cldr'
3
3
  require 'cldr/download'
4
4
  require 'cldr/export/data'
5
5
  require 'cldr/export/data/timezones'
6
+ require 'cldr/export/data/territories_containment'
6
7
  require 'pathname'
7
8
 
8
9
  module TimezoneParser
@@ -14,6 +15,8 @@ module TimezoneParser
14
15
 
15
16
  protected
16
17
  @@Version = nil
18
+ @@Locales = nil
19
+ @@Territories = nil
17
20
 
18
21
  public
19
22
  def self.download(source = 'http://unicode.org/Public/cldr/latest/core.zip', target = nil)
@@ -37,9 +40,26 @@ module TimezoneParser
37
40
  @@Version
38
41
  end
39
42
 
43
+ def self.getLocales
44
+ unless @@Locales
45
+ @@Locales = Cldr::Export::Data.locales.sort
46
+ end
47
+ @@Locales
48
+ end
49
+
50
+ def self.getTerritories
51
+ unless @@Territories
52
+ @@Territories = {}
53
+ Cldr::Export::Data::TerritoriesContainment.new.territories.each do |territory, info|
54
+ @@Territories[territory] = info[:contains]
55
+ end
56
+ end
57
+ @@Territories
58
+ end
59
+
40
60
  def self.getTimezones
41
61
  timezones = { }
42
- Cldr::Export::Data.locales.sort.each do |locale|
62
+ getLocales.each do |locale|
43
63
  tz = Cldr::Export::Data::Timezones.new(locale)
44
64
  next if tz.timezones.empty? and tz.metazones.empty?
45
65
 
@@ -84,7 +104,7 @@ module TimezoneParser
84
104
  end
85
105
 
86
106
  def self.updateAbbreviations(abbreviations)
87
- Cldr::Export::Data.locales.sort.each do |locale|
107
+ getLocales.each do |locale|
88
108
  tz = Cldr::Export::Data::Timezones.new(locale)
89
109
  next if tz.timezones.empty? and tz.metazones.empty?
90
110
  tz.timezones.each do |timezone, data|
@@ -1,5 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'yaml'
3
2
  require 'date'
4
3
  require 'insensitive_hash'
5
4
 
@@ -19,6 +18,7 @@ module TimezoneParser
19
18
  @@RailsTranslated = nil
20
19
 
21
20
  public
21
+
22
22
  def self.Abbreviations
23
23
  unless @@Abbreviations
24
24
  @@Abbreviations = Marshal.load(File.open(Data::DataDir + 'abbreviations.dat'))
@@ -68,6 +68,11 @@ module TimezoneParser
68
68
  @@TimezoneCountries[timezone].sort!
69
69
  end
70
70
  end
71
+ ::TZInfo::Timezone.all_linked_zones.each do |zone|
72
+ timezone = zone.identifier
73
+ actual_timezone = zone.canonical_zone.identifier
74
+ @@TimezoneCountries[timezone] = @@TimezoneCountries[actual_timezone].dup unless @@TimezoneCountries[actual_timezone].nil?
75
+ end
71
76
  @@TimezoneCountries = Hash[@@TimezoneCountries.to_a.sort_by { |pair| pair.first }]
72
77
  end
73
78
  @@TimezoneCountries
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'win32/registry'
3
3
  require 'fiddle'
4
+ require 'insensitive_hash/minimal'
4
5
 
5
6
  module TimezoneParser
6
7
  # Windows module
@@ -32,6 +33,10 @@ module TimezoneParser
32
33
 
33
34
  def self.getTimezones(path = TimeZonePath)
34
35
  timezones = {}
36
+
37
+ timezones['North Pacific Standard Time'] = { 'standard' => 3600 * -8, 'daylight' => 3600 * -7 }
38
+ timezones['Russia TZ 5 Standard Time'] = { 'standard' => 3600 * 6, 'daylight' => 3600 * 6 }
39
+
35
40
  begin
36
41
  Win32::Registry::HKEY_LOCAL_MACHINE.open(path, Win32::Registry::KEY_READ).each_key do |key, wtime|
37
42
  Win32::Registry::HKEY_LOCAL_MACHINE.open(path + '\\' + key, Win32::Registry::KEY_READ) do |reg|
@@ -54,10 +59,21 @@ module TimezoneParser
54
59
  rescue Win32::Registry::Error => e
55
60
  @@Errors << e.message
56
61
  end
62
+
57
63
  timezones = Hash[timezones.to_a.sort_by { |d| d.first } ]
58
64
  timezones
59
65
  end
60
66
 
67
+ def self.getTimezonesUTC()
68
+ timezones = {}
69
+ ((1..13).to_a + (-12..-1).to_a.reverse).each do |o|
70
+ name = "UTC%+03d" % o
71
+ timezones[name] = { 'standard' => 3600 * o }
72
+ timezones[name]['daylight'] = timezones[name]['standard']
73
+ end
74
+ timezones
75
+ end
76
+
61
77
  def self.getMUIOffsets(path = TimeZonePath)
62
78
  offsets = {}
63
79
  begin
@@ -141,7 +157,7 @@ module TimezoneParser
141
157
  puts "Warning: No translation to locale name from LCID (#{lcid}), skipping!"
142
158
  next
143
159
  end
144
- metazones[locale] = {}
160
+ metazones[locale] = InsensitiveHash.new
145
161
  offsets.each do |id, info|
146
162
  unless data.has_key?(id)
147
163
  puts "Warning: Didn't found timezone name for #{id} for #{locale} locale, skipping!"
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module TimezoneParser
3
3
  # Version
4
- VERSION = '0.3.3'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -116,13 +116,13 @@ describe TimezoneParser do
116
116
 
117
117
  describe '.getOffsets' do
118
118
  it 'should return offsets for WAST abbreviation in NA region' do
119
- expect(TimezoneParser::Abbreviation::getOffsets('WAST', DateTime.now, nil, ['NA'])).to eq([7200])
119
+ expect(TimezoneParser::Abbreviation::getOffsets('WAST', DateTime.now, nil, ['NA'])).to eq([3600])
120
120
  end
121
121
  end
122
122
 
123
123
  describe '.getTimezones' do
124
124
  it 'should return timezones for WAST abbreviation' do
125
- expect(TimezoneParser::Abbreviation::getTimezones('WAST', DateTime.parse('1988-07-28T03:26:56+00:00'), DateTime.parse('1994-07-28T01:14:40+00:00'), ['NA'])).to eq(['Africa/Windhoek'])
125
+ expect(TimezoneParser::Abbreviation::getTimezones('WAST', DateTime.parse('1994-07-28T01:14:40+00:00'), DateTime.parse('1988-07-28T03:26:56+00:00'), ['NA'])).to eq(['Africa/Windhoek'])
126
126
  end
127
127
  end
128
128
 
@@ -56,7 +56,7 @@ describe TimezoneParser do
56
56
  end
57
57
 
58
58
  it 'should find timezones in only "GR", "FI" and "BG" regions' do
59
- expect(TimezoneParser::Timezone.new('აღმოსავლეთ ევროპის დრო').set(nil, ['GR', 'FI', 'BG']).getTimezones).to eq(['Europe/Athens', 'Europe/Helsinki', 'Europe/Sofia'])
59
+ expect(TimezoneParser::Timezone.new('აღმოსავლეთ ევროპის დრო').set(nil, ['GR', 'FI', 'BG']).getTimezones).to eq(['Europe/Athens', 'Europe/Helsinki', 'Europe/Mariehamn', 'Europe/Sofia'])
60
60
  end
61
61
  end
62
62
 
@@ -93,8 +93,8 @@ describe TimezoneParser do
93
93
  end
94
94
 
95
95
  describe '.getTimezones' do
96
- it 'should return all timezones for "Britain dzomeŋɔli gaƒoƒome"' do
97
- expect(TimezoneParser::Timezone::getTimezones('Britain dzomeŋɔli gaƒoƒome', nil, nil, ['dz', 'ee'], ['IM'])).to eq(['Europe/London'])
96
+ it 'should return all timezones for "British dzomeŋɔli gaƒoƒo me"' do
97
+ expect(TimezoneParser::Timezone::getTimezones('British dzomeŋɔli gaƒoƒo me', nil, nil, ['dz', 'ee'], ['IM'])).to eq(['Europe/London'])
98
98
  end
99
99
  end
100
100
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: TimezoneParser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dāvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-06 00:00:00.000000000 Z
11
+ date: 2018-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo
@@ -174,6 +174,7 @@ extra_rdoc_files: []
174
174
  files:
175
175
  - ".gitignore"
176
176
  - ".rspec"
177
+ - ".travis.yml"
177
178
  - ".yardopts"
178
179
  - Gemfile
179
180
  - README.md
@@ -181,17 +182,28 @@ files:
181
182
  - TimezoneParser.gemspec
182
183
  - UNLICENSE
183
184
  - data/abbreviations.dat
185
+ - data/abbreviations.yaml
184
186
  - data/countries.dat
187
+ - data/countries.yaml
188
+ - data/locales.yaml
185
189
  - data/metazones.dat
190
+ - data/metazones.yaml
186
191
  - data/rails.dat
192
+ - data/rails.yaml
187
193
  - data/rails_i18n.dat
194
+ - data/rails_i18n.yaml
195
+ - data/territories.yaml
188
196
  - data/timezones.dat
189
- - data/version.yml
197
+ - data/timezones.yaml
198
+ - data/version.yaml
190
199
  - data/windows_locales.yaml
191
200
  - data/windows_offsets.dat
201
+ - data/windows_offsets.yaml
192
202
  - data/windows_timezones.dat
203
+ - data/windows_timezones.yaml
193
204
  - data/windows_tzres.yaml
194
205
  - data/windows_zonenames.dat
206
+ - data/windows_zonenames.yaml
195
207
  - lib/timezone_parser.rb
196
208
  - lib/timezone_parser/abbreviation.rb
197
209
  - lib/timezone_parser/data.rb
data/data/version.yml DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- TZInfo: 2017b
3
- CLDR: 31.0.1
4
- Rails: 5.1.3
5
- WindowsZones: 7e10400