collective / collective.solr

Solr search engine integration for Plone
https://pypi.org/project/collective.solr/
22 stars 46 forks source link

Fix millisecond management while indexing dates #259

Closed odelaere closed 4 years ago

odelaere commented 4 years ago

I had an issue in plone 4 where some dates were weirdly formatted in strformat. This happens when the millisecond are too close to 0 or 1000. Then its faultly rounded and solr doesn't like a date like this : 2015-07-20T11:07:60.000Z (instead of 2015-07-20T11:07:59.999Z) For this example I had this in the indexer :

71         if isinstance(value, DateTime):
 72             v = value.toZone("UTC")
 73  ->         value = "%04d-%02d-%02dT%02d:%02d:%06.3fZ" % (
 74                 v.year(),
 75                 v.month(),
 76                 v.day(),
 77                 v.hour(),
 78                 v.minute(),
(ipdb>) v.second()
59.99973
(ipdb>) "%06.3f" % v.second()
'60.000'
tisto commented 4 years ago

@odelaere merged and released. Thanks for your fix!