bugfix: time with 24:00

This commit is contained in:
Lea 2024-08-28 17:17:59 +02:00
parent 50271d1607
commit f6315e4403
3 changed files with 22 additions and 6 deletions

View File

@ -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
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}")

View File

@ -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(),

View File

@ -103,7 +103,6 @@
</div>
</fieldset>
</div>
<button type="submit" class="btn btn-primary">Suche</button>
</fieldset>
</form>