mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Fix a regression in 8.0 that caused the clock to display an extra p after the time. Fixes #2106280 [extraneous letter 'p' in the clock](https://bugs.launchpad.net/calibre/+bug/2106280)
Apparently Qt has now started using Ap and aP as AM/PM formatters. Sigh.
This commit is contained in:
parent
30b66dc452
commit
75b513834a
@ -33,7 +33,7 @@ except:
|
|||||||
def fmt_date_pat():
|
def fmt_date_pat():
|
||||||
ans = fmt_date_pat.ans
|
ans = fmt_date_pat.ans
|
||||||
if not ans?:
|
if not ans?:
|
||||||
ans = fmt_date_pat.ans = /(s{1,2})|(m{1,2})|(h{1,2})|(H{1,2})|(zzz)|(z)|(ap)|(AP)|(a)|(A)|(t)|(d{1,4}|M{1,4}|(?:yyyy|yy))/g
|
ans = fmt_date_pat.ans = /(s{1,2})|(m{1,2})|(h{1,2})|(H{1,2})|(zzz)|(z)|(ap)|(AP)|(Ap)|(aP)|(a)|(A)|(t)|(d{1,4}|M{1,4}|(?:yyyy|yy))/g
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
@ -73,9 +73,25 @@ def fd_format_timezone(dt, ampm, t, as_utc):
|
|||||||
return window.Intl.DateTimeFormat().resolvedOptions().timeZone
|
return window.Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||||
|
|
||||||
|
|
||||||
|
def get_ampm_text(which):
|
||||||
|
ans = get_ampm_text[which]
|
||||||
|
if not ans:
|
||||||
|
d = Date()
|
||||||
|
if which is 'am':
|
||||||
|
d.setHours(1, 0, 0, 0)
|
||||||
|
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()
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def fd_format_ampm(dt, ampm, ap, as_utc):
|
def fd_format_ampm(dt, ampm, ap, as_utc):
|
||||||
h = dt.getUTCHours() if as_utc else dt.getHours()
|
h = dt.getUTCHours() if as_utc else dt.getHours()
|
||||||
ans = 'am' if h < 12 else 'pm'
|
ans = 'am' if h < 12 else 'pm'
|
||||||
|
ans = get_ampm_text(ans)
|
||||||
|
if ans is 'Ap' or ans is 'aP':
|
||||||
|
return ans
|
||||||
return ans if (ap is 'ap' or ap is 'a') else ans.toUpperCase()
|
return ans if (ap is 'ap' or ap is 'a') else ans.toUpperCase()
|
||||||
|
|
||||||
|
|
||||||
@ -122,6 +138,10 @@ fd_function_index = {
|
|||||||
's': fd_format_second,
|
's': fd_format_second,
|
||||||
'a': fd_format_ampm,
|
'a': fd_format_ampm,
|
||||||
'A': fd_format_ampm,
|
'A': fd_format_ampm,
|
||||||
|
'ap': fd_format_ampm,
|
||||||
|
'AP': fd_format_ampm,
|
||||||
|
'Ap': fd_format_ampm,
|
||||||
|
'aP': fd_format_ampm,
|
||||||
'z': fd_format_ms,
|
'z': fd_format_ms,
|
||||||
't': fd_format_timezone,
|
't': fd_format_timezone,
|
||||||
}
|
}
|
||||||
@ -130,7 +150,7 @@ fd_function_index = {
|
|||||||
def am_pm_pat():
|
def am_pm_pat():
|
||||||
ans = am_pm_pat.ans
|
ans = am_pm_pat.ans
|
||||||
if not ans?:
|
if not ans?:
|
||||||
ans = am_pm_pat.ans = /(ap)|(a)|(AP)|(A)/
|
ans = am_pm_pat.ans = /(ap)|(AP)|(Ap)|(aP)|(a)|(A)/
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
from __python__ import bound_methods, hash_literals
|
from __python__ import bound_methods, hash_literals
|
||||||
|
|
||||||
from date import format_date
|
from date import format_date, get_ampm_text
|
||||||
from testing import test, assert_equal
|
from testing import test, assert_equal, assert_true
|
||||||
|
|
||||||
|
|
||||||
def test_fd(date, fmt, ans):
|
def test_fd(date, fmt, ans):
|
||||||
@ -12,6 +12,8 @@ def test_fd(date, fmt, ans):
|
|||||||
|
|
||||||
@test
|
@test
|
||||||
def date_formatting():
|
def date_formatting():
|
||||||
|
assert_true(get_ampm_text('am'))
|
||||||
|
assert_true(get_ampm_text('pm'))
|
||||||
test_fd('1101-01-01T09:00:00+00:00', 'hh h', '09 9')
|
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-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-01T00:15:00+00:00', 'h:m ap', '12:15 am')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user