annotate duration with Second type alias

This commit is contained in:
Sean Breckenridge 2023-02-26 16:52:09 -08:00
parent 3be9fe7713
commit aa4ee0382c
2 changed files with 10 additions and 1 deletions

View file

@ -6,12 +6,14 @@ from datetime import datetime, timedelta, timezone
from ..common import LocationProtocol, Location from ..common import LocationProtocol, Location
DateExact = Union[datetime, float, int] # float/int as epoch timestamps DateExact = Union[datetime, float, int] # float/int as epoch timestamps
Second = float
@dataclass @dataclass
class FallbackLocation(LocationProtocol): class FallbackLocation(LocationProtocol):
lat: float lat: float
lon: float lon: float
dt: datetime dt: datetime
duration: Optional[float] = None # time in seconds for how long this is valid duration: Optional[Second] = None
accuracy: Optional[float] = None accuracy: Optional[float] = None
elevation: Optional[float] = None elevation: Optional[float] = None
datasource: Optional[str] = None # which module provided this, useful for debugging datasource: Optional[str] = None # which module provided this, useful for debugging

View file

@ -250,6 +250,13 @@ def _get_tz(dt: datetime) -> Optional[pytz.BaseTzInfo]:
if res is not None: if res is not None:
return res return res
# fallback to home tz # fallback to home tz
# note: the fallback to fallback.via_home.estimate_location is still needed, since
# _iter_local_dates_fallback only returns days which we actually have a datetime for
# (e.g. there was an IP address within a day of that datetime)
#
# given a datetime, fallback.via_home.estimate_location will find which home location
# that datetime is between, else fallback on your first home location, so it acts
# as a last resort
from my.location.fallback import via_home as home from my.location.fallback import via_home as home
loc = list(home.estimate_location(dt)) loc = list(home.estimate_location(dt))
assert len(loc) == 1, f"should only have one home location, received {loc}" assert len(loc) == 1, f"should only have one home location, received {loc}"