I would like to change only the date and/or time parts of a System.DateTime object in F#, while maintaining the existing fields. When I say "change", I mean to maintain immutability, so I want to receive a new DateTime object after the operation.
I have illustrated how I would think I would change the time, but this appears to be incorrect.
open System
type State = {
When: DateTime
}
// How would I actually do the following?
// let setTime h m state = { state with When = { state.When with Hour = h; Minute = m } }
Ideally the solution will work on both .NET Core and Framework.
Edit
As mentioned in a comment, there is a separate question on how to change a DateTime, but this question appears to be focused on C# (rather than F#) and also on adding a TimeSpan. I want to set the field values (rather than add to them). There are answers that give copying the fields and calling the constructor, but I was hoping for a more elegant solution.