fix latest/earliest entry functions

This commit is contained in:
Florian Stinglmayr 2023-06-18 15:33:07 +02:00
parent 4f339944c6
commit 20c44d41ca

View File

@ -36,24 +36,28 @@ public class DiscordLogGenerator {
return string.Format("EliteBGS {0}", ver); return string.Format("EliteBGS {0}", ver);
} }
protected virtual DateTime GetDateOfEarliestEntry(Objective objective) { protected virtual DateTime? GetDateOfEarliestEntry(Objective objective) {
return objective var it = objective
.Transactions .Transactions
.SelectMany(x => x.Entries) .OrderBy(x => x.CompletedAtDateTime)
.OrderBy(x => x.Timestamp) .FirstOrDefault()
.First()
.Timestamp
; ;
if (it != null) {
return it.CompletedAtDateTime;
}
return null;
} }
protected virtual DateTime GetDateOfLatestEntry(Objective objective) { protected virtual DateTime? GetDateOfLatestEntry(Objective objective) {
return objective var it = objective
.Transactions .Transactions
.SelectMany(x => x.Entries) .OrderByDescending(x => x.CompletedAtDateTime)
.OrderByDescending(x => x.Timestamp) .FirstOrDefault()
.First()
.Timestamp
; ;
if (it != null) {
return it.CompletedAtDateTime;
}
return null;
} }
protected virtual string GenerateSummary(Objective objective) { protected virtual string GenerateSummary(Objective objective) {
@ -113,10 +117,14 @@ public class DiscordLogGenerator {
DateTime.Now.ToString("dd/MM/yyyy"), DateTime.Now.ToString("dd/MM/yyyy"),
GetToolVersion() GetToolVersion()
); );
var earliest = GetDateOfEarliestEntry(objective);
var latest = GetDateOfLatestEntry(objective);
if (earliest != null && latest != null) {
log.AppendFormat("**Date:** {0} - {1}\n", log.AppendFormat("**Date:** {0} - {1}\n",
GetDateOfEarliestEntry(objective), GetDateOfEarliestEntry(objective),
GetDateOfLatestEntry(objective) GetDateOfLatestEntry(objective)
); );
}
log.AppendFormat("**Target:** {0}\n", location); log.AppendFormat("**Target:** {0}\n", location);
if (!string.IsNullOrEmpty(summary)) { if (!string.IsNullOrEmpty(summary)) {
log.AppendFormat("**Summary**: {0}\n", summary); log.AppendFormat("**Summary**: {0}\n", summary);