Bug report #17681
Negative values for age in expressions
|Affected QGIS version:||2.18.14||Regression?:||No|
|Operating System:||Mac OS High Sierra||Easy fix?:||No|
|Pull Request or Patch supplied:||Yes||Resolution:||fixed/implemented|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||25578|
In calculating the difference between two dates from a long list of starting and ending dates (from medieval period to now), some of the outcomes produce negative values:
DATEfrom DATEto AGE (in days)
1380-01-01 1515-12-31 -37
1100-01-01 1225-12-31 -3689
580-01-01 665-12-31 -18299
1612-01-01 1697-12-31 -18299
Whereas most other dates do provide correct ages (>90%):
1001-01-01 1199-12-31 23339
1814-01-01 2016-12-31 24434
The expression used here is: day(age("DATEto","DATEfrom")). Is this a bug?
#2 Updated by Sandro Santilli almost 3 years ago
- Assignee set to Sandro Santilli
- Status changed from Open to In Progress
I'm looking at this, starting from the existing unit test tests/src/core/testqgsexpression.cpp (run via output/bin/qgis_expressiontest).
The test in there puts later day first, but I'm not sure yet about the test code semantic:
#3 Updated by Sandro Santilli almost 3 years ago
I'm guessing it's an overflow of `int` type used to compute seconds between the dates.
The first age you report as working has 4291574400, max integer is 4294967296.
The first non-working age has 6279724800 seconds, so turns to negative.
I'm working on adding an automated test for this.