/**
* NL4B / NL for Business
*
* Copyrights 2008 NL for Business / Theo van der Sluijs
*
* Author : Theo van der Sluijs / theo.van.der.sluijs@nl4b.com
*
* All Rights Reserved.
*
* Creative Commons Attribution-Noncommercial 3.0
*
* You are free:
* to Share — to copy, distribute and transmit the work
* to Remix — to adapt the work
*
* Under the following conditions:
* Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
* Noncommercial — You may not use this work for commercial purposes
*
* With the understanding that:
* Waiver — Any of the above conditions can be waived if you get permission from the copyright holder.
*
* Other Rights — In no way are any of the following rights affected by the license:
* Your fair dealing or fair use rights;
* The author's moral rights;
* Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
*
* Notice — For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.
*
* http://creativecommons.org/licenses/by-nc/3.0/
*
* www.nl4b.com info@nl4b.com
* www.iamboredsoiblog.eu info@iamboredsoiblog.eu
* */
package com.scripts
{
import mx.validators.DateValidator;
import mx.validators.ValidationResult;
public class StartEndDateValidator extends DateValidator
{
private var results:Array;
private var _matches : String = "";
private var _dFormat : String = "DD/MM/YYYY";
private var _mismatchError : String = "End date smaller than start date? Do you own a DeLorean with Flux Capacitor?";
public function StartEndDateValidator()
{
super();
}
public function set matches (s : String ) : void {
_matches = s;
}
public function set dFormat (s : String ) : void {
_dFormat = s;
}
public function set mismatchError (s : String) : void {
_mismatchError = s;
}
override protected function doValidation(value:Object):Array
{
var sDate: String = _matches; var eDate: String = source.text; var dFormat: String= _dFormat;
results = [];
results = super.doValidation(value);
if(sDate == "" || eDate == ""){
return results;
}
var Yindex:Number = dFormat.indexOf("YYYY"); var Dindex:Number = dFormat.indexOf("DD"); var Mindex:Number = dFormat.indexOf("MM");
var StartDate:Date = new Date(sDate.substr(Yindex, 4), sDate.substr(Mindex, 2), sDate.substr(Dindex, 2)); var StartEnd:Date = new Date(eDate.substr(Yindex, 4), eDate.substr(Mindex, 2), eDate.substr(Dindex, 2));
var StartTimestamp : Number = StartDate.getTime (); var EndTimestamp : Number = StartEnd.getTime ();
if (results.length > 0)
{
return results;
}
if (StartTimestamp == EndTimestamp){ return results;
} else if (StartTimestamp < EndTimestamp){ return results;
} else { results.push(new ValidationResult(true, null, "Date Error", _mismatchError));
return results;
}
}
}
}