Skip to content

Commit

Permalink
Add year interval for DateHistogramFacet
Browse files Browse the repository at this point in the history
  • Loading branch information
nrsimha authored Jul 13, 2021
1 parent 7cc4484 commit 1ac597f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions elasticsearch_dsl/faceted_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ def get_value_filter(self, filter_value):
)


def _date_interval_year(d):
return d.replace(year=d.year+1, day=(28 if d.month == 2 and d.day == 29 else d.day))


def _date_interval_month(d):
return (d + timedelta(days=32)).replace(day=1)

Expand All @@ -188,6 +192,8 @@ class DateHistogramFacet(Facet):
agg_type = "date_histogram"

DATE_INTERVALS = {
"year": _date_interval_year,
"1Y": _date_interval_year,
"month": _date_interval_month,
"1M": _date_interval_month,
"week": _date_interval_week,
Expand Down
4 changes: 4 additions & 0 deletions tests/test_faceted_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def test_date_histogram_facet_with_1970_01_01_date():
@pytest.mark.parametrize(
["interval_type", "interval"],
[
("interval", "year"),
("calendar_interval", "year"),
("interval", "month"),
("calendar_interval", "month"),
("interval", "week"),
Expand All @@ -160,6 +162,8 @@ def test_date_histogram_facet_with_1970_01_01_date():
("fixed_interval", "day"),
("interval", "hour"),
("fixed_interval", "hour"),
("interval", "1Y"),
("calendar_interval", "1Y"),
("interval", "1M"),
("calendar_interval", "1M"),
("interval", "1w"),
Expand Down

0 comments on commit 1ac597f

Please sign in to comment.