From 1c478d35151cb9e3b66b5f8e829cf7f1daa451b7 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Thu, 25 Jul 2024 09:38:10 +0200 Subject: [PATCH] Bugfix for comparer when times value is null and DateTime.Now is inconsistent --- src/BreCalClient/MainWindow.xaml.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 734408d..475c8ac 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -817,14 +817,20 @@ namespace BreCalClient { if (x.Shipcall == null) return 0; if (y.Shipcall == null) return 0; - DateTime xDate = (x.Shipcall.Type == ShipcallType.Arrival) ? x.Eta ?? DateTime.Now : x.Etd ?? DateTime.Now; + DateTime now = DateTime.Now; + + DateTime xDate = (x.Shipcall.Type == ShipcallType.Arrival) ? (x.Eta ?? now) : (x.Etd ?? now); + Times? xTimes = x.GetTimesForParticipantType(ParticipantType.AGENCY); if(xTimes != null) - xDate = (x.Shipcall.Type == ShipcallType.Arrival) ? xTimes.EtaBerth ?? DateTime.Now : xTimes.EtdBerth ?? DateTime.Now; - DateTime yDate = (y.Shipcall.Type == ShipcallType.Arrival) ? y.Eta ?? DateTime.Now : y.Etd ?? DateTime.Now; + xDate = (x.Shipcall.Type == ShipcallType.Arrival) ? (xTimes.EtaBerth ?? now) : (xTimes.EtdBerth ?? now); + + DateTime yDate = (y.Shipcall.Type == ShipcallType.Arrival) ? (y.Eta ?? now) : (y.Etd ?? now); + Times? yTimes = y.GetTimesForParticipantType(ParticipantType.AGENCY); if (yTimes != null) - yDate = (y.Shipcall.Type == ShipcallType.Arrival) ? yTimes.EtaBerth ?? DateTime.Now : yTimes.EtdBerth ?? DateTime.Now; + yDate = (y.Shipcall.Type == ShipcallType.Arrival) ? (yTimes.EtaBerth ?? now) : (yTimes.EtdBerth ?? now); + return DateTime.Compare(xDate, yDate); }); break;