(core) Fix date filter for DateTime columns.

Summary:
Date filter was not taking timezone correclty into account, which was
causing to wrong-inclusion and wrong-exclusion of dates near the
bounds.

Diff fixes that, it also bring little refactoring that hopefully clarifies things a little.

Test Plan: Includes brand new test for `app/common/ColumnFilterFunc`.

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D3763
This commit is contained in:
Cyprien P
2023-01-17 12:05:22 +01:00
parent a822a5771c
commit 18d016c745
6 changed files with 99 additions and 55 deletions

View File

@@ -3,7 +3,7 @@ import {CellValue} from 'app/common/DocActions';
import {
FilterSpec, FilterState, IRelativeDateSpec, isRangeFilter, isRelativeBound, makeFilterState
} from "app/common/FilterState";
import {toUnixTimestamp} from "app/common/RelativeDates";
import {relativeDateToUnixTimestamp} from "app/common/RelativeDates";
import {nativeCompare} from 'app/common/gutil';
import {Computed, Disposable, Observable} from 'grainjs';
@@ -124,9 +124,11 @@ export class ColumnFilter extends Disposable {
return this.makeFilterJson() !== this._initialFilterJson;
}
public getBoundsValue(minMax: 'min' | 'max'): number | undefined {
// Retuns min or max as a numeric value.
public getBoundsValue(minMax: 'min' | 'max'): number {
const value = this[minMax].get();
return isRelativeBound(value) ? toUnixTimestamp(value) : value;
if (value === undefined) { return minMax === 'min' ? -Infinity : +Infinity; }
return isRelativeBound(value) ? relativeDateToUnixTimestamp(value) : value;
}