Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
45
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.  
  16.                 if (month === 'Feb' && match[1] > 28) {
  17.                     continue;
  18.                 }
  19.             }
  20.  
  21.             if (month === 'Jan' && match[1] > 31) {
  22.                 continue;
  23.             } else if (month === 'Mar' && match[1] > 31) {
  24.                 continue;
  25.             } else if (month === 'Apr' && match[1] > 30) {
  26.                 continue;
  27.             } else if (month === 'May' && match[1] > 31) {
  28.                 continue;
  29.             } else if (month === 'Jun' && match[1] > 30) {
  30.                 continue;
  31.             } else if (month === 'Jul' && match[1] > 31) {
  32.                 continue;
  33.             } else if (month === 'Aug' && match[1] > 31) {
  34.                 continue;
  35.             } else if (month === 'Sep' && match[1] > 30) {
  36.                 continue;
  37.             } else if (month === 'Oct' && match[1] > 31) {
  38.                 continue;
  39.             } else if (month === 'Nov' && match[1] > 30) {
  40.                 continue;
  41.             } else if (month === 'Dec' && match[1] > 31) {
  42.                 continue;
  43.             }
  44.  
  45.             arrayOfDates.push(match[0].replace(/-/g, ' '));
  46.         }
  47.     }
  48.  
  49.     arrayOfDates.forEach(date => console.log(date));
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement