def test_parse_datetime(self): """Test datetime parser.""" dt_with_milliseconds = datetime.datetime(2021, 11, 12, 13, 14, 15, 567000, tzinfo=datetime.timezone.utc) dt_without_milliseconds = datetime.datetime(2021, 11, 12, 13, 14, 15, tzinfo=datetime.timezone.utc) self.assertEqual(dt_with_milliseconds, parse_datetime("2021-11-12T13:14:15.567Z")) self.assertEqual(dt_without_milliseconds, parse_datetime("2021-11-12T13:14:15Z")) with self.assertLogs(level=logging.ERROR): self.assertIsNone(parse_datetime("2021-14-12T13:14:15Z"))
def __init__(self, cbs_data: dict): #: date when the service is due self.due_date = parse_datetime(cbs_data.get('dateTime')) #: status of the service self.state = ConditionBasedServiceStatus(cbs_data['status']) #: service type self.service_type = cbs_data['type'] #: distance when the service is due self.due_distance = None if 'distance' in cbs_data: self.due_distance = (cbs_data["distance"]['value'], cbs_data["distance"]['units']) #: description of the required service self.description = None # Could be retrieved from status.requiredServices if needed
def timestamp(self) -> datetime.datetime: """Get the timestamp when the data was recorded.""" return max(parse_datetime(self.properties['lastUpdatedAt']), parse_datetime(self.status['lastUpdatedAt']))