Skip to content

Commit

Permalink
bug[TW25783]: Fix Filter DateTime Column
Browse files Browse the repository at this point in the history
Change-Id: I88e37a6ff8a89fdbaf6a8062327e983e540450b8
  • Loading branch information
vaibhavypatel committed Apr 3, 2024
1 parent 44150cc commit 4b0fdfc
Showing 1 changed file with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.nebula.widgets.xviewer;

import java.util.Calendar;
import java.util.Date;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -134,31 +135,28 @@ public boolean select(Viewer viewer, Object parentElement, Object element) {
String cellStr =
xViewer.getColumnText(element, xViewer.getCustomizeMgr().getColumnNumFromXViewerColumn(xCol));
if (Strings.isValid(cellStr)) {
Date cellDate = XViewerSorter.parseDatePair(cellStr, "").getFirst();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm a");
LocalDateTime cellDate = LocalDateTime.parse(cellStr, formatter);
if (cellDate != null) {
ColumnDateFilter columnDateFilter = colIdToDateFilter.get(xCol.getId());
Calendar cellCal = Calendar.getInstance();
cellCal.setTime(cellDate);
Calendar filterCal = Calendar.getInstance();
Date filterDate1 = columnDateFilter.getDate1();
filterCal.setTime(filterDate1);
LocalDateTime filterDate1 =
LocalDateTime.ofInstant(columnDateFilter.getDate1().toInstant(), ZoneId.systemDefault());
DateRangeType rangeType = columnDateFilter.getType();
if (rangeType == DateRangeType.Equals_Date) {
if (cellCal.get(Calendar.YEAR) != filterCal.get(Calendar.YEAR) || cellCal.get(
Calendar.MONTH) != filterCal.get(Calendar.MONTH) || cellCal.get(
Calendar.DAY_OF_MONTH) != filterCal.get(Calendar.DAY_OF_MONTH)) {
if (cellDate.getYear() != filterDate1.getYear() || cellDate.getMonth() != filterDate1.getMonth() || cellDate.getDayOfMonth() != filterDate1.getDayOfMonth()) {
return false;
}
} else if (rangeType == DateRangeType.After_Date && cellDate.before(filterDate1)) {
} else if (rangeType == DateRangeType.After_Date && cellDate.isBefore(filterDate1)) {
return false;
} else if (rangeType == DateRangeType.Before_Date && cellDate.after(filterDate1)) {
} else if (rangeType == DateRangeType.Before_Date && cellDate.isAfter(filterDate1)) {
return false;
} else if (rangeType == DateRangeType.Between_Dates) {
if (cellDate.before(filterDate1)) {
if (cellDate.isBefore(filterDate1)) {
return false;
}
Date filterDate2 = columnDateFilter.getDate2();
if (cellDate.after(filterDate2)) {
LocalDateTime filterDate2 =
LocalDateTime.ofInstant(columnDateFilter.getDate2().toInstant(), ZoneId.systemDefault());
if (cellDate.isAfter(filterDate2)) {
return false;
}
}
Expand Down

0 comments on commit 4b0fdfc

Please sign in to comment.