Skip to content

Commit

Permalink
Merge pull request #40 from DSaladinCH/develop
Browse files Browse the repository at this point in the history
Fix infinite loop on statistics calculation
  • Loading branch information
DominicSaladin authored Jul 10, 2024
2 parents 76ad84c + b6750a5 commit 913a8b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions speed-time/Dialogs/TimeStatistics.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ private async Task LoadData()
currentStartOfWeek = currentStartOfWeek.AddDays(-1);
}

while (currentStartOfWeek <= EndDate)
for (DateTime current = StartDate; current <= EndDate; current = current.AddDays(7))
{
DateTime currentEndOfWeek = currentStartOfWeek.AddDays(6); // Move to Sunday
DateTime currentEndOfWeek = current.AddDays(6); // Move to Sunday

// Adjust dates to fit within the range
DateTime effectiveStart = (currentStartOfWeek < StartDate) ? StartDate : currentStartOfWeek;
DateTime effectiveStart = (current < StartDate) ? StartDate : current;
DateTime effectiveEnd = (currentEndOfWeek > EndDate) ? EndDate : currentEndOfWeek;

double targetWorkhours = SettingsModel.Instance.Workdays.GetWorkHoursForRange(effectiveStart, effectiveEnd);
Expand All @@ -269,11 +269,8 @@ private async Task LoadData()
if (targetWorkhours == 0 && actualWorkhours == 0)
continue;

actualWork.Add(new(currentStartOfWeek, actualWorkhours));
targetWork.Add(new(currentStartOfWeek, targetWorkhours));

// Move to the start of the next week
currentStartOfWeek = currentStartOfWeek.AddDays(7);
actualWork.Add(new(current, actualWorkhours));
targetWork.Add(new(current, targetWorkhours));
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion speed-time/speed-time.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<ApplicationIcon>Icon.ico</ApplicationIcon>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<Version>0.17.1</Version>
<Version>0.17.2</Version>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down

0 comments on commit 913a8b9

Please sign in to comment.