From 7e3ac04222fbe471b3881b5d2cbba8fb812c0268 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 3 Feb 2024 09:13:33 +0530 Subject: [PATCH] E-book viewer: Fix clock showing hour as zero instead of 12 between 12 and 1 am/pm --- src/pyj/date.pyj | 2 ++ src/pyj/test_date.pyj | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/pyj/date.pyj b/src/pyj/date.pyj index 26cfe8b408..bf2fe51bca 100644 --- a/src/pyj/date.pyj +++ b/src/pyj/date.pyj @@ -41,6 +41,8 @@ def fd_format_hour(dt, ampm, hr, as_utc): h = dt.getUTCHours() if as_utc else dt.getHours() if ampm: h %= 12 + if h is 0: + h = 12 return h.toString() if hr.length is 1 else str.format('{:02d}', h) diff --git a/src/pyj/test_date.pyj b/src/pyj/test_date.pyj index bfc48e290c..40f22a99a8 100644 --- a/src/pyj/test_date.pyj +++ b/src/pyj/test_date.pyj @@ -13,6 +13,9 @@ def test_fd(date, fmt, ans): @test def date_formatting(): test_fd('1101-01-01T09:00:00+00:00', 'hh h', '09 9') + test_fd('1101-01-01T12:15:00+00:00', 'h:m ap', '12:15 pm') + test_fd('1101-01-01T00:15:00+00:00', 'h:m ap', '12:15 am') + test_fd('1101-01-01T13:15:00+00:00', 'h:m ap', '1:15 pm') test_fd('1101-01-01T09:01:00+00:00', 'h:mm AP', '9:01 AM') test_fd('1101-01-01T09:05:01.012+00:00', 'hh h mm m ss s z zzz ap AP a A yy yyyy', '09 9 05 5 01 1 12 012 am AM am AM 01 1101') test_fd('2001-01-02T09:00:00+00:00', 'M MM MMM MMMM', '1 01 Jan January')