Skip to content

Commit b92eb6c

Browse files
committed
fix: normalize date range to whole-day boundaries
1 parent 322e857 commit b92eb6c

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

lib/EasyInk.Net/EasyInk.Printer/src/UI/Presenters/LogsPresenter.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,20 @@ private static void WriteCsvValue(TextWriter writer, string? value)
199199

200200
private static void NormalizeRange(ref DateTime from, ref DateTime to)
201201
{
202-
if (from <= to) return;
202+
var fromDate = from.Date;
203+
var toDate = to.Date;
203204

204-
var tmp = from;
205-
from = to;
206-
to = tmp;
205+
if (fromDate > toDate)
206+
{
207+
var tmp = fromDate;
208+
fromDate = toDate;
209+
toDate = tmp;
210+
}
211+
212+
from = fromDate;
213+
to = toDate >= DateTime.MaxValue.Date
214+
? DateTime.MaxValue
215+
: toDate.AddDays(1).AddTicks(-1);
207216
}
208217

209218
private void Post(Action<ILogsView> update)

lib/EasyInk.Net/EasyInk.Printer/tests/LogsPresenterTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ namespace EasyInk.Printer.Tests;
1111

1212
public class LogsPresenterTests
1313
{
14+
[Fact]
15+
public async Task RefreshAsync_UsesWholeDayRangeForDateOnlyFilters()
16+
{
17+
LangManager.Initialize("zh-CN");
18+
var service = new FakeAuditService(Array.Empty<PrintAuditLog>());
19+
var presenter = new LogsPresenter(service);
20+
presenter.Attach(new TestLogsView());
21+
22+
await presenter.RefreshAsync(
23+
new DateTime(2026, 5, 17, 15, 30, 0),
24+
new DateTime(2026, 5, 18, 9, 45, 0));
25+
26+
Assert.Equal(new DateTime(2026, 5, 17, 0, 0, 0), service.LastStartTime);
27+
Assert.Equal(new DateTime(2026, 5, 18, 23, 59, 59, 999).AddTicks(9999), service.LastEndTime);
28+
}
29+
1430
[Fact]
1531
public async Task ExportCsvAsync_WritesCsvWithCurrentDateRangeAndEscaping()
1632
{
@@ -41,7 +57,7 @@ public async Task ExportCsvAsync_WritesCsvWithCurrentDateRangeAndEscaping()
4157

4258
Assert.Equal(1, count);
4359
Assert.Equal(startTime, service.LastStartTime);
44-
Assert.Equal(endTime, service.LastEndTime);
60+
Assert.Equal(new DateTime(2026, 5, 18, 23, 59, 59, 999).AddTicks(9999), service.LastEndTime);
4561
Assert.StartsWith("时间,打印机,状态,用户,标签类型,任务ID,错误", csv);
4662
Assert.Contains("\"Printer, A\"", csv);
4763
Assert.Contains("\"job\"\"1\"", csv);
@@ -79,6 +95,8 @@ public List<PrintAuditLog> QueryLogs(
7995
int limit = 100,
8096
int offset = 0)
8197
{
98+
LastStartTime = startTime;
99+
LastEndTime = endTime;
82100
return new List<PrintAuditLog>(_logs);
83101
}
84102

0 commit comments

Comments
 (0)