Skip to content

Commit

Permalink
applied datetime handling patch which correctly preserves time compon…
Browse files Browse the repository at this point in the history
…ent (thanks fred). Fixes issue #16

git-svn-id: http://solrpy.googlecode.com/svn/trunk@58 3a1802d4-3049-0410-b936-3fc652297a5e
  • Loading branch information
ed.summers committed Feb 18, 2010
1 parent 1e3535f commit 1575649
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions solr/core.py
Expand Up @@ -714,10 +714,12 @@ def __add(self, lst, fields):
if value == None:
continue
# Do some basic data conversion
if isinstance(value, datetime.date):
value = datetime.datetime.combine(value, datetime.time(tzinfo=UTC()))
if isinstance(value, datetime.datetime):
value = utc_to_string(value)
elif isinstance(value, datetime.date):
value = datetime.datetime.combine(
value, datetime.time(tzinfo=UTC()))
value = utc_to_string(value)
elif isinstance(value, bool):
value = value and 'true' or 'false'

Expand Down
14 changes: 14 additions & 0 deletions tests/test_all.py
Expand Up @@ -18,6 +18,7 @@

# solrpy
from solr import SolrConnection, SolrPaginator
import solr.core

SOLR_PATH = "/solr"
SOLR_HOST = "localhost"
Expand Down Expand Up @@ -867,6 +868,19 @@ def test_date(self):
self.assertEqual(str(results[0]['creation_time']),
'1969-05-28 00:00:00+00:00')

def test_datetime_utc(self):
id = data = user_id = get_rand_string()
dt = datetime.datetime(
1969, 5, 28, 12, 24, 42, tzinfo=solr.core.UTC())
self.conn.add(id=id, user_id=user_id, data=data, creation_time=dt)
self.conn.commit()
results = self.conn.query("id:%s" % id).results
self.assertEqual(len(results), 1)
self.assertTrue(isinstance(results[0]['creation_time'],
datetime.datetime))
self.assertEqual(str(results[0]['creation_time']),
'1969-05-28 12:24:42+00:00')

def test_multi_date(self):
id = data = user_id = get_rand_string()
dates = [datetime.date(1969, 5, 28), datetime.date(2009, 1, 30)]
Expand Down

0 comments on commit 1575649

Please sign in to comment.