Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- parse(value: any): Date | null {
- const parsedDate = super.parse(value);
- if (parsedDate instanceof Date && !isNaN(parsedDate.getTime())) {
- return parsedDate;
- } else {
- let otherDate: Date = null;
- const yearResults = value.match(/[1-9]{1}[0-9]{3}/g);
- if (yearResults && yearResults.length > 0) {
- const year = yearResults[0];
- otherDate = new Date(year);
- const monthResults = (value.replace(year, '')).match(/[0-9]{1}[1-9]{1}/g);
- if (monthResults && monthResults.length > 0) {
- const month = monthResults[0];
- otherDate = new Date(year, month - 1);
- const dayResults = (value.replace(year, '').replace(month, '')).match(/[0-9]{1}[1-9]{1}/g);
- if (dayResults && dayResults.length > 0) {
- const day = dayResults[0];
- otherDate = new Date(year, month - 1, day);
- }
- }
- }
- if (otherDate != null && !isNaN(otherDate.getTime())) {
- return otherDate;
- } else {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement