Currently date based constraint validators for @Past and @Future use the default system time to create the instant to compare with. This causes problems during testing, where there always will be border cases based on when the test is run. For testing purposes we want to be able to provide for example a constant instant via the TimeProvider contract. This way the test harness could be easily setup. Per default the TimeProvider would of course use the system time.
We can also consider to make the contract available for users, so that they can plug in their custom implementation. To a certain degree this is what for example java.lang.Clock tries to solve as well.
I thought a bit about this one before and adding the contract and making in pluggable via a HV specific feature is easy. The interesting thing was, how to get hold of the time provider in a constraint validator (eg Past). I see basically two options:
Have some homegrown injection solution for this (nasty and might be a bit work)
Provide access via HibernateConstraintValidatorContext. Quite simple, the drawback being that the provider would only be accessible during the isValid call
> Provide access via HibernateConstraintValidatorContext
Yes, I think that's the better approach. Also what I had in mind. If people want to inject stuff, they always can plug in the custom injection-enabled constraint validator factory and validators.
Yes, I think that's the better approach. Also what I had in mind.