diff --git a/arztapi/APIHandler.py b/arztapi/APIHandler.py index a10680c..a54a741 100644 --- a/arztapi/APIHandler.py +++ b/arztapi/APIHandler.py @@ -38,7 +38,8 @@ class APIHandler: print("foo") print(response.text) - def get_list_of_doctors(self, lat, lon, req_val_base64, therapy_types, therapy_age, therapy_setting) -> ArztPraxisDatas: + def get_list_of_doctors(self, lat, lon, req_val_base64, therapy_types, therapy_age, + therapy_setting) -> ArztPraxisDatas: api_path = self.base_api_url + "data" headers = { "Accept": "application/json", @@ -232,6 +233,22 @@ class APIHandler: @staticmethod def parse_date_string(date_string): format_string = "%d.%m. %H:%M" - # TODO: handle turn of year - parsed_date = datetime.strptime(date_string, format_string).replace(year=datetime.now().year) - return parsed_date + current_year = datetime.now().year + + try: + if "24:00" in date_string: + # Sometimes the API returns 24:00 as time, so filtering for those cases and replacing it with a minute + # less to work with propery input + date_string.replace("24:00", "23:59") + + # Add the current year since it is not part of the original date sent by the API + parsed_date = datetime.strptime(date_string, format_string).replace(year=datetime.now().year) + + # Handle turn of the year: if date is in the past relative to today, consider it as part of the next year + if parsed_date < datetime.now(): + parsed_date = parsed_date.replace(year=current_year + 1) + + return parsed_date + + except ValueError as e: + raise ValueError(f"Error parsing date string: '{date_string}'. Details: {e}") diff --git a/forms/SearchForm.py b/forms/SearchForm.py index 4610806..3f770b3 100644 --- a/forms/SearchForm.py +++ b/forms/SearchForm.py @@ -24,7 +24,7 @@ class RangeInput(Input): class SearchForm(Form): location = StringField("Standort/PLZ", validators=[validators.InputRequired(), validators.Length(min=2, max=50), - validators.Regexp("^[a-zA-ZäöüßÄÖÜẞ]+$")]) + validators.Regexp("^[a-zA-ZäöüßÄÖÜẞ0-9]+$")]) therapy_distance = IntegerField( "Distanz (in km)", widget=RangeInput(), diff --git a/templates/index.html b/templates/index.html index 2f896ae..855c791 100644 --- a/templates/index.html +++ b/templates/index.html @@ -103,7 +103,6 @@ -