From 23187893baa54ab264cbda41af87b00e26e2ee80 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 5 Apr 2025 10:38:04 +0530 Subject: [PATCH] Fix failing test --- src/calibre/utils/date.py | 7 ++++++- src/pyj/date.pyj | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/utils/date.py b/src/calibre/utils/date.py index 2ac5a6f577..a3b815b865 100644 --- a/src/calibre/utils/date.py +++ b/src/calibre/utils/date.py @@ -289,7 +289,12 @@ def timestampfromdt(dt, assume_utc=True): # Format date functions {{{ def fd_format_hour(dt, ampm, hr): - h = int(strftime('%I' if ampm else '%H', t=dt.timetuple()).strip()) + try: + h = int(strftime('%I' if ampm else '%H', t=dt.timetuple()).strip()) + except Exception: + h = dt.hour + if ampm: + h %= 12 if len(hr) == 1: return f'{h}' return f'{h:02}' diff --git a/src/pyj/date.pyj b/src/pyj/date.pyj index 298bc5369a..ec7727a829 100644 --- a/src/pyj/date.pyj +++ b/src/pyj/date.pyj @@ -82,7 +82,7 @@ def get_ampm_text(which): else: d.setHours(13, 0, 0, 0) x = window.Intl.DateTimeFormat('default', { 'hour': 'numeric', 'hour12': True }).format(d) - ans = get_ampm_text[which] = x.replace(/\d+/g, '').trim() + ans = get_ampm_text[which] = x.replace(/\d+/g, '').trim() or which.toUpperCase() return ans