With a facet on a Date field, the facet's displayed label for the Month+Year visualization is wrong for some months.
Mistaken months are those with less than 31 days: February, April, June, September, November, and the next month's label for all these.
For instance, April 2014 becomes May 2014, June 2014 becomes July 2014, and so on.
I could repeat the error in a clean installation with search api views, Solr and Db indexes.
Repeated also with all three different date formats.
I think it's a presentation issue since the underlying values seem ok: the count is right, and further refining the search the label of the month is correct (see the screenshots attached).
Thanks
Filippo
Comments
Comment #1
filippo.ledda commentedIt seems it's a DateTime::createFromFormat bug, or at better, very strange behavior.
The conversion is made in the function search_api_facetapi_map_date.
Using
DateTime::createFromFormat("Y-m", "2014-02")
We expect a date where year is 2014 and month is February. But the date has also the current day and time.
So, if today is 31, internally is set 2014-02-31, that is converted back to the timestamp of March 3.
I can't think anything better than bypass the function when this format is involved. Any idea?
Comment #2
filippo.ledda commentedComment #3
filippo.ledda commentedstrtotime seems to solve the issue.
Attached the patch.
Comment #5
rovoI had the same issue, and this patch fixed it for me. I applied it manually, leaving in the $format granularity format line (line 543). I wasn't sure why that line was removed.
- $format = search_api_facetapi_date_get_granularity_format($granularity);Thank you.
Comment #6
filippo.ledda commentedHi, the line has been removed because the variable $format is no longer needed.
Comment #7
switzernThis fix also worked for me to solve the same problem. I've re-rolled the patch to apply to the tip of the Search API repo, per the SimpleTest feedback in the prior version.
Comment #8
manuel garcia commentedConfirming both the bug, and that the patch fixes it.
Comment #9
hartsak commentedOk, I realize this is somewhat old issue but this issue happened to me today. It's 31st day of this month and the date filter was working fine before this day on this month. I tested the patch and the date filter is working perfectly now! I didn't go through the code but I assume the day of the month when the date filter is viewed could affect this making testing more difficult?
This is how the date filter looks like before the patch:
And after the patch:
Comment #10
drunken monkeySorry I didn't see this back then, but it's now already been fixed in #2678856: Date facets show wrong month on leap days.
Comment #11
manuel garcia commented@drunken monkey thanks for the heads up!