From 20c44d41cab270e9f75dbbca776e7fb055775f71 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Sun, 18 Jun 2023 15:33:07 +0200 Subject: [PATCH] fix latest/earliest entry functions --- EliteBGS/DiscordLogGenerator.cs | 40 ++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/EliteBGS/DiscordLogGenerator.cs b/EliteBGS/DiscordLogGenerator.cs index b155a49..87b135a 100644 --- a/EliteBGS/DiscordLogGenerator.cs +++ b/EliteBGS/DiscordLogGenerator.cs @@ -36,24 +36,28 @@ public class DiscordLogGenerator { return string.Format("EliteBGS {0}", ver); } - protected virtual DateTime GetDateOfEarliestEntry(Objective objective) { - return objective + protected virtual DateTime? GetDateOfEarliestEntry(Objective objective) { + var it = objective .Transactions - .SelectMany(x => x.Entries) - .OrderBy(x => x.Timestamp) - .First() - .Timestamp + .OrderBy(x => x.CompletedAtDateTime) + .FirstOrDefault() ; + if (it != null) { + return it.CompletedAtDateTime; + } + return null; } - protected virtual DateTime GetDateOfLatestEntry(Objective objective) { - return objective + protected virtual DateTime? GetDateOfLatestEntry(Objective objective) { + var it = objective .Transactions - .SelectMany(x => x.Entries) - .OrderByDescending(x => x.Timestamp) - .First() - .Timestamp + .OrderByDescending(x => x.CompletedAtDateTime) + .FirstOrDefault() ; + if (it != null) { + return it.CompletedAtDateTime; + } + return null; } protected virtual string GenerateSummary(Objective objective) { @@ -113,10 +117,14 @@ public class DiscordLogGenerator { DateTime.Now.ToString("dd/MM/yyyy"), GetToolVersion() ); - log.AppendFormat("**Date:** {0} - {1}\n", - GetDateOfEarliestEntry(objective), - GetDateOfLatestEntry(objective) - ); + var earliest = GetDateOfEarliestEntry(objective); + var latest = GetDateOfLatestEntry(objective); + if (earliest != null && latest != null) { + log.AppendFormat("**Date:** {0} - {1}\n", + GetDateOfEarliestEntry(objective), + GetDateOfLatestEntry(objective) + ); + } log.AppendFormat("**Target:** {0}\n", location); if (!string.IsNullOrEmpty(summary)) { log.AppendFormat("**Summary**: {0}\n", summary);