Lower Or Equal To 'DateTime.Now' Rule Implementation. #2181
Replies: 1 comment 1 reply
-
We have many places in our business rules where the user is not allowed to enter a future date, or must enter date less than the current date. We've adopted the "good enough" philosophy. If it works for the normal business cases, there isn't a need to over-engineer the solution. The developers have had debates considering theoretical cases such as when the user started the data entry at 11:59 PM but didn't save until after midnight. Over time, we realized that most of these scenarios don't really matter to the end user. You didn't mention when the rule executes. We often restrict this kind of rule to only run when the property is changed. We also have scenarios where the property can be edited after the object is saved, but we don't want to allow the date to be later than the date that the record was created. We handle this by implemented a DateAdded property and including that in the rule, with the consideration that we use DateTime.Today when the DateAdded property is null. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
Problem:
Our current design has a business object called
Part
that contains aManufacturedDateTime
property. Ideally, this property should contain the date time when the part was manufactured. The problem is that every once in a while an operator will incorrectly enter a data time value that falls way into the future and this creates significant problems for us.Our Current Solution To This Problem:
To stop this from happening, we created a rule that stops a future date time from being entered. Essentially something kind of like this (note that the code below is just exemplary, it is not an actual implementation):
Concerns:
Although the rule works, something just does not feel right about it. For example, its weird that given the same property input, the rule may pass or fail depending on the current value of
DateTime.Now
. There is also another weirdness, the rule really needs to be checked right before the userSaves
the object (not when the property value is set). This is because the act of saving needs to define theDateTime.Now
value when the rule is checked (at least that is how we feel about it). There are other weirdnesses happening but lets not get to hung up in the details.Suggestions Needed:
Could someone suggest how to properly solve the problem that we are having?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions