View Single Post
Old 12-15-2011, 06:09 AM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
The following program demonstrates that mi.get() returns a datetime object for a datetime custom column.

Code:
from calibre.ebooks.metadata.book.base import Metadata
from calibre.library.database2 import LibraryDatabase2
from calibre.utils.config import prefs

src = prefs['library_path']
db = LibraryDatabase2(src)

mi = db.get_metadata(1353, index_is_id=True)
dt = mi.get('#mydate')
print dt
print type(dt)
print dt.timetuple()
Output:
Code:
2011-11-23 09:01:10+01:00
<type 'datetime.datetime'>
time.struct_time(tm_year=2011, tm_mon=11, tm_mday=23, tm_hour=9, tm_min=1, tm_sec=10, tm_wday=2, tm_yday=327, tm_isdst=0)
Adding to kovid's suggestion, the delegate used for datetime custom columns is CcDateDelegate at line 246 of delegates.py. This delegate is used to both display and edit the value. The value itself comes from models.py, function data() (line 702) that calls datetime_type() (line 580).

Last edited by chaley; 12-15-2011 at 06:13 AM. Reason: Add delegate info
chaley is offline   Reply With Quote