Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from aridevelopment-de/feature/suntime
Constant evaluation based on coordinates and timezone
- Loading branch information
Showing
11 changed files
with
184 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from timezonefinder import TimezoneFinder | ||
|
||
|
||
class TimeZoneManager(TimezoneFinder): | ||
|
||
def __init__(self): | ||
super(TimeZoneManager, self).__init__(in_memory=True) | ||
|
||
def get_coordinates(self, timezone: str) -> tuple[float, float]: | ||
coords = self.get_geometry(tz_name=timezone, coords_as_pairs=True) | ||
|
||
while not isinstance(coords[0], tuple): | ||
coords = coords[len(coords) // 2] | ||
|
||
coords: tuple[float, float] = coords[len(coords) // 2] | ||
|
||
# timezone = self.timezone_at(lng=coords[0] + 1, lat=coords[1]) | ||
# TODO: needs to be improved, at the moment it's just a small fix, not tested if it works with all timezones | ||
# TODO: add testcases for ALL timezones if possible to check if the "+1" fix is working | ||
# at the moment it returns "Europe/Belgium" if the timezone "Europe/Berlin" is used -> the "+1" on longitude fixes that | ||
|
||
return coords[0] + 1, coords[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from datetime import datetime | ||
|
||
|
||
class Result: | ||
""" | ||
The returned Result by the parse function, containing the output information | ||
- Attributes: | ||
- time (datetime): The parsed time | ||
- timezone (str): The used timezone | ||
- coordinates (Optional[tuple[float, float]]): Coordinates used for parsing | ||
""" | ||
time: datetime | ||
timezone: str | ||
coordinates: tuple[float, float] | ||
|
||
def __init__(self, time: datetime, timezone: str, coordinates: tuple[float, float] = None): | ||
self.time = time | ||
self.timezone = timezone | ||
self.coordinates = coordinates | ||
|
||
def __repr__(self): | ||
out: str = "'None'" | ||
if self.coordinates: | ||
out: str = f"[longitude='{self.coordinates[0]}', latitude='{self.coordinates[1]}]'" | ||
return f"<Result: time='{self.time}', timezone='{self.timezone}', coordinates={out}>" | ||
|
||
def __str__(self): | ||
return self.__repr__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
python-dateutil | ||
pytz | ||
typing | ||
typing | ||
timezonefinder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters