mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-25 23:57:20 -04:00
This will correct/switch "year" unit diffing from the current integer
subtraction to a crono subtraction. Consequently, two dates are (at
least) one year apart now if (at least) a full calendar year separates
them. The previous implementation simply subtracted the year part of the
dates.
Note: this parts with ES SQL's implementation of the same function,
which itself is aligned with MS SQL's implementation, which works
equivalent to an integer subtraction.
Fixes #112482.
(cherry picked from commit f7ff00f645
)
24 lines
798 B
Text
Generated
24 lines
798 B
Text
Generated
// This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
|
|
|
|
*Examples*
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/date.csv-spec[tag=docsDateDiff]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/date.csv-spec[tag=docsDateDiff-result]
|
|
|===
|
|
When subtracting in calendar units - like year, month a.s.o. - only the fully elapsed units are counted.
|
|
To avoid this and obtain also remainders, simply switch to the next smaller unit and do the date math accordingly.
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/date.csv-spec[tag=evalDateDiffYearForDocs]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/date.csv-spec[tag=evalDateDiffYearForDocs-result]
|
|
|===
|
|
|