kgabryje commented on code in PR #36270:
URL: https://github.com/apache/superset/pull/36270#discussion_r2667897082
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/utils/dateFilterComparator.ts:
##########
@@ -17,25 +17,53 @@
* under the License.
*/
-const dateFilterComparator = (filterDate: Date, cellValue: Date) => {
+/**
+ * Timezone-safe date comparator for AG Grid date filters.
+ *
+ * This comparator normalizes both dates to UTC midnight before comparison,
+ * fixing the off-by-one day bug that occurs when:
+ * - User's timezone differs from UTC
+ * - Data is stored in UTC but filtered in local time
+ * - Midnight boundary crossing due to timezone offset
+ *
+ * Bug references:
+ * - AG Grid Issue #8611: UTC Date Editor Problem
+ * - AG Grid Issue #3921: DateFilter timezone regression
+ *
+ */
+const dateFilterComparator = (
+ filterDate: Date,
+ cellValue: Date | null | undefined,
+) => {
+ if (cellValue == null) {
+ return -1;
+ }
+
const cellDate = new Date(cellValue);
- cellDate.setHours(0, 0, 0, 0);
- if (Number.isNaN(cellDate?.getTime())) return -1;
+ if (Number.isNaN(cellDate?.getTime())) {
Review Comment:
nit: the optional chaining is probably not necessary here, even if cellValue
is not a date string, cellDate will still be a Date object
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]