mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
@@ -32,31 +32,25 @@ export function isRelativeBound(bound?: number|IRelativeDateSpec): bound is IRel
|
||||
|
||||
// Returns the number of seconds between 1 January 1970 00:00:00 UTC and the given bound, may it be
|
||||
// a relative date.
|
||||
export function toUnixTimestamp(bound: IRelativeDateSpec|number): number {
|
||||
export function relativeDateToUnixTimestamp(bound: IRelativeDateSpec): number {
|
||||
const localDate = getCurrentTime().startOf('day');
|
||||
const date = moment.utc(localDate.toObject());
|
||||
const periods = Array.isArray(bound) ? bound : [bound];
|
||||
|
||||
if (isRelativeBound(bound)) {
|
||||
const localDate = getCurrentTime().startOf('day');
|
||||
const date = moment.utc(localDate.toObject());
|
||||
const periods = Array.isArray(bound) ? bound : [bound];
|
||||
for (const period of periods) {
|
||||
const {quantity, unit, endOf} = period;
|
||||
|
||||
for (const period of periods) {
|
||||
const {quantity, unit, endOf} = period;
|
||||
date.add(quantity, unit);
|
||||
if (endOf) {
|
||||
date.endOf(unit);
|
||||
|
||||
date.add(quantity, unit);
|
||||
if (endOf) {
|
||||
date.endOf(unit);
|
||||
|
||||
// date must have "hh:mm:ss" set to "00:00:00"
|
||||
date.startOf('day');
|
||||
} else {
|
||||
date.startOf(unit);
|
||||
}
|
||||
// date must have "hh:mm:ss" set to "00:00:00"
|
||||
date.startOf('day');
|
||||
} else {
|
||||
date.startOf(unit);
|
||||
}
|
||||
|
||||
return Math.floor(date.valueOf() / 1000);
|
||||
} else {
|
||||
return bound;
|
||||
}
|
||||
return Math.floor(date.valueOf() / 1000);
|
||||
}
|
||||
|
||||
// Format a relative date.
|
||||
|
||||
Reference in New Issue
Block a user