Skip to content

Commit 9785bae

Browse files
Fixes an oversight in PR 870 due to which DateOnly values were calculated but not mapped (#874)
1 parent dff07fb commit 9785bae

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/MiniExcel.Core/Reflection/MiniExcelMapper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ public static partial class MiniExcelMapper
156156
if (config.DateOnlyConversionMode == DateOnlyConversionMode.RequireMidnight && dateTimeValue.TimeOfDay != TimeSpan.Zero)
157157
throw new InvalidCastException($"Could not convert cell of type DateTime to DateOnly, because DateTime was not at midnight, but at {dateTimeValue:HH:mm:ss}.");
158158

159-
return DateOnly.FromDateTime(dateTimeValue);
159+
newValue = DateOnly.FromDateTime(dateTimeValue);
160+
pInfo.Property.SetValue(v, newValue);
161+
return newValue;
160162
}
161163

162164
var vs = itemValue?.ToString();

tests/MiniExcel.Core.Tests/MiniExcelIssueTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3681,7 +3681,8 @@ public void TestIssue869(string fileName, DateOnlyConversionMode mode, bool thro
36813681
{
36823682
try
36833683
{
3684-
_ = testFn();
3684+
var result = testFn();
3685+
Assert.Equal(new DateOnly(2025, 1, 1), result[0].Date);
36853686
}
36863687
catch (Exception ex)
36873688
{

0 commit comments

Comments
 (0)