Skip to content

Commit

Permalink
Use the right sort key inside forceTz (#40)
Browse files Browse the repository at this point in the history
* Add a simple test case

* Sort by the right key

* Fix tests. setuptools has dropped python 3.2 support

* Exclude these files from .coveralls runs
  • Loading branch information
famanson authored and pegler committed May 25, 2017
1 parent 3e743eb commit 8a38690
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
@@ -0,0 +1,5 @@
[report]
omit =
*/python?.?/*
*/site-packages/nose/*
*__init__*
3 changes: 1 addition & 2 deletions .travis.yml
@@ -1,7 +1,6 @@
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
Expand All @@ -10,7 +9,7 @@ install:
- pip install -e .
- pip install -r tests/requirements.txt
# command to run tests
script:
script:
- nosetests --with-coverage --cover-branches --cover-inclusive --cover-package=tzwhere
after_script:
coveralls
1 change: 1 addition & 0 deletions tests/test_locations.py
Expand Up @@ -47,6 +47,7 @@ class LocationTestCase(unittest.TestCase):
( 61.17, -150.02, 'Anchorage, AK', 'America/Anchorage'),
( 40.7271, -73.98, 'Shore Lake Michigan', 'America/New_York'),
( 50.1536, -8.051, 'Off Cornwall', 'Europe/London'),
( 49.2698, -123.1302, 'Vancouver', 'America/Vancouver'),
( 50.26, -9.051, 'Far off Cornwall', None)
)

Expand Down
3 changes: 2 additions & 1 deletion tzwhere/tzwhere.py
Expand Up @@ -229,7 +229,8 @@ def tzNameAt(self, latitude, longitude, forceTZ=False):
d = poly.distance(queryPoint)
distances.append((d, tzname))
if len(distances) > 0:
return sorted(distances, key=lambda x: x[1])[0][1]
# Sort by distances, and then return the timezone name of the first instance in the sorted list
return sorted(distances, key=lambda x: x[0])[0][1]

@staticmethod
def _point_inside_polygon(x, y, poly):
Expand Down

0 comments on commit 8a38690

Please sign in to comment.