Skip to content

Commit 7495c3c

Browse files
authored
Treat content schedule dates as UTC (#19028)
1 parent f9496e8 commit 7495c3c

File tree

13 files changed

+172
-25
lines changed

13 files changed

+172
-25
lines changed

src/Umbraco.Core/Extensions/ContentExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ public static ContentStatus GetStatus(this IContent content, ContentScheduleColl
245245
}
246246

247247
IEnumerable<ContentSchedule> expires = contentSchedule.GetSchedule(culture, ContentScheduleAction.Expire);
248-
if (expires != null && expires.Any(x => x.Date > DateTime.MinValue && DateTime.Now > x.Date))
248+
if (expires != null && expires.Any(x => x.Date > DateTime.MinValue && DateTime.UtcNow > x.Date))
249249
{
250250
return ContentStatus.Expired;
251251
}
252252

253253
IEnumerable<ContentSchedule> release = contentSchedule.GetSchedule(culture, ContentScheduleAction.Release);
254-
if (release != null && release.Any(x => x.Date > DateTime.MinValue && x.Date > DateTime.Now))
254+
if (release != null && release.Any(x => x.Date > DateTime.MinValue && x.Date > DateTime.UtcNow))
255255
{
256256
return ContentStatus.AwaitingRelease;
257257
}

tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestWithContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public virtual void CreateTestData()
5757
// Create and Save Content "Text Page 1" based on "umbTextpage" -> 1054
5858
Subpage = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 1", Textpage.Id);
5959
Subpage.Key = new Guid(SubPageKey);
60-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
60+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
6161
ContentService.Save(Subpage, -1, contentSchedule);
6262

6363
// Create and Save Content "Text Page 1" based on "umbTextpage" -> 1055

tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public async Task Perform_Scheduled_Publishing()
214214
ctVariant.Variations = ContentVariation.Culture;
215215
ContentTypeService.Save(ctVariant);
216216

217-
var now = DateTime.Now;
217+
var now = DateTime.UtcNow;
218218

219219
// 10x invariant content, half is scheduled to be published in 5 seconds, the other half is scheduled to be unpublished in 5 seconds
220220
var invariant = new List<IContent>();
@@ -321,7 +321,7 @@ public void Remove_Scheduled_Publishing_Date()
321321
// Act
322322
var content = ContentService.CreateAndSave("Test", Constants.System.Root, "umbTextpage");
323323

324-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(null, DateTime.Now.AddHours(2));
324+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(null, DateTime.UtcNow.AddHours(2));
325325
ContentService.Save(content, Constants.Security.SuperUserId, contentSchedule);
326326
Assert.AreEqual(1, contentSchedule.FullSchedule.Count);
327327

@@ -676,7 +676,7 @@ public void Can_Get_Content_For_Expiration()
676676
var root = ContentService.GetById(Textpage.Id);
677677
ContentService.Publish(root!, root!.AvailableCultures.ToArray());
678678
var content = ContentService.GetById(Subpage.Id);
679-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(null, DateTime.Now.AddSeconds(1));
679+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(null, DateTime.UtcNow.AddSeconds(1));
680680
ContentService.PersistContentSchedule(content!, contentSchedule);
681681
ContentService.Publish(content, content.AvailableCultures.ToArray());
682682

@@ -1386,7 +1386,7 @@ public void Cannot_Publish_Expired_Content()
13861386
{
13871387
// Arrange
13881388
var content = ContentService.GetById(Subpage.Id); // This Content expired 5min ago
1389-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(null, DateTime.Now.AddMinutes(-5));
1389+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(null, DateTime.UtcNow.AddMinutes(-5));
13901390
ContentService.Save(content, contentSchedule: contentSchedule);
13911391

13921392
var parent = ContentService.GetById(Textpage.Id);
@@ -1416,7 +1416,7 @@ public void Cannot_Publish_Expired_Culture()
14161416

14171417
var content = ContentBuilder.CreateBasicContent(contentType);
14181418
content.SetCultureName("Hello", "en-US");
1419-
var contentSchedule = ContentScheduleCollection.CreateWithEntry("en-US", null, DateTime.Now.AddMinutes(-5));
1419+
var contentSchedule = ContentScheduleCollection.CreateWithEntry("en-US", null, DateTime.UtcNow.AddMinutes(-5));
14201420
ContentService.Save(content, contentSchedule: contentSchedule);
14211421

14221422
var published = ContentService.Publish(content, new[] { "en-US" });
@@ -1431,7 +1431,7 @@ public void Cannot_Publish_Content_Awaiting_Release()
14311431
{
14321432
// Arrange
14331433
var content = ContentService.GetById(Subpage.Id);
1434-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddHours(2), null);
1434+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddHours(2), null);
14351435
ContentService.Save(content, Constants.Security.SuperUserId, contentSchedule);
14361436

14371437
var parent = ContentService.GetById(Textpage.Id);
@@ -1488,7 +1488,7 @@ public void Failed_Publish_Should_Not_Update_Edited_State_When_Edited_True()
14881488
content.Properties[0].SetValue("Foo", string.Empty);
14891489
contentService.Save(content);
14901490
contentService.PersistContentSchedule(content,
1491-
ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddHours(2), null));
1491+
ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddHours(2), null));
14921492

