Skip to content

Commit

Permalink
Refactor to use pytz instead of pendulum
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed May 31, 2024
1 parent 9481238 commit 2090f5a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions neon_utils/location_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import pendulum
import pytz

from datetime import datetime
from typing import Optional, Union

from dateutil.tz import tzlocal
from timezonefinder import TimezoneFinder
from re import sub
Expand Down Expand Up @@ -143,10 +144,10 @@ def get_timezone(lat, lng) -> (str, float):
Note that some coordinates do not have a city, but may have a county.
:param lat: latitude
:param lng: longitude
:return: timezone name, offset from GMT
:return: timezone name, offset in hours from UTC
"""
timezone = TimezoneFinder().timezone_at(lng=float(lng), lat=float(lat))
offset = pendulum.from_timestamp(0, timezone).offset_hours
offset = pytz.timezone(timezone).utcoffset(datetime.utcnow()).seconds / 3600.0
return timezone, offset


Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ovos-bus-client~=0.0.3
combo-lock~=0.2
pendulum~=2.1
pytz>=2022.1
timezonefinder~=5.2
nltk~=3.5
pyyaml>=5.4,<7.0
Expand Down

0 comments on commit 2090f5a

Please sign in to comment.