mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Match parse_date() behavior for false date_strings
This commit is contained in:
parent
ae632d23cc
commit
1cfe7a6f3c
@ -12,7 +12,7 @@ from functools import partial
|
|||||||
|
|
||||||
from calibre import strftime
|
from calibre import strftime
|
||||||
from calibre.constants import iswindows, isosx, plugins
|
from calibre.constants import iswindows, isosx, plugins
|
||||||
from calibre.utils.iso8601 import utc_tz, local_tz
|
from calibre.utils.iso8601 import utc_tz, local_tz, UNDEFINED_DATE
|
||||||
from calibre.utils.localization import lcdata
|
from calibre.utils.localization import lcdata
|
||||||
|
|
||||||
_utc_tz = utc_tz
|
_utc_tz = utc_tz
|
||||||
@ -53,7 +53,6 @@ else:
|
|||||||
except:
|
except:
|
||||||
parse_date_day_first = False
|
parse_date_day_first = False
|
||||||
|
|
||||||
UNDEFINED_DATE = datetime(101,1,1, tzinfo=utc_tz)
|
|
||||||
DEFAULT_DATE = datetime(2000,1,1, tzinfo=utc_tz)
|
DEFAULT_DATE = datetime(2000,1,1, tzinfo=utc_tz)
|
||||||
EPOCH = datetime(1970, 1, 1, tzinfo=_utc_tz)
|
EPOCH = datetime(1970, 1, 1, tzinfo=_utc_tz)
|
||||||
|
|
||||||
|
@ -29,9 +29,12 @@ class SafeLocalTimeZone(tzlocal):
|
|||||||
utc_tz = tzutc()
|
utc_tz = tzutc()
|
||||||
local_tz = SafeLocalTimeZone()
|
local_tz = SafeLocalTimeZone()
|
||||||
del tzutc, tzlocal
|
del tzutc, tzlocal
|
||||||
|
UNDEFINED_DATE = datetime(101,1,1, tzinfo=utc_tz)
|
||||||
|
|
||||||
if hasattr(speedup, 'parse_iso8601'): # For people running from source without updated binaries
|
if hasattr(speedup, 'parse_iso8601'): # For people running from source without updated binaries
|
||||||
def parse_iso8601(date_string, assume_utc=True, as_utc=True):
|
def parse_iso8601(date_string, assume_utc=False, as_utc=True):
|
||||||
|
if not date_string:
|
||||||
|
return UNDEFINED_DATE
|
||||||
dt, aware, tzseconds = speedup.parse_iso8601(date_string)
|
dt, aware, tzseconds = speedup.parse_iso8601(date_string)
|
||||||
tz = utc_tz if assume_utc else local_tz
|
tz = utc_tz if assume_utc else local_tz
|
||||||
if aware: # timezone was specified
|
if aware: # timezone was specified
|
||||||
@ -133,7 +136,9 @@ else:
|
|||||||
minutes = -minutes
|
minutes = -minutes
|
||||||
return tzoffset(description, 3600*hours + 60*minutes)
|
return tzoffset(description, 3600*hours + 60*minutes)
|
||||||
|
|
||||||
def parse_iso8601(date_string, assume_utc=True, as_utc=True):
|
def parse_iso8601(date_string, assume_utc=False, as_utc=True):
|
||||||
|
if not date_string:
|
||||||
|
return UNDEFINED_DATE
|
||||||
if isinstance(date_string, bytes):
|
if isinstance(date_string, bytes):
|
||||||
date_string = date_string.decode('ascii')
|
date_string = date_string.decode('ascii')
|
||||||
m = iso_pat().match(date_string)
|
m = iso_pat().match(date_string)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user