Zeiten nochmal verbessert
This commit is contained in:
@@ -129,11 +129,13 @@ def format_decimal_german(value: Decimal | float | int | None, *, max_fraction_d
|
||||
|
||||
|
||||
def format_utc_datetime(dt_utc: datetime) -> str:
|
||||
return dt_utc.astimezone(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
|
||||
dt_utc = dt_utc.astimezone(timezone.utc)
|
||||
return dt_utc.strftime("%Y-%m-%d %H:%M:%S") + f".{dt_utc.microsecond // 1000:03d}"
|
||||
|
||||
|
||||
def format_german_datetime(dt_utc: datetime) -> str:
|
||||
return dt_utc.astimezone(timezone.utc).strftime("%d.%m.%Y %H:%M:%S")
|
||||
dt_utc = dt_utc.astimezone(timezone.utc)
|
||||
return dt_utc.strftime("%d.%m.%Y %H:%M:%S") + f",{dt_utc.microsecond // 1000:03d}"
|
||||
|
||||
|
||||
def format_clock(hours_value: float) -> str:
|
||||
@@ -161,9 +163,10 @@ def parse_utc_datetime(value: str) -> datetime | None:
|
||||
if text == "":
|
||||
return None
|
||||
|
||||
for fmt in ("%Y-%m-%d %H:%M:%S", "%Y-%m-%dT%H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d"):
|
||||
normalized = text.replace(",", ".")
|
||||
for fmt in ("%Y-%m-%d %H:%M:%S.%f", "%Y-%m-%dT%H:%M:%S.%f", "%Y-%m-%d %H:%M:%S", "%Y-%m-%dT%H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d"):
|
||||
try:
|
||||
parsed = datetime.strptime(text, fmt)
|
||||
parsed = datetime.strptime(normalized, fmt)
|
||||
return parsed.replace(tzinfo=timezone.utc)
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user