/** * @requirefiles {controls/Validator/Validator.js} */ /** * The DateValidator class provides for validation of date values. * @class DateValidator * @extends Validator */ function DateValidator() { } /** * Forces validation of value and returns valid value. * @function * @name DateValidator#Force * @param {string} value The value to force validation from. * @return {string} */ function DateValidator_Force(value) { if (value instanceof Date) { let m = value.getMonth() + 1; let d = value.getDate(); return (value.getFullYear() + '-' + (m.toString().length < 2 ? '0' : '') + m + '-' + (d.toString().length < 2 ? '0' : '') + d); } else { if (((typeof value) === 'string') && (value.length > 4)) { let tA = null; if (value.indexOf('/') > 0) { tA = value.split('/'); } else if (value.indexOf('-') > 0) { tA = value.split('-'); } if ((tA !== null) && (tA.length === 3)) { let y, m, d; if (tA[0].length === 4) { y = parseInt(tA[0]); m = parseInt(tA[1]); d = parseInt(tA[2]); } else { y = parseInt(tA[2]); m = parseInt(tA[0]); d = parseInt(tA[1]); } return (y + '-' + (m.toString().length < 2 ? '0' : '') + m + '-' + (d.toString().length < 2 ? '0' : '') + d); } } } return ('0000-00-00'); } /** * Determines whether or not a value is valid. * @function * @name DateValidator#Validate * @param {string} value The value to determine the validation state of. * @return {boolean} */ function DateValidator_Validate(value) { if (value.length > 4) { let tA = null; if (value.indexOf('/') > 0) { tA = value.split('/'); } else if (value.indexOf('-') > 0) { tA = value.split('-'); } return ((tA !== null) && (tA.length === 3) && (tA[0].length > 0) && Validator.UnsignedNumeric.Validate(tA[0]) && (tA[1].length > 0) && Validator.UnsignedNumeric.Validate(tA[1]) && (tA[2].length > 0) && Validator.UnsignedNumeric.Validate(tA[2])); } return (false); } /** * Determines whether or not the formatting of the source should be utilized. * @name DateValidator#AllowFormatting * @type {boolean} * @default {false} */ /** * Determines whether or not the validator works on multiple lines. * @name DateValidator#Multiline * @type {boolean} * @default {false} */ // noinspection JSClosureCompilerSyntax,JSValidateTypes DateValidator.prototype = new Validator(false, false); DateValidator.prototype.constructor = DateValidator; DateValidator.prototype.Force = DateValidator_Force; DateValidator.prototype.Validate = DateValidator_Validate; /** * The global DateValidator instance. * @name Validator.Date * @type {DateValidator} * @static */ Validator.Date = new DateValidator();