rename dateishexact to dateish

This commit is contained in:
Sean Breckenridge 2023-02-21 02:02:03 -08:00
parent 2fa0b5cef8
commit 00c135c460

View file

@ -4,7 +4,7 @@ from typing import Optional, Callable, Sequence, Iterator, List, Union
from datetime import datetime, timedelta from datetime import datetime, timedelta
from ..common import LocationProtocol, Location from ..common import LocationProtocol, Location
DateIshExact = Union[datetime, float, int] DateIsh = Union[datetime, float, int]
@dataclass @dataclass
class FallbackLocation(LocationProtocol): class FallbackLocation(LocationProtocol):
@ -62,17 +62,17 @@ class FallbackLocation(LocationProtocol):
) )
LocationEstimator = Callable[[DateIshExact], Optional[FallbackLocation]] LocationEstimator = Callable[[DateIsh], Optional[FallbackLocation]]
LocationEstimators = Sequence[LocationEstimator] LocationEstimators = Sequence[LocationEstimator]
# helper function, instead of dealing with datetimes while comparing, just use epoch timestamps # helper function, instead of dealing with datetimes while comparing, just use epoch timestamps
def _datetime_timestamp(dt: DateIshExact) -> float: def _datetime_timestamp(dt: DateIsh) -> float:
if isinstance(dt, datetime): if isinstance(dt, datetime):
return dt.timestamp() return dt.timestamp()
return float(dt) return float(dt)
def _iter_estimate_from( def _iter_estimate_from(
dt: DateIshExact, dt: DateIsh,
estimators: LocationEstimators, estimators: LocationEstimators,
) -> Iterator[FallbackLocation]: ) -> Iterator[FallbackLocation]:
for est in estimators: for est in estimators:
@ -83,7 +83,7 @@ def _iter_estimate_from(
def estimate_from( def estimate_from(
dt: DateIshExact, dt: DateIsh,
estimators: LocationEstimators, estimators: LocationEstimators,
*, *,
first_match: bool = False, first_match: bool = False,