Use UTC for system dates in Umbraco (#19822)

* Persist and expose Umbraco system dates as UTC (#19705)

* Updated persistence DTOs defining default dates to use UTC.

* Remove ForceToUtc = false from all persistence DTO attributes (default when not specified is true).

* Removed use of SpecifyKind setting dates to local.

* Removed unnecessary Utc suffixes on properties.

* Persist current date time with UtcNow.

* Removed further necessary Utc suffixes and fixed failing unit tests.

* Added migration for SQL server to update database date default constraints.

* Added comment justifying not providing a migration for SQLite default date constraints.

* Ensure UTC for datetimes created from persistence DTOs.

* Ensure UTC when creating dates for published content rendering in Razor and outputting in delivery API.

* Fixed migration SQL syntax.

* Introduced AuditItemFactory for creating entries for the backoffice document history, so we can control the UTC setting on the retrieved persisted dates.

* Ensured UTC dates are retrieved for document versions.

* Ensured UTC is returned for backoffice display of last edited and published for variant content.

* Fixed SQLite syntax for default current datetime.

* Apply suggestions from code review

Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com>

* Further updates from code review.

---------

Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com>

* Migrate system dates from local server time to UTC (#19798)

* Add settings for the migration.

* Add migration and implement for SQL server.

* Implement for SQLite.

* Fixes from testing with SQL Server.

* Fixes from testing with SQLite.

* Code tidy.

* Cleaned up usings.

* Removed audit log date from conversion.

* Removed webhook log date from conversion.

* Updated update date initialization on saving dictionary items.

* Updated filter on log queries.

* Use timezone ID instead of system name to work cross-culture.

---------

Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com>
This commit is contained in:
Andy Butland
2025-08-22 11:59:23 +02:00
committed by GitHub
parent b427a8cbdd
commit d623476902
176 changed files with 951 additions and 5459 deletions

View File

@@ -1265,7 +1265,7 @@ public class ContentService : RepositoryService, IContentService
// publish the culture(s)
// we don't care about the response here, this response will be rechecked below but we need to set the culture info values now.
var publishTime = DateTime.Now;
var publishTime = DateTime.UtcNow;
foreach (CultureImpact? impact in impacts)
{
content.PublishCulture(impact, publishTime, _propertyEditorCollection);
@@ -1980,7 +1980,7 @@ public class ContentService : RepositoryService, IContentService
// variant content type - publish specified cultures
// invariant content type - publish only the invariant culture
var publishTime = DateTime.Now;
var publishTime = DateTime.UtcNow;
if (content.ContentType.VariesByCulture())
{
return culturesToPublish.All(culture =>
@@ -2395,7 +2395,7 @@ public class ContentService : RepositoryService, IContentService
if (deletePriorVersions)
{
IContent? content = GetVersion(versionId);
DeleteVersions(id, content?.UpdateDate ?? DateTime.Now, userId);
DeleteVersions(id, content?.UpdateDate ?? DateTime.UtcNow, userId);
}
scope.WriteLock(Constants.Locks.ContentTree);
@@ -3179,7 +3179,7 @@ public class ContentService : RepositoryService, IContentService
.ToArray();
// publish the culture(s)
var publishTime = DateTime.Now;
var publishTime = DateTime.UtcNow;
if (!impactsToPublish.All(impact => content.PublishCulture(impact, publishTime, _propertyEditorCollection)))
{
return new PublishResult(PublishResultType.FailedPublishContentInvalid, evtMsgs, content);
@@ -3447,7 +3447,7 @@ public class ContentService : RepositoryService, IContentService
// otherwise it would remain released == published
ContentScheduleCollection contentSchedule = _documentRepository.GetContentSchedule(content.Id);
IReadOnlyList<ContentSchedule> pastReleases =
contentSchedule.GetPending(ContentScheduleAction.Expire, DateTime.Now);
contentSchedule.GetPending(ContentScheduleAction.Expire, DateTime.UtcNow);
foreach (ContentSchedule p in pastReleases)
{
contentSchedule.Remove(p);
@@ -3722,7 +3722,7 @@ public class ContentService : RepositoryService, IContentService
scope.Complete();
}
DateTime now = DateTime.Now;
DateTime now = DateTime.UtcNow;
foreach (var culture in cultures)
{
foreach (IProperty property in blueprint.Properties)