From 27c21ec32e33d8bc89656c9dcf96ede7c9fc41b8 Mon Sep 17 00:00:00 2001 From: Alexandre Brandizzi Date: Fri, 25 Sep 2026 12:06:36 -0300 Subject: [PATCH] fix(services): stamp user, contact, calendar and location audit times in UTC User creation, contact, calendar event and site-contact create/modify/delete stamps used local server time. Validation rules comparing user-entered dates and the JWT expiry are unchanged. --- Api.SeaHavenIndustries.Tests/CalendarServiceTests.cs | 5 ++++- SeaHaven.Services/Implementation/CalendarService.cs | 6 +++--- SeaHaven.Services/Implementation/ContactService.cs | 4 ++-- SeaHaven.Services/Implementation/LocationService.cs | 8 ++++---- SeaHaven.Services/Implementation/UserService.cs | 4 ++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Api.SeaHavenIndustries.Tests/CalendarServiceTests.cs b/Api.SeaHavenIndustries.Tests/CalendarServiceTests.cs index bceb520..fbab136 100644 --- a/Api.SeaHavenIndustries.Tests/CalendarServiceTests.cs +++ b/Api.SeaHavenIndustries.Tests/CalendarServiceTests.cs @@ -44,7 +44,7 @@ public class CalendarServiceTests StartDate = startDate, EndDate = startDate, IsDeleted = isDeleted, - CreatedDate = DateTime.Now + CreatedDate = DateTime.UtcNow }; ctx.Events.Add(ev); ctx.SaveChanges(); @@ -64,6 +64,7 @@ public class CalendarServiceTests saved.Title.Should().Be("Standup"); saved.IsDeleted.Should().Be(false); saved.CreatedDate.Should().NotBeNull(); + saved.CreatedDate!.Value.Kind.Should().Be(DateTimeKind.Utc); } [Fact] @@ -97,6 +98,7 @@ public class CalendarServiceTests var updated = ctx.Events.Single(); updated.Title.Should().Be("New"); updated.LastModificationTime.Should().NotBeNull(); + updated.LastModificationTime!.Value.Kind.Should().Be(DateTimeKind.Utc); } [Fact] @@ -134,6 +136,7 @@ public class CalendarServiceTests var row = ctx.Events.Single(); row.IsDeleted.Should().Be(true); row.DeletionTime.Should().NotBeNull(); + row.DeletionTime!.Value.Kind.Should().Be(DateTimeKind.Utc); } [Fact] diff --git a/SeaHaven.Services/Implementation/CalendarService.cs b/SeaHaven.Services/Implementation/CalendarService.cs index cece13d..596c083 100644 --- a/SeaHaven.Services/Implementation/CalendarService.cs +++ b/SeaHaven.Services/Implementation/CalendarService.cs @@ -31,7 +31,7 @@ namespace SeaHaven.Services.Implementation EndDate = input.EndDate, EndTime = input.EndTime, AllDay = input.AllDay, - CreatedDate = DateTime.Now, + CreatedDate = DateTime.UtcNow, IsDeleted = false }; @@ -57,7 +57,7 @@ namespace SeaHaven.Services.Implementation model.EndDate = input.EndDate; model.EndTime = input.EndTime; model.AllDay = input.AllDay; - model.LastModificationTime = DateTime.Now; + model.LastModificationTime = DateTime.UtcNow; await _dataService.UpdateEventAsync(model, cancellationToken); return true; @@ -76,7 +76,7 @@ namespace SeaHaven.Services.Implementation return false; model.IsDeleted = true; - model.DeletionTime = DateTime.Now; + model.DeletionTime = DateTime.UtcNow; await _dataService.UpdateEventAsync(model, cancellationToken); return true; diff --git a/SeaHaven.Services/Implementation/ContactService.cs b/SeaHaven.Services/Implementation/ContactService.cs index cfeab5b..bf359d2 100644 --- a/SeaHaven.Services/Implementation/ContactService.cs +++ b/SeaHaven.Services/Implementation/ContactService.cs @@ -104,7 +104,7 @@ namespace SeaHaven.Services.Implementation ContactType = dto.Type, AccountId = dto.AccountId, createdby = userId, - CreatedDate = DateTime.Now + CreatedDate = DateTime.UtcNow }; var savedContact = await _contactDataService.AddAsync(contact); @@ -151,7 +151,7 @@ namespace SeaHaven.Services.Implementation if (dto.AccountId.HasValue) existingContact.AccountId = dto.AccountId; - existingContact.LastModificationTime = DateTime.Now; + existingContact.LastModificationTime = DateTime.UtcNow; await _contactDataService.UpdateAsync(existingContact); diff --git a/SeaHaven.Services/Implementation/LocationService.cs b/SeaHaven.Services/Implementation/LocationService.cs index 64b275a..3e89cea 100644 --- a/SeaHaven.Services/Implementation/LocationService.cs +++ b/SeaHaven.Services/Implementation/LocationService.cs @@ -399,7 +399,7 @@ namespace SeaHaven.Services.Implementation { ThrowOnInvalidContacts(contacts); - var now = DateTime.Now; + var now = DateTime.UtcNow; var siteContacts = contacts .Select((row, index) => new Contacts { @@ -457,7 +457,7 @@ namespace SeaHaven.Services.Implementation existing.PhoneNumber = phone; existing.SiteContactOrder = i; existing.AccountId = location.AccountId; - existing.LastModificationTime = DateTime.Now; + existing.LastModificationTime = DateTime.UtcNow; } else { @@ -470,7 +470,7 @@ namespace SeaHaven.Services.Implementation PhoneNumber = phone, SiteContactOrder = i, AccountId = location.AccountId, - CreatedDate = DateTime.Now, + CreatedDate = DateTime.UtcNow, createdby = actorId }); } @@ -478,7 +478,7 @@ namespace SeaHaven.Services.Implementation // Rows omitted from the request are soft deleted so historical // WorkOrderContacts keep rendering. - var now = DateTime.Now; + var now = DateTime.UtcNow; foreach (var existing in existingById.Values) { if (keptIds.Contains(existing.Id) || existing.IsDeleted == true) diff --git a/SeaHaven.Services/Implementation/UserService.cs b/SeaHaven.Services/Implementation/UserService.cs index 99105a3..f448a1f 100644 --- a/SeaHaven.Services/Implementation/UserService.cs +++ b/SeaHaven.Services/Implementation/UserService.cs @@ -72,7 +72,7 @@ namespace SeaHaven.Services.Implementation { model.EmailConfirmed = true; model.UserName = model.Email; - model.CreatedDate = DateTime.Now; + model.CreatedDate = DateTime.UtcNow; model.UniqueName = "Active"; model.PhoneNumber = dto.Role; @@ -152,7 +152,7 @@ namespace SeaHaven.Services.Implementation exist.Email = dto.Email; exist.NormalizedEmail = dto.Email.ToUpperInvariant(); exist.NormalizedUserName = dto.Email.ToUpperInvariant(); - exist.CreatedDate = DateTime.Now; + exist.CreatedDate = DateTime.UtcNow; exist.UniqueName = "Active"; exist.PhoneNumber = dto.Role; exist.AccountId = dto.AccountId;