Skip to content

Commit

Permalink
fix: date filters in grid could filter out items based on timezone
Browse files Browse the repository at this point in the history
* started fix filters

* lint fixed

* fixing timezone

* fixed issue with timezone when select a date to filter

* Remove debug message

* fix date filter time zone for quick filter

* rename method to format filters in grids

---------

Co-authored-by: RenzoPrats <renzoprats@icloud.com>
Co-authored-by: Nathan <humbertclaude.nathan@gmail.com>
Co-authored-by: Antoine Hurard <antoine.reliefapps@gmail.com>
  • Loading branch information
4 people committed Aug 30, 2023
1 parent 7f05dce commit 2f37b39
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions libs/safe/src/lib/components/ui/core-grid/grid/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,48 @@ export class SafeGridComponent
* @param filter Filter event.
*/
public onFilterChange(filter: CompositeFilterDescriptor): void {
// format filter before sending
this.formatFilter(filter);

if (!this.loadingRecords) {
this.filter = filter;
this.filterChange.emit(filter);
}
}

/**
* Format filter before sending.
* Adjust date filters to remove timezone.
*
* @param filter Filter value.
*/
private formatFilter(filter: any) {
filter.filters.forEach((filter: any) => {
// if there are sub filters
if (filter.filters) {
this.formatFilter(filter);
} else if (filter.value instanceof Date) {
const currentDate = filter.value;
const hoursToAdjustTimezone = Math.floor(
(currentDate as Date).getTimezoneOffset() / 60
);
const minutesToAdjustTimezone =
(currentDate as Date).getTimezoneOffset() % 60;

const dateObj = new Date(currentDate);
dateObj.setHours(dateObj.getHours() - hoursToAdjustTimezone);
dateObj.setMinutes(dateObj.getMinutes() - minutesToAdjustTimezone);
// Convert the modified date back to the original format
const modifiedDateString = dateObj
.toISOString()
.replace('T00:00:00.000Z', '');
const modifiedDate = new Date(modifiedDateString);

filter.value = modifiedDate;
}
});
}

/**
* Toggles quick filter visibility
*/
Expand Down

0 comments on commit 2f37b39

Please sign in to comment.