Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

avit
Copy link
Contributor

@avit avit commented Aug 8, 2017

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" and 1200 are understood differently as 12 hours vs. 1200 hours, respectively.

end

it 'returns true when preceded by a space' do
expect('August 9, 6:56 AM -10').to be true
Copy link
Contributor

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

Copy link
Contributor Author

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. 😆

end

it 'returns false when part of a date' do
expect('2017-10-10').to be false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing ZoneOffset.detect?

avit added 5 commits December 20, 2017 13:03
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
@avit avit force-pushed the zone_offset_parsing branch from 34299c7 to ed4ac03 Compare December 20, 2017 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants