mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
0a1d0f56c8
commit
5228e61a0e
@ -132,6 +132,20 @@ def am_pm_pat():
|
|||||||
return ans
|
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):
|
def format_date(date=None, fmt='dd MMM yyyy', as_utc=False):
|
||||||
fmt = fmt or 'dd MMM yyyy'
|
fmt = fmt or 'dd MMM yyyy'
|
||||||
ampm = am_pm_pat().test(fmt)
|
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()
|
date = date or Date()
|
||||||
if is_date_undefined(date):
|
if is_date_undefined(date):
|
||||||
return ''
|
return ''
|
||||||
|
if fmt is 'iso':
|
||||||
|
return as_iso(date)
|
||||||
return fmt.replace(fmt_date_pat(), def(match):
|
return fmt.replace(fmt_date_pat(), def(match):
|
||||||
if not match:
|
if not match:
|
||||||
return ''
|
return ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user