diff --git a/src/Yavsc.Api.Test/RdvQueryApiControllerTests.cs b/src/Yavsc.Api.Test/RdvQueryApiControllerTests.cs index fcd87f9a3..668814239 100644 --- a/src/Yavsc.Api.Test/RdvQueryApiControllerTests.cs +++ b/src/Yavsc.Api.Test/RdvQueryApiControllerTests.cs @@ -112,4 +112,35 @@ public sealed class RdvQueryApiControllerTests : IClassFixture(TestContext.Current.CancellationToken); + Assert.NotNull(created); + Assert.Equal(DateTimeKind.Utc, created!.EventDate.Kind); + } } diff --git a/src/Yavsc.Api/Controllers/Business/RdvQueryApiController.cs b/src/Yavsc.Api/Controllers/Business/RdvQueryApiController.cs index dd2982138..48e3be2e1 100644 --- a/src/Yavsc.Api/Controllers/Business/RdvQueryApiController.cs +++ b/src/Yavsc.Api/Controllers/Business/RdvQueryApiController.cs @@ -67,6 +67,7 @@ public class RdvQueryApiController : Controller var uid = User.GetUserId(); // Security: the caller always posts for themselves. query.ClientId = uid; + query.EventDate = EnsureUtc(query.EventDate); ModelState.Remove("Client"); ModelState.Remove("ClientId"); @@ -140,7 +141,7 @@ public class RdvQueryApiController : Controller existing.ActivityCode = query.ActivityCode; existing.PerformerId = query.PerformerId; existing.Consent = query.Consent; - existing.EventDate = query.EventDate; + existing.EventDate = EnsureUtc(query.EventDate); existing.LocationType = query.LocationType; existing.Reason = query.Reason; existing.Status = query.Status; @@ -206,4 +207,14 @@ public class RdvQueryApiController : Controller { return _context.RdvQueries.Any(e => e.Id == id); } + + private static DateTime EnsureUtc(DateTime value) + { + return value.Kind switch + { + DateTimeKind.Utc => value, + DateTimeKind.Local => value.ToUniversalTime(), + _ => DateTime.SpecifyKind(value, DateTimeKind.Utc) + }; + } }