Skip to content

Commit f9496e8

Browse files
AndyButlandkjac
andauthored
Ensure dates read from the database are treated as local when constructing entities (2) (#19013)
* Revert "Ensure dates read from the database are treated as local when constructing entities (#18989)" This reverts commit 7b10d39. * Avoid system dates stored with local server time being defaulted to UTC on database read. * ContentScheduleDto.Date is UTC --------- Co-authored-by: kjac <[email protected]>
1 parent 7b10d39 commit f9496e8

28 files changed

+65
-99
lines changed

src/Umbraco.Cms.Api.Management/Factories/DocumentVersionPresentationFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Task<DocumentVersionItemResponseModel> CreateAsync(ContentVersionMe
2626
new ReferenceByIdModel(_entityService.GetKey(contentVersion.ContentTypeId, UmbracoObjectTypes.DocumentType)
2727
.Result),
2828
new ReferenceByIdModel(await _userIdKeyResolver.GetAsync(contentVersion.UserId)),
29-
new DateTimeOffset(contentVersion.VersionDate),
29+
new DateTimeOffset(contentVersion.VersionDate, TimeSpan.Zero), // todo align with datetime offset rework
3030
contentVersion.CurrentPublishedVersion,
3131
contentVersion.CurrentDraftVersion,
3232
contentVersion.PreventCleanup);

src/Umbraco.Core/Models/ContentVersionMeta.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ContentVersionMeta(
3737

3838
public int UserId { get; }
3939

40-
public DateTime VersionDate { get; private set; }
40+
public DateTime VersionDate { get; }
4141

4242
public bool CurrentPublishedVersion { get; }
4343

@@ -47,7 +47,5 @@ public ContentVersionMeta(
4747

4848
public string? Username { get; }
4949

50-
public void SpecifyVersionDateKind(DateTimeKind kind) => VersionDate = DateTime.SpecifyKind(VersionDate, kind);
51-
5250
public override string ToString() => $"ContentVersionMeta(versionId: {VersionId}, versionDate: {VersionDate:s}";
5351
}

src/Umbraco.Infrastructure/Persistence/Dtos/AccessDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ internal class AccessDto
2727
[ForeignKey(typeof(NodeDto), Name = "FK_umbracoAccess_umbracoNode_id2")]
2828
public int NoAccessNodeId { get; set; }
2929

30-
[Column("createDate")]
30+
[Column("createDate", ForceToUtc = false)]
3131
[Constraint(Default = SystemMethods.CurrentDateTime)]
3232
public DateTime CreateDate { get; set; }
3333

34-
[Column("updateDate")]
34+
[Column("updateDate", ForceToUtc = false)]
3535
[Constraint(Default = SystemMethods.CurrentDateTime)]
3636
public DateTime UpdateDate { get; set; }
3737

src/Umbraco.Infrastructure/Persistence/Dtos/AccessRuleDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ internal class AccessRuleDto
2525
[Column("ruleType")]
2626
public string? RuleType { get; set; }
2727

28-
[Column("createDate")]
28+
[Column("createDate", ForceToUtc = false)]
2929
[Constraint(Default = SystemMethods.CurrentDateTime)]
3030
public DateTime CreateDate { get; set; }
3131

32-
[Column("updateDate")]
32+
[Column("updateDate", ForceToUtc = false)]
3333
[Constraint(Default = SystemMethods.CurrentDateTime)]
3434
public DateTime UpdateDate { get; set; }
3535
}

src/Umbraco.Infrastructure/Persistence/Dtos/AuditEntryDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal class AuditEntryDto
3030
[Length(Constants.Audit.IpLength)]
3131
public string? PerformingIp { get; set; }
3232

33-
[Column("eventDateUtc")]
33+
[Column("eventDateUtc", ForceToUtc = false)]
3434
[Constraint(Default = SystemMethods.CurrentDateTime)]
3535
public DateTime EventDateUtc { get; set; }
3636

src/Umbraco.Infrastructure/Persistence/Dtos/ConsentDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class ConsentDto
2929
[Length(512)]
3030
public string? Action { get; set; }
3131

32-
[Column("createDate")]
32+
[Column("createDate", ForceToUtc = false)]
3333
[Constraint(Default = SystemMethods.CurrentDateTime)]
3434
public DateTime CreateDate { get; set; }
3535

src/Umbraco.Infrastructure/Persistence/Dtos/ContentScheduleDto.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal class ContentScheduleDto
2424
[NullSetting(NullSetting = NullSettings.Null)] // can be invariant
2525
public int? LanguageId { get; set; }
2626

27+
// NOTE: this date is explicitly stored and treated as UTC despite the lack of "Utc" postfix.
2728
[Column("date")]
2829
public DateTime Date { get; set; }
2930

src/Umbraco.Infrastructure/Persistence/Dtos/ContentVersionCleanupPolicyDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ internal class ContentVersionCleanupPolicyDto
2727
[NullSetting(NullSetting = NullSettings.Null)]
2828
public int? KeepLatestVersionPerDayForDays { get; set; }
2929

30-
[Column("updated")]
30+
[Column("updated", ForceToUtc = false)]
3131
public DateTime Updated { get; set; }
3232
}

src/Umbraco.Infrastructure/Persistence/Dtos/ContentVersionCultureVariationDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal class ContentVersionCultureVariationDto
3333
[Column("name")]
3434
public string? Name { get; set; }
3535

36-
[Column("date")] // TODO: db rename to 'updateDate'
36+
[Column("date", ForceToUtc = false)] // TODO: db rename to 'updateDate'
3737
public DateTime UpdateDate { get; set; }
3838

3939
[Column("availableUserId")] // TODO: db rename to 'updateDate'

src/Umbraco.Infrastructure/Persistence/Dtos/ContentVersionDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ContentVersionDto
2222
[Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_NodeId", ForColumns = "nodeId,current", IncludeColumns = "id,versionDate,text,userId,preventCleanup")]
2323
public int NodeId { get; set; }
2424

25-
[Column("versionDate")] // TODO: db rename to 'updateDate'
25+
[Column("versionDate", ForceToUtc = false)] // TODO: db rename to 'updateDate'
2626
[Constraint(Default = SystemMethods.CurrentDateTime)]
2727
public DateTime VersionDate { get; set; }
2828

0 commit comments

Comments
 (0)