Verbessere die RFC 2822 Datumsformatierung, um englische Namen unabhängig von der Locale zu verwenden und füge einen Fallback für die manuelle Formatierung hinzu.
This commit is contained in:
@ -283,8 +283,30 @@ class LocalPodcastGenerator:
|
||||
def format_rfc2822_date(self, dt):
|
||||
"""Formatiert ein Datum im RFC 2822 Format für RSS."""
|
||||
# RFC 2822 Format: "Wed, 02 Oct 2002 08:00:00 +0000"
|
||||
# Verwende die eingebaute strftime Funktion für korrekte Formatierung
|
||||
return dt.strftime('%a, %d %b %Y %H:%M:%S +0000')
|
||||
# Explizite englische Namen verwenden (unabhängig von Locale)
|
||||
import locale
|
||||
old_locale = locale.getlocale(locale.LC_TIME)
|
||||
try:
|
||||
# Versuche englisches Locale zu setzen
|
||||
locale.setlocale(locale.LC_TIME, 'C')
|
||||
formatted = dt.strftime('%a, %d %b %Y %H:%M:%S +0000')
|
||||
except:
|
||||
# Fallback: manuelle Formatierung
|
||||
weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
||||
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
||||
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||
|
||||
weekday = weekdays[dt.weekday()]
|
||||
month = months[dt.month - 1]
|
||||
formatted = f"{weekday}, {dt.day:02d} {month} {dt.year} {dt.hour:02d}:{dt.minute:02d}:{dt.second:02d} +0000"
|
||||
finally:
|
||||
# Locale zurücksetzen
|
||||
try:
|
||||
locale.setlocale(locale.LC_TIME, old_locale)
|
||||
except:
|
||||
pass
|
||||
|
||||
return formatted
|
||||
|
||||
def format_duration(self, seconds):
|
||||
"""Formatiert die Dauer in HH:MM:SS Format."""
|
||||
|
Reference in New Issue
Block a user