Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MmmarinaMarinova/469d0e2e21d9dee7dd677c44fa27077a to your computer and use it in GitHub Desktop.
Save MmmarinaMarinova/469d0e2e21d9dee7dd677c44fa27077a to your computer and use it in GitHub Desktop.
private _validateDate(value: any) {
if (this.hasFlag('notDate')) {
return this;
}
if (!(UtilsCollections.isString(value) || UtilsCollections.isValidNumber(value))) {
if (UtilsCollections.isString(this.propertyKey)) {
this.recordFlag('propertyNotDate', [this.value, this.propertyKey]);
} else {
this.recordFlag('notDate', [this.value]);
}
this.writeDebugLog(`${TypeValidator.name}: Date should contain some value.`);
return this;
}
// const dateTime = moment(value, Utils.getDateFormat(), true);
const dateTime: string = Utils.formatDate(value, 'en-GB');
// try {
// dateTime = Utils.formatDate(value, 'en-GB');
// } catch (e) {
// return undefined;
// }
if (!isDate(dateTime)) {
// if (dateTime.match(getLocaleDateFormat('en-GB', FormatWidth.Short))) {
if (UtilsCollections.isString(this.propertyKey)) {
this.recordFlag('propertyNotDate', [this.value, this.propertyKey]);
} else {
this.recordFlag('notDate', [this.value]);
}
}
this.writeDebugLog(`${TypeValidator.name}: Date cannot be parsed`);
// }
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment