# Issue in Offset Rounding in case Offset leads to change in the DST state

**URL:** <https://discuss.elastic.co/t/issue-in-offset-rounding-in-case-offset-leads-to-change-in-the-dst-state/296986>\
**Category:** Elasticsearch\
**Created:** [February 11, 2022, 2:33pm UTC](https://discuss.elastic.co/t/issue-in-offset-rounding-in-case-offset-leads-to-change-in-the-dst-state/296986 "2022-02-11T14:33:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRIYANSHU\_KUSHWAHA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priyanshu_kushwaha/32/101726_2.png) [@PRIYANSHU\_KUSHWAHA](https://discuss.elastic.co/u/PRIYANSHU_KUSHWAHA)\
**Post date:** [February 11, 2022, 2:33pm UTC](https://discuss.elastic.co/t/issue-in-offset-rounding-in-case-offset-leads-to-change-in-the-dst-state/296986/1 "2022-02-11T14:33:35Z")

</div>

I am using ES version 7.11.

```auto
{
  "size": 0,
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "must": [
            {
              "terms": {
                "deleted": [
                  "false"
                ]
              }
            }
          ]
        }
      }
    }
  },
  "aggregations": {
    "DEFAULT": {
      "filter": {
        "match_all": {}
      },
      "aggregations": {
        "DURATION_AGGREGATION": {
          "date_histogram": {
            "script": {
              "inline": "date-range-histo-script",
              "lang": "native",
              "params": {
                "post_offset": "-2d",
                "start_seed": 1640991600000,
                "tzLocation": "Europe/Madrid",
                "pre_offset": "2d",
                "timezone": "Europe/Madrid",
                "end_date_field": "endDate",
                "interval": "1w",
                "max_seed": 1648850399999,
                "start_date_field": "startDate"
              }
            },
            "interval": "1w",
            "min_doc_count": 1,
            "time_zone": "Europe/Madrid",
            "offset": "-172800000ms"
          }
        }
      }
    }
  }
}

```

My query is related to Offset rounding used in DateHistogramAggregator.class

org/Elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.class:165

```auto
 long rounded = DateHistogramAggregator.this.preparedRounding.round(value);

```

Suppose, value is `1648249200000` == \> Friday, 25 March 2022 23:00:00 UTC

after rounding the value is 1648245600000 ==\> Friday, 25 March 2022 22:00:00 UTC

Reason for above is DST correction has been applied but DST in "Europe/Madrid" starts at 27th March 2022 02:00:00.

```auto
public long round(long utcMillis) {
                    return delegatePrepared.round(utcMillis - OffsetRounding.this.offset) + OffsetRounding.this.offset;
                }

org/elasticsearch/common/Rounding.class:1051

```

This is happening because we are subtracting the offset which shifts the above value to Friday, 27 March 2022 23:00:00 UTC and then we are rounding it in which DST correction is also considered as the value has surpassed DST start time.

Isn't the above DST correction wrong?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 11, 2022, 2:33pm UTC](https://discuss.elastic.co/t/issue-in-offset-rounding-in-case-offset-leads-to-change-in-the-dst-state/296986/2 "2022-03-11T14:33:51Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
