-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix zone offset parsing #40
base: master
Are you sure you want to change the base?
Conversation
spec/data/zone_spec.rb
Outdated
end | ||
|
||
it 'returns true when preceded by a space' do | ||
expect('August 9, 6:56 AM -10').to be true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test is missing method to test on expectation.
expect( ZoneOffset.detect?('August 9, 6:56 AM -10') ).to be true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I had some unpushed fixes here. 😆
spec/data/zone_spec.rb
Outdated
end | ||
|
||
it 'returns false when part of a date' do | ||
expect('2017-10-10').to be false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing ZoneOffset.detect?
Parse numeric strings to avoid errors when API responses don't send a known zone string but default to a numeric offset instead.
The entire time string is passed to the zone parser, so look for numeric offsets that may be preceded by a space.
Parsing the time string using `strptime` against the format string was causing errors. Unsure if all times sent from Wunderground are like this, or only some locations. In any case, both formats are recognized without the format string using the `DateTime.parse` method
34299c7
to
ed4ac03
Compare
We were seeing errors from Weather Underground for certain locations where a time zone name was not being returned, and Barometer was unable to parse the offset value. It looks like the zone data parsing was tested under the assumption that it expects a numeric value, when in fact it receives a string value.
This change teaches the zone data to parse standard offset strings of
+HH
or+HHMM
.The original implementation was treating numeric values as hours, and this assumption still remains when passing integer types. This means
"1200"
and1200
are understood differently as 12 hours vs. 1200 hours, respectively.