From fdc5845cec48a8e7ed7b184e41e865c9d7d24e22 Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Sun, 6 Jul 2025 11:34:41 +0200 Subject: [PATCH] =?UTF-8?q?Verbessere=20die=20RFC=202822=20Datumsformatier?= =?UTF-8?q?ung,=20um=20englische=20Namen=20unabh=C3=A4ngig=20von=20der=20L?= =?UTF-8?q?ocale=20zu=20verwenden=20und=20f=C3=BCge=20einen=20Fallback=20f?= =?UTF-8?q?=C3=BCr=20die=20manuelle=20Formatierung=20hinzu.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- local_podcast_generator.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/local_podcast_generator.py b/local_podcast_generator.py index 1211f0d..8f32c2a 100644 --- a/local_podcast_generator.py +++ b/local_podcast_generator.py @@ -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."""