mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Fix nasty bug in handling of dates in the database. This can prevent calibre from starting. An update is highly recommended
This commit is contained in:
parent
7b87aaf55f
commit
ded6c02dba
@ -12,11 +12,50 @@ from sqlite3 import IntegrityError
|
||||
from threading import Thread
|
||||
from Queue import Queue
|
||||
from threading import RLock
|
||||
from datetime import tzinfo, datetime, timedelta
|
||||
|
||||
from calibre.library import title_sort
|
||||
|
||||
global_lock = RLock()
|
||||
|
||||
def convert_timestamp(val):
|
||||
datepart, timepart = val.split(' ')
|
||||
tz, mult = None, 1
|
||||
x = timepart.split('+')
|
||||
if len(x) > 1:
|
||||
timepart, tz = x
|
||||
else:
|
||||
x = timepart.split('-')
|
||||
if len(x) > 1:
|
||||
timepart, tz = x
|
||||
mult = -1
|
||||
|
||||
year, month, day = map(int, datepart.split("-"))
|
||||
timepart_full = timepart.split(".")
|
||||
hours, minutes, seconds = map(int, timepart_full[0].split(":"))
|
||||
if len(timepart_full) == 2:
|
||||
microseconds = int(timepart_full[1])
|
||||
else:
|
||||
microseconds = 0
|
||||
if tz is not None:
|
||||
h, m = map(int, tz.split(':'))
|
||||
delta = timedelta(minutes=mult*(60*h + m))
|
||||
tz = type('CustomTZ', (tzinfo,), {'utcoffset':lambda self, dt:delta,
|
||||
'dst':lambda self,dt:timedelta(0)})()
|
||||
|
||||
val = datetime(year, month, day, hours, minutes, seconds, microseconds,
|
||||
tzinfo=tz)
|
||||
if tz is not None:
|
||||
val = datetime(*(val.utctimetuple()[:6]))
|
||||
return val
|
||||
|
||||
def adapt_datetime(dt):
|
||||
dt = datetime(*(dt.utctimetuple()[:6]))
|
||||
return dt.isoformat(' ')
|
||||
|
||||
sqlite.register_adapter(datetime, adapt_datetime)
|
||||
sqlite.register_converter('timestamp', convert_timestamp)
|
||||
|
||||
class Concatenate(object):
|
||||
'''String concatenation aggregator for sqlite'''
|
||||
def __init__(self, sep=','):
|
||||
|
Loading…
x
Reference in New Issue
Block a user