TimezoneParser 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/timezone_parser/abbreviation.rb +11 -1
- data/lib/timezone_parser/data/storage.rb +2 -2
- data/lib/timezone_parser/version.rb +1 -1
- data/spec/abbreviation_spec.rb +16 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 801e797d854babedd580bcf96aa98356e03e4923
|
4
|
+
data.tar.gz: d5d0f47184e279fd7628fe292c24778b8e044927
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 913e2b9eb391a6fdf900f0645f12914b39b68d819c6f89adff62d2bae24abaf278cebe6405ff23f2f08eb973b372f0d739929047209c215b443978d44d9dc094
|
7
|
+
data.tar.gz: 1bb4c8dba1a94a09eae70416a7e7149d1123ab47571df2d03745e251394f402e51d496d05ab854786f24affb9751db7182290c66987c9a4e9a3875db7e60e618
|
@@ -80,13 +80,23 @@ module TimezoneParser
|
|
80
80
|
@Offsets
|
81
81
|
end
|
82
82
|
|
83
|
-
# Check if given Timezone abbreviation is a valid timezone
|
83
|
+
# Check if given Timezone abbreviation (case-sensitive) is a valid timezone
|
84
84
|
# @param abbreviation [String] Timezone abbreviation
|
85
85
|
# @return [Boolean] whether Timezone is valid
|
86
86
|
def self.isValid?(abbreviation)
|
87
87
|
Data::Storage.Abbreviations.has_key?(abbreviation)
|
88
88
|
end
|
89
89
|
|
90
|
+
# Check if given Timezone abbreviation (case-insensitive) could be a valid timezone
|
91
|
+
# @param abbreviation [String] Timezone abbreviation to check for
|
92
|
+
# @return [Boolean] whether Timezone is valid
|
93
|
+
def self.couldBeValid?(abbreviation)
|
94
|
+
Data::Storage.Abbreviations.each_key do |abbr|
|
95
|
+
return true if abbr.casecmp(abbreviation).zero?
|
96
|
+
end
|
97
|
+
false
|
98
|
+
end
|
99
|
+
|
90
100
|
# Get UTC offsets in seconds for given Timezone abbreviation
|
91
101
|
# @param abbreviation [String] Timezone abbreviation
|
92
102
|
# @param toTime [DateTime] look for offsets which came into effect before this date, exclusive
|
@@ -21,7 +21,7 @@ module TimezoneParser
|
|
21
21
|
public
|
22
22
|
def self.Abbreviations
|
23
23
|
unless @@Abbreviations
|
24
|
-
@@Abbreviations = Marshal.load(File.open(Data::DataDir + 'abbreviations.dat'))
|
24
|
+
@@Abbreviations = Marshal.load(File.open(Data::DataDir + 'abbreviations.dat'))
|
25
25
|
@@Abbreviations.each do |abbr, data|
|
26
26
|
proccessData(data)
|
27
27
|
end
|
@@ -45,7 +45,7 @@ module TimezoneParser
|
|
45
45
|
|
46
46
|
def self.Metazones
|
47
47
|
unless @@Metazones
|
48
|
-
@@Metazones = Marshal.load(File.open(Data::DataDir + 'metazones.dat'))
|
48
|
+
@@Metazones = Marshal.load(File.open(Data::DataDir + 'metazones.dat'))
|
49
49
|
@@Metazones.each do |zone, data|
|
50
50
|
proccessData(data)
|
51
51
|
end
|
data/spec/abbreviation_spec.rb
CHANGED
@@ -18,8 +18,8 @@ describe TimezoneParser do
|
|
18
18
|
expect(TimezoneParser::Abbreviation.new('LOL').isValid?).to be false
|
19
19
|
end
|
20
20
|
|
21
|
-
it 'should be
|
22
|
-
expect(TimezoneParser::Abbreviation.new('Pst').isValid?).to be
|
21
|
+
it 'should be invalid case-insensitive abbreviation' do
|
22
|
+
expect(TimezoneParser::Abbreviation.new('Pst').isValid?).to be false
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -100,6 +100,20 @@ describe TimezoneParser do
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
describe '.couldBeValid?' do
|
104
|
+
it 'should be valid abbreviation' do
|
105
|
+
expect(TimezoneParser::Abbreviation.couldBeValid?('cet')).to be true
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should not be valid abbreviation' do
|
109
|
+
expect(TimezoneParser::Abbreviation.couldBeValid?('WZE')).to be false
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should be valid case-insensitive abbreviation' do
|
113
|
+
expect(TimezoneParser::Abbreviation.couldBeValid?('Pst')).to be true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
103
117
|
describe '.getOffsets' do
|
104
118
|
it 'should return offsets for WGT abbreviation in GL region' do
|
105
119
|
expect(TimezoneParser::Abbreviation::getOffsets('WGT', DateTime.now, nil, ['GL'])).to eq([-10800])
|