Ensure dates read from the database are treated as local when constructing entities (#18989)

* Ensure dates read from the database are treated as local when constructing entities.

* Fixed typos in comments.
This commit is contained in:
Andy Butland
2025-04-11 09:32:05 +02:00
committed by mole
parent 97b3023e14
commit 7b10d39d66
7 changed files with 65 additions and 30 deletions

View File

@@ -1,3 +1,4 @@
using System.Data;
using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
@@ -98,6 +99,16 @@ internal class DocumentVersionRepository : IDocumentVersionRepository
Page<ContentVersionMeta>? page =
_scopeAccessor.AmbientScope?.Database.Page<ContentVersionMeta>(pageIndex + 1, pageSize, query);
// Dates stored in the database are local server time, but for SQL Server, will be considered
// as DateTime.Kind = Utc. Fix this so we are consistent when later mapping to DataTimeOffset.
if (page is not null)
{
foreach (ContentVersionMeta item in page.Items)
{
item.SpecifyVersionDateKind(DateTimeKind.Local);
}
}
totalRecords = page?.TotalItems ?? 0;
return page?.Items;