14931493
// Act
14941494
var result = contentService.Publish(content, Array.Empty<string>(), userId: Constants.Security.SuperUserId);
@@ -1540,7 +1540,7 @@ public void Failed_Publish_Should_Not_Update_Edited_State_When_Edited_False()
15401540
contentService.Publish(content, Array.Empty<string>());
15411541

15421542
contentService.PersistContentSchedule(content,
1543-
ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddHours(2), null));
1543+
ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddHours(2), null));
15441544
contentService.Save(content);
15451545

15461546
// Act
@@ -1568,7 +1568,7 @@ public void Cannot_Publish_Culture_Awaiting_Release()
15681568

15691569
var content = ContentBuilder.CreateBasicContent(contentType);
15701570
content.SetCultureName("Hello", "en-US");
1571-
var contentSchedule = ContentScheduleCollection.CreateWithEntry("en-US", DateTime.Now.AddHours(2), null);
1571+
var contentSchedule = ContentScheduleCollection.CreateWithEntry("en-US", DateTime.UtcNow.AddHours(2), null);
15721572
ContentService.Save(content, contentSchedule: contentSchedule);
15731573

15741574
var published = ContentService.Publish(content, new[] { "en-US" });

tests/Umbraco.Tests.Integration/Umbraco.Core/Services/DocumentUrlServiceTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public void GetDocumentKeyByRoute_Published_Then_Unpublished_Documents_Have_No_P
230230
// Create a subpage
231231
var subsubpage = ContentBuilder.CreateSimpleContent(ContentType, documentName, Subpage.Id);
232232
subsubpage.Key = Guid.Parse(documentKey);
233-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
233+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
234234
ContentService.Save(subsubpage, -1, contentSchedule);
235235

236236
if (loadDraft is false)
@@ -248,7 +248,7 @@ public void GetDocumentKeyByRoute_Published_Then_Unpublished_Documents_Have_No_P
248248
// Create a second root
249249
var secondRoot = ContentBuilder.CreateSimpleContent(ContentType, "Second Root", null);
250250
secondRoot.Key = new Guid("8E21BCD4-02CA-483D-84B0-1FC92702E198");
251-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
251+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
252252
ContentService.Save(secondRoot, -1, contentSchedule);
253253

