/**
 * Table of meets in the year page parser
 */
'use strict';
module.exports = (function() {
  var util = require('../swimtrack-util.js');
  let dayRe = /([0-9]+)日\([日月火水木金土・祝]+\)/g; // Allow global match (its lastIndex property is updated by a match)
  const VENUE_PAT = /^(.+)\((25m|50m)\)$/;
  const HTML_PAT = /HTM|HTML$/;
  let parsePage = function(year, $) {
    let ret = {};
    ret.meets = [];
    $('table').each(function(month) { // for table per month
      $(this).find('tr').each(function(trIndex) { // each meet
        if (trIndex === 0) {// haeder row
          return;
        }
        let meet = {};
        meet.venue = {};
        let $cells = $(this).find('td');
        for (let tdIndex = 0; tdIndex < $cells.length; tdIndex++) { // each cell
          let $cell = $cells[tdIndex];
          let fontElm = util.findLastFontElm($($cell));
          let text = util.normalizeText($($cell).text());
          switch (tdIndex) {
            case 0: // day
              meet.days = [];
              let dayMatch;
              while ((dayMatch = dayRe.exec(text)) !== null) {
                let date = new Date(Date.UTC(year, month, dayMatch[1]));
                meet.days.push(util.formatDate(date));
              }
              break;
            case 1: // meet name
              meet.name = text;
              break;
            case 2: // venue city
              meet.venue.city = text;
              break;
            case 3: // venue name and course
              let venueMatch = VENUE_PAT.exec(text);
              if (!venueMatch) {
                meet.venue.name = text;
                break;
              }
              meet.venue.name = venueMatch[1];
              let meetCourse = '';
              if (venueMatch[2] === '25m') {
                meetCourse = '短水路';
              } else if (venueMatch[2] === '50m') {
                meetCourse = '長水路';
              }
              meet.venue.course = meetCourse;
              break;
            case 4: // meet page url
              meet.url = $($cell).find('a').attr('href');
              if (!meet.url) {
                console.warn('Cannot extract meet url', meet);
              } else if (HTML_PAT.exec(meet.url) === null) {// not html
                console.warn('The meet page is not HTML', meet.url);
                meet.url = null;
              }
              break;
          }
        }
        ret.meets.push(meet);
      });
    });
    return ret;
  };
  return {
    parsePage: parsePage
  };
}());

@@ -140,17 +140,22 @@
 ;%0A  
-let dayRe
+const DATE_PAT
  = /
@@ -186,77 +186,8 @@
 )/g;
- // Allow global match (its lastIndex property is updated by a match)
 %0A  c
@@ -260,19 +260,19 @@
 ML$/;%0A  
-let
+var
  parsePa
@@ -1002,13 +1002,16 @@
 h = 
-dayRe
+DATE_PAT
 .exe
@@ -2018,292 +2018,8 @@
 ');%0A
-              if (!meet.url) %7B%0A                console.warn('Cannot extract meet url', meet);%0A              %7D else if (HTML_PAT.exec(meet.url) === null) %7B// not html%0A                console.warn('The meet page is not HTML', meet.url);%0A                meet.url = null;%0A              %7D%0A
     
@@ -2048,32 +2048,61 @@
      %7D%0A        %7D
+%0A%0A        validateMeet(meet);
 %0A        ret.mee
@@ -2150,20 +2150,1313 @@
 rn ret;%0A
-
   %7D;
+%0A%0A  const VALID_DATE_PAT = /%5E%5B0-9%5D%7B4%7D%5C-%5B0-9%5D%7B2%7D%5C-%5B0-9%5D%7B2%7D/;%0A  var validateMeet = function(meet) %7B%0A    //%0A    // Check venue%0A    //%0A    if (!meet.venue) %7B%0A      console.warn('Cannot extract meet venue', meet);%0A    %7D else %7B%0A      if (!meet.venue.city) %7B%0A        console.warn('Cannot extract venue city', meet);%0A      %7D%0A      if (!meet.venue.name) %7B%0A        console.warn('Cannot extract venue name', meet);%0A      %7D%0A      if (!meet.venue.course) %7B%0A        console.warn('Cannot extract venue course', meet)%0A      %7D%0A    %7D%0A%0A    //%0A    // Check days%0A    //%0A    if (!meet.days %7C%7C meet.days.length == 0) %7B%0A      console.warn('Cannot extract meet days', meet);%0A    %7D else %7B%0A      for (let i = 0; i %3C meet.days.length; i++) %7B%0A        if (!VALID_DATE_PAT.exec(meet.days%5Bi%5D)) %7B%0A          console.warn('Invalid date', meet);%0A          meet.days%5Bi%5D = null;  // Remove the invalid date%0A        %7D%0A      %7D%0A    %7D%0A%0A    //%0A    // Check name%0A    //%0A    if (!meet.name) %7B%0A      console.warn('Cannot extract meet name', meet);%0A    %7D%0A%0A    //%0A    // Check url%0A    //%0A    if (!meet.url) %7B%0A      console.warn('Cannot extract meet url', meet);%0A    %7D else if (HTML_PAT.exec(meet.url) === null) %7B// not html%0A      console.warn('The meet page is not HTML', meet.url);%0A      meet.url = null;  //Remove the invalid url%0A    %7D%0A  %7D
 %0A  retur

Add meet value check to year-parser