mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Template language: Fix an error formatting dates when the underlying date does not have a day. Fixes #1576742 [BAD DATE for dates in February](https://bugs.launchpad.net/calibre/+bug/1576742)
This commit is contained in:
parent
b620f6c5b7
commit
578085765c
@ -44,10 +44,7 @@ class SafeLocalTimeZone(tzlocal):
|
|||||||
# Here is a more stable implementation:
|
# Here is a more stable implementation:
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
timestamp = ((dt.toordinal() - EPOCHORDINAL) * 86400
|
timestamp = ((dt.toordinal() - EPOCHORDINAL) * 86400 + dt.hour * 3600 + dt.minute * 60 + dt.second)
|
||||||
+ dt.hour * 3600
|
|
||||||
+ dt.minute * 60
|
|
||||||
+ dt.second)
|
|
||||||
return time.localtime(timestamp+time.timezone).tm_isdst
|
return time.localtime(timestamp+time.timezone).tm_isdst
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
@ -122,14 +119,14 @@ def parse_date(date_string, assume_utc=False, as_utc=True, default=None):
|
|||||||
:param as_utc: If True, return a UTC datetime
|
:param as_utc: If True, return a UTC datetime
|
||||||
|
|
||||||
:param default: Missing fields are filled in from default. If None, the
|
:param default: Missing fields are filled in from default. If None, the
|
||||||
current date is used.
|
current month and year are used.
|
||||||
'''
|
'''
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
if not date_string:
|
if not date_string:
|
||||||
return UNDEFINED_DATE
|
return UNDEFINED_DATE
|
||||||
if default is None:
|
if default is None:
|
||||||
func = datetime.utcnow if assume_utc else datetime.now
|
func = datetime.utcnow if assume_utc else datetime.now
|
||||||
default = func().replace(hour=0, minute=0, second=0, microsecond=0,
|
default = func().replace(day=15, hour=0, minute=0, second=0, microsecond=0,
|
||||||
tzinfo=_utc_tz if assume_utc else _local_tz)
|
tzinfo=_utc_tz if assume_utc else _local_tz)
|
||||||
dt = parse(date_string, default=default, dayfirst=parse_date_day_first)
|
dt = parse(date_string, default=default, dayfirst=parse_date_day_first)
|
||||||
if dt.tzinfo is None:
|
if dt.tzinfo is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user