From 62824549fc83f9c7f272b0c4a91544c8ce93713c Mon Sep 17 00:00:00 2001 From: ThompsonNye Date: Thu, 16 Oct 2025 18:21:14 +0200 Subject: [PATCH] Always use current datetime for validation --- src/Vegasco.Server.Api/Consumptions/CreateConsumption.cs | 6 +++--- src/Vegasco.Server.Api/Consumptions/UpdateConsumption.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Vegasco.Server.Api/Consumptions/CreateConsumption.cs b/src/Vegasco.Server.Api/Consumptions/CreateConsumption.cs index 767cdab..87c25b1 100644 --- a/src/Vegasco.Server.Api/Consumptions/CreateConsumption.cs +++ b/src/Vegasco.Server.Api/Consumptions/CreateConsumption.cs @@ -26,13 +26,13 @@ public static class CreateConsumption { public Validator(TimeProvider timeProvider) { - DateTime todayEndOfDay = timeProvider.GetUtcNow() + Func getTodayEndOfDay = () => timeProvider.GetUtcNow() .Date .AddDays(1) .AddTicks(-1); - + RuleFor(x => x.DateTime.ToUniversalTime()) - .LessThanOrEqualTo(todayEndOfDay) + .LessThanOrEqualTo(_ => getTodayEndOfDay()) .WithName(nameof(Request.DateTime)); RuleFor(x => x.Distance) diff --git a/src/Vegasco.Server.Api/Consumptions/UpdateConsumption.cs b/src/Vegasco.Server.Api/Consumptions/UpdateConsumption.cs index 80ce097..119f1fb 100644 --- a/src/Vegasco.Server.Api/Consumptions/UpdateConsumption.cs +++ b/src/Vegasco.Server.Api/Consumptions/UpdateConsumption.cs @@ -26,13 +26,13 @@ public static class UpdateConsumption { public Validator(TimeProvider timeProvider) { - DateTime todayEndOfDay = timeProvider.GetUtcNow() + Func getTodayEndOfDay = () => timeProvider.GetUtcNow() .Date .AddDays(1) .AddTicks(-1); RuleFor(x => x.DateTime.ToUniversalTime()) - .LessThanOrEqualTo(todayEndOfDay) + .LessThanOrEqualTo(_ => getTodayEndOfDay()) .WithName(nameof(Request.DateTime)); RuleFor(x => x.Distance)