Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dateFinder(params) {
  2.     let regex = /\b([1-9][0-9]?)(-)(?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\2(?<year>[1-9]\d{3})\b/g;
  3.    
  4.     let arrayOfDates = [];
  5.     for (const line of params) {
  6.         let match;
  7.         while ((match = regex.exec(line)) !== null) {
  8.             let year = +match.groups.year;
  9.             let month = match.groups.month;
  10.             if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
  11.                 if (month === 'Feb' && match[1] > 29) {
  12.                     continue;
  13.                 }
  14.             } else {
  15.                 if (month === 'Feb' && match[1] > 28) {
  16.                     continue;
  17.                 }
  18.             }
  19.  
  20.             if (month === 'Jan' && match[1] > 31) {
  21.                 continue;
  22.             } else if (month === 'Mar' && match[1] > 31) {
  23.                 continue;
  24.             } else if (month === 'Apr' && match[1] > 30) {
  25.                 continue;
  26.             } else if (month === 'May' && match[1] > 31) {
  27.                 continue;
  28.             } else if (month === 'Jun' && match[1] > 30) {
  29.                 continue;
  30.             } else if (month === 'Jul' && match[1] > 31) {
  31.                 continue;
  32.             } else if (month === 'Aug' && match[1] > 31) {
  33.                 continue;
  34.             } else if (month === 'Sep' && match[1] > 30) {
  35.                 continue;
  36.             } else if (month === 'Oct' && match[1] > 31) {
  37.                 continue;
  38.             } else if (month === 'Nov' && match[1] > 30) {
  39.                 continue;
  40.             } else if (month === 'Dec' && match[1] > 31) {
  41.                 continue;
  42.             }
  43.  
  44.             arrayOfDates.push(match[0].replace(/-/g, ' '));
  45.         }
  46.     }
  47.  
  48.     arrayOfDates.forEach(date => console.log(date));
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement