def __init__(self, recorded_at: time, response_timestamp: datetime, expected_arrival_time: time, current_location: GeoPoint): self.recorded_at: time = recorded_at.replace(microsecond=0) self.response_timestamp: datetime = response_timestamp.astimezone() self.expected_arrival_time: time = expected_arrival_time.replace(microsecond=0) self.current_location: GeoPoint = current_location
def equals_time(value: time, another: Any, formats: List[str]) -> bool: """ microsecond is ignored """ if isinstance(another, time): return value.replace(microsecond=0) == another.replace(microsecond=0) elif isinstance(another, str): parsed, another_value = is_time(another, formats) return parsed and value.replace(microsecond=0) == another_value.replace(microsecond=0) else: return False
def fetch_range(self, *, start: datetime.time, end: datetime.time, inclusive: bool = True, tz: str = None): if tz: start = start.replace(tzinfo=pytz.timezone(tz)) end = end.replace(tzinfo=pytz.timezone(tz)) if inclusive: filters = {"time_actual__gte": start, "time__actual__lte": end} else: filters = {"time_actual__gt": start, "time__actual__lt": end} return self.filter(**filters)
def __init__(self, line_name: str, license_plate: str, operator_ref: int, line_ref: int, departure_time: time, journey_ref: int, siri_records: Set[SiriRecord], doc_id: str = None, siri_ride_analytics: SiriRideAnalytics = None): """ :param doc_id: :param line_name: :param license_plate: :param operator_ref: :param line_ref: :param departure_time: :param journey_ref: The number part of trip ID. Valid value is like: 20925867. The value is reference to TripId at TripIdToDate.txt file at the GTFS :param siri_records: :param siri_ride_analytics: """ self.doc_id = doc_id self.line_name = line_name self.license_plate = license_plate self.departure_time: time = departure_time.replace(microsecond=0) self.operator_ref = int(operator_ref) self.line_ref = int(line_ref) self.journey_ref = int(journey_ref) self.siri_records: Set[SiriRecord] = siri_records self.siri_ride_analytics: SiriRideAnalytics = siri_ride_analytics
def get_time(default: dt.time = None) -> dt.time: default = str(default.replace(microsecond=0, second=default.second + 1)) if default else None time = get_input('Please enter a 24 hour time (HH:MM[:SS])', default, key=lambda x: dt.time( *(int(comp) for comp in x.split(':')))) return time
def prepare(self, value: datetime.time) -> Optional[str]: """ Prepare for serialisation """ if value is not None: if self.ignore_timezone and value.tzinfo is not None: # Strip the timezone value = value.replace(tzinfo=None) return value
def greater_or_equals_time( value: time, another: Any, formats: List[str], allow_equals: bool ) -> Tuple[bool, Optional[bool]]: """ return a tuple which first is can be compared. second is comparison result when first is true, otherwise second is none. """ if isinstance(another, time): return True, value.replace(microsecond=0) >= another.replace(microsecond=0) \ if allow_equals else value.replace(microsecond=0) > another.replace(microsecond=0) elif isinstance(another, str): parsed, another_value = is_time(another, formats) if parsed: return True, value.replace(microsecond=0) >= another_value.replace(microsecond=0) \ if allow_equals else value.replace(microsecond=0) > another_value.replace(microsecond=0) else: return False, None else: return False, None
def get_next_datetime(time: datetime.time): time = time.replace(second=0) now = datetime.datetime.now() if datetime.datetime.now().time() > time: date = now.replace(day=now.day + 1) else: date = now return date.replace(hour=time.hour, second=time.second, minute=time.minute, microsecond=time.microsecond)
def __init__(self, t: datetime.time, tz: datetime.timezone) -> None: self.t = t.replace(tzinfo=tz)
def set_value(self, obj, value: time): if self.default_timezone and value.tzinfo is None: value = value.replace(tzinfo=self.default_timezone) super(TimeField, self).set_value(obj, value)
def ensure_tzinfo(t: time) -> TimeTz: if t.tzinfo is not None: return TimeTz(t) return TimeTz(t.replace(tzinfo=timezone.utc))
def encode_time(val: time) -> str: encoded = val.replace(tzinfo=None).isoformat() return encoded.rstrip("0")