From 1b662769bf952698d74f6d2bbc567984e1ff1d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 8 Jul 2010 20:01:11 +0200 Subject: [PATCH] Fix extract function in SQLite to work with date (transplanted from faf73da610031ab5d7b49e89c4aca221846b10d9) --- trytond/backend/sqlite/database.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/trytond/backend/sqlite/database.py b/trytond/backend/sqlite/database.py index 6f4bb89637..826a14a5fe 100644 --- a/trytond/backend/sqlite/database.py +++ b/trytond/backend/sqlite/database.py @@ -28,14 +28,18 @@ def extract(lookup_type, date): if date is None: return None try: - datepart, timepart = date.split(" ") - 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]) - date = datetime.datetime(year, month, day, hours, minutes, seconds, - microseconds) + if len(date) == 10: + year, month, day = map(int, date.split('-')) + date = datetime.date(year, month, day) + else: + datepart, timepart = date.split(" ") + 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]) + date = datetime.datetime(year, month, day, hours, minutes, seconds, + microseconds) except: return None if lookup_type.lower() == 'century': @@ -58,7 +62,7 @@ def extract(lookup_type, date): return date.month / 4 + 1 elif lookup_type.lower() == 'week': return date.isocalendar()[1] - return getattr(date, lookup_type) + return getattr(date, lookup_type.lower()) def date_trunc(_type, date): if _type == 'second':