Skip to content

Commit 026d34a

Browse files
nanotaboadaCopilot
andcommitted
fix(validation): compare date component to reject same-day birth dates (#344)
- Change DateOfBirth predicate from `date < DateTime.UtcNow` to `date!.Value.Date < DateTime.UtcNow.Date` to reject same-day dates - Access nullable value via `.Value.Date` consistently in both Must lambdas, safe within the When(HasValue) guard Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 2264c0d commit 026d34a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ public PlayerRequestModelValidator(IPlayerRepository playerRepository)
4545
() =>
4646
{
4747
RuleFor(player => player.DateOfBirth)
48-
.Must(date => date < DateTime.UtcNow)
48+
.Must(date => date!.Value.Date < DateTime.UtcNow.Date)
4949
.WithMessage("DateOfBirth must be a date in the past.")
50-
.Must(date => date >= new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc))
50+
.Must(date =>
51+
date!.Value.Date >= new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc)
52+
)
5153
.WithMessage("DateOfBirth must be on or after January 1, 1900.");
5254
}
5355
);

0 commit comments

Comments
 (0)