Skip to content

Commit

Permalink
Fix math in get_timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed May 31, 2024
1 parent 2090f5a commit ba9b5ee
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion neon_utils/location_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from time import time

import pytz

Expand Down Expand Up @@ -147,7 +148,10 @@ def get_timezone(lat, lng) -> (str, float):
:return: timezone name, offset in hours from UTC
"""
timezone = TimezoneFinder().timezone_at(lng=float(lng), lat=float(lat))
offset = pytz.timezone(timezone).utcoffset(datetime.utcnow()).seconds / 3600.0
_time = time()
utc_timestamp = datetime.utcfromtimestamp(_time).timestamp()
local_timestamp = datetime.fromtimestamp(_time, tz=pytz.timezone(timezone)).timestamp()
offset = (local_timestamp - utc_timestamp) / 3600
return timezone, offset


Expand Down

0 comments on commit ba9b5ee

Please sign in to comment.