Content server: Fix formatting of dates for custom columns using ISO format. Fixes #1986412 [Content Server: iso date format break in book details page](https://bugs.launchpad.net/calibre/+bug/1986412)

This commit is contained in:
Kovid Goyal 2022-08-13 09:05:53 +05:30
parent 0a1d0f56c8
commit 5228e61a0e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -132,6 +132,20 @@ def am_pm_pat():
return ans
def as_iso(date):
tzo = -date.getTimezoneOffset()
dif = '+' if tzo >= 0 else '-'
def pad(num):
return ('0' if num < 10 else '') + num
return (
date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + ' ' + pad(date.getHours()) +
':' + pad(date.getMinutes()) + ':' + pad(date.getSeconds()) + dif + pad(Math.floor(Math.abs(tzo) / 60)) +
':' + pad(Math.abs(tzo) % 60)
)
def format_date(date=None, fmt='dd MMM yyyy', as_utc=False):
fmt = fmt or 'dd MMM yyyy'
ampm = am_pm_pat().test(fmt)
@ -140,6 +154,8 @@ def format_date(date=None, fmt='dd MMM yyyy', as_utc=False):
date = date or Date()
if is_date_undefined(date):
return ''
if fmt is 'iso':
return as_iso(date)
return fmt.replace(fmt_date_pat(), def(match):
if not match:
return ''