Skip to content

Commit

Permalink
Don't add timezone info to Solr dates if already there
Browse files Browse the repository at this point in the history
Fixes ckan#7664

Check before appending the "Z" bit otherwise we get a wrong date string
  • Loading branch information
amercader committed Sep 5, 2023
1 parent cff1cba commit 9ed5810
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ckan/lib/search/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def index_package(self,
try:
date = parse(value, default=bogus_date)
if date != bogus_date:
value = date.isoformat() + 'Z'
value = date.isoformat()
if not date.tzinfo:
value += 'Z'
else:
# The date field was empty, so dateutil filled it with
# the default bogus date
Expand Down
5 changes: 5 additions & 0 deletions ckan/tests/lib/search/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def test_index_date_field(self):
"extras": [
{"key": "test_date", "value": "2014-03-22"},
{"key": "test_tim_date", "value": "2014-03-22 05:42:14"},
{"key": "test_full_iso_date", "value": "2019-10-10T01:15:00Z"},
]
}
)
Expand All @@ -142,6 +143,10 @@ def test_index_date_field(self):
response.docs[0]["test_tim_date"].strftime("%Y-%m-%d %H:%M:%S")
== "2014-03-22 05:42:14"
)
assert (
response.docs[0]["test_full_iso_date"].strftime("%Y-%m-%d %H:%M:%S")
== "2019-10-10 01:15:00"
)

def test_index_date_field_wrong_value(self):

Expand Down

0 comments on commit 9ed5810

Please sign in to comment.