annotate duration with Second type alias
This commit is contained in:
parent
3be9fe7713
commit
aa4ee0382c
2 changed files with 10 additions and 1 deletions
|
@ -6,12 +6,14 @@ from datetime import datetime, timedelta, timezone
|
|||
from ..common import LocationProtocol, Location
|
||||
DateExact = Union[datetime, float, int] # float/int as epoch timestamps
|
||||
|
||||
Second = float
|
||||
|
||||
@dataclass
|
||||
class FallbackLocation(LocationProtocol):
|
||||
lat: float
|
||||
lon: float
|
||||
dt: datetime
|
||||
duration: Optional[float] = None # time in seconds for how long this is valid
|
||||
duration: Optional[Second] = None
|
||||
accuracy: Optional[float] = None
|
||||
elevation: Optional[float] = None
|
||||
datasource: Optional[str] = None # which module provided this, useful for debugging
|
||||
|
|
|
@ -250,6 +250,13 @@ def _get_tz(dt: datetime) -> Optional[pytz.BaseTzInfo]:
|
|||
if res is not None:
|
||||
return res
|
||||
# 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
|
||||
loc = list(home.estimate_location(dt))
|
||||
assert len(loc) == 1, f"should only have one home location, received {loc}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue