New Posts New Posts RSS Feed: How to verify that a date is in the future?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How to verify that a date is in the future?

 Post Reply Post Reply
Author
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Topic: How to verify that a date is in the future?
    Posted: 01-Feb-2012 at 2:43pm
Hi ajhops,
 
I'd suggest enabling this validation for property updates only (i.e. disable it during Instance validation).
By default a verifier ExecutionMode is set to VerifierExecutionModes.InstanceAndOnBeforeSetTriggers. i.e. during instance validation and when the property is updated (OnBeforeSetTriggers).
You could disable it by set the ExecutionMode to VerifierExecutionModes.OnBeforeSetTriggers:
 
public static Verifier GetFutureDateVerifier(Type type, string propertyName, bool isRequired) {
  var v = new DateTimeRangeVerifier(type, propertyName, isRequired, DateTime.Today.Date, DateTime.MaxValue);
  v.VerifierArgs.ErrorMessageInfo.ErrorMessage = "Must be on or after today.";
  v.VerifierOptions.ExecutionModes =  VerifierExecutionModes.OnAfterSetTriggers;
  return v;
}
 
Note the if this property is required, you might want a RequiredValueVerifier to execute on instance validation.
 
You can find more information about configuring verifiers in the DevForce Resource Center.
 
Regards,
   Silvio.
Back to Top
ajhops View Drop Down
Newbie
Newbie
Avatar

Joined: 23-Aug-2010
Posts: 11
Post Options Post Options   Quote ajhops Quote  Post ReplyReply Direct Link To This Post Posted: 31-Jan-2012 at 6:55am
What is the proper way to validate that a datetime*when set* is in the future? 

My field is "Publication Date". The business says that Publication Date must be today or after. This part is easy on the first save, but if the date passes and the user edits other fields on a day after publication - I get a server side validation error (but not client side). 

Silverlight if it matters.

Here is my static method to create this verifier:

public static Verifier GetFutureDateVerifier(Type type, string propertyName, bool isRequired)
		{
			var v = new DateTimeRangeVerifier(type, propertyName, isRequired, DateTime.Today.Date, DateTime.MaxValue);
			v.VerifierArgs.ErrorMessageInfo.ErrorMessage = "Must be on or after today.";
			return v;
		}

Thanks!!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down