From 4b0fdfcbda555e2aa979ff02e8d21a0f2ef3285e Mon Sep 17 00:00:00 2001 From: "Patel (US), Vaibhav Y" Date: Wed, 3 Apr 2024 12:01:11 -0500 Subject: [PATCH] bug[TW25783]: Fix Filter DateTime Column Change-Id: I88e37a6ff8a89fdbaf6a8062327e983e540450b8 --- .../widgets/xviewer/XViewerTextFilter.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerTextFilter.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerTextFilter.java index 38125d2b2..b5d856d28 100644 --- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerTextFilter.java +++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerTextFilter.java @@ -5,7 +5,7 @@ * 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: @@ -13,8 +13,9 @@ *******************************************************************************/ 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; @@ -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; } }