254254
if (loadDraft is false)
@@ -266,7 +266,7 @@ public void GetDocumentKeyByRoute_Published_Then_Unpublished_Documents_Have_No_P
266266
{
267267
// Create a second root
268268
var secondRoot = ContentBuilder.CreateSimpleContent(ContentType, "Second Root", null);
269-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
269+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
270270
ContentService.Save(secondRoot, -1, contentSchedule);
271271

272272
// Create a child of second root

tests/Umbraco.Tests.Integration/Umbraco.Core/Services/DocumentUrlServiceTests_HideTopLevel_False.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override void Setup()
6262
// Create a subpage
6363
var subsubpage = ContentBuilder.CreateSimpleContent(ContentType, "Sub Page 1", Subpage.Id);
6464
subsubpage.Key = new Guid("DF49F477-12F2-4E33-8563-91A7CC1DCDBB");
65-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
65+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
6666
ContentService.Save(subsubpage, -1, contentSchedule);
6767

6868
if (loadDraft is false)
@@ -81,7 +81,7 @@ public override void Setup()
8181
// Create a second root
8282
var secondRoot = ContentBuilder.CreateSimpleContent(ContentType, "Second Root", null);
8383
secondRoot.Key = new Guid("8E21BCD4-02CA-483D-84B0-1FC92702E198");
84-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
84+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
8585
ContentService.Save(secondRoot, -1, contentSchedule);
8686

8787
if (loadDraft is false)
@@ -100,7 +100,7 @@ public override void Setup()
100100
{
101101
// Create a second root
102102
var secondRoot = ContentBuilder.CreateSimpleContent(ContentType, "Second Root", null);
103-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
103+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
104104
ContentService.Save(secondRoot, -1, contentSchedule);
105105

106106
// Create a child of second root

tests/Umbraco.Tests.Integration/Umbraco.Core/Services/PublishStatusServiceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void Unpublish_leads_to_unpublised_in_this_service()
164164
{
165165
var grandchild = ContentBuilder.CreateSimpleContent(ContentType, "Grandchild", Subpage2.Id);
166166

167-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
167+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
168168
ContentService.Save(grandchild, -1, contentSchedule);
169169

170170
var publishResults = ContentService.PublishBranch(Textpage, PublishBranchFilter.IncludeUnpublished, ["*"]);

tests/Umbraco.Tests.Integration/Umbraco.Core/Services/PublishedUrlInfoProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public async Task Two_items_in_level_1_with_same_name_will_have_conflicting_rout
1212
{
1313
// Create a second root
1414
var secondRoot = ContentBuilder.CreateSimpleContent(ContentType, "Second Root", null);
15-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
15+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
1616
ContentService.Save(secondRoot, -1, contentSchedule);
1717

1818
// Create a child of second root

tests/Umbraco.Tests.Integration/Umbraco.Core/Services/PublishedUrlInfoProvider_hidetoplevel_false.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public async Task Two_items_in_level_1_with_same_name_will_not_have_conflicting_
1919
{
2020
// Create a second root
2121
var secondRoot = ContentBuilder.CreateSimpleContent(ContentType, "Second Root", null);
22-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
22+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
2323
ContentService.Save(secondRoot, -1, contentSchedule);
2424

2525
// Create a child of second root

tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentPublishingServiceTests.Scheduling.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public async Task Can_Publish_Root_In_The_Future()
1414

1515
var result = await ContentPublishingService.PublishAsync(
1616
Textpage.Key,
17-
MakeModel(ContentScheduleCollection.CreateWithEntry("*", DateTime.Now.AddDays(1), null)),
17+
MakeModel(ContentScheduleCollection.CreateWithEntry("*", DateTime.UtcNow.AddDays(1), null)),
1818
Constants.Security.SuperUserKey);
1919

2020
Assert.IsTrue(result.Success);
@@ -25,7 +25,7 @@ public async Task Can_Publish_Root_In_The_Future()
2525
[Test]
2626
public async Task Publish_Single_Item_Does_Not_Publish_Children_In_The_Future()
2727
{
28-
await ContentPublishingService.PublishAsync(Textpage.Key, MakeModel(ContentScheduleCollection.CreateWithEntry("*", DateTime.Now.AddDays(1), null)), Constants.Security.SuperUserKey);
28+
await ContentPublishingService.PublishAsync(Textpage.Key, MakeModel(ContentScheduleCollection.CreateWithEntry("*", DateTime.UtcNow.AddDays(1), null)), Constants.Security.SuperUserKey);
2929

3030
VerifyIsNotPublished(Textpage.Key);
3131
VerifyIsNotPublished(Subpage.Key);
@@ -36,7 +36,7 @@ public async Task Can_Publish_Child_Of_Root_In_The_Future()
3636
{
3737
await ContentPublishingService.PublishAsync(Textpage.Key, MakeModel(_allCultures), Constants.Security.SuperUserKey);
3838

39-
var result = await ContentPublishingService.PublishAsync(Subpage.Key, MakeModel(ContentScheduleCollection.CreateWithEntry("*", DateTime.Now.AddDays(1), null)), Constants.Security.SuperUserKey);
39+
var result = await ContentPublishingService.PublishAsync(Subpage.Key, MakeModel(ContentScheduleCollection.CreateWithEntry("*", DateTime.UtcNow.AddDays(1), null)), Constants.Security.SuperUserKey);
4040

4141
Assert.IsTrue(result.Success);
4242
Assert.AreEqual(ContentPublishingOperationStatus.Success, result.Status);

tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ public async Task CreateTestData()
968968

969969
// Create and Save Content "Text Page 1" based on "umbTextpage" -> 1054
970970
_subpage = ContentBuilder.CreateSimpleContent(_contentType, "Text Page 1", _textpage.Id);
971-
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);
971+
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
972972
ContentService.Save(_subpage, -1, contentSchedule);
973973

974974
// Create and Save Content "Text Page 2" based on "umbTextpage" -> 1055

0 commit comments

Comments
 (0)