我的脚本成功地提取了API数据,但我的脚本忽略了前几​​个实例

问题描述:

我正在处理一个脚本来从API抽取和解析开放时间。我在接下来的七天使用常规时间创建了一个对象,然后与我们的假期小时列表进行比较。我的脚本成功地提取了API数据,但我的脚本忽略了前几​​个实例

如果假期发生在这七天中的某一天,则开放时间将被这些数据覆盖。

// get regular hours 
    var next7days = []; 
    var storeday = new Date(2012, 12-1, 5); 
    for (var i = 0; i < 7; i++) { 
     var dayofweek = (storeday.getDay() + 6) % 7; 
     next7days[i] = data.hours.regular_hours[dayofweek]; 
     next7days[i].date = storeday; 
     storeday = new Date(storeday.getTime() + 86400000); 
    } 

    // get holiday hours 
    for (var i = 0; i < data.hours.holiday_hours.length; i++) { 

     // this spits out all holidays fine 
     console.log('holiday:'); 
     console.log(data.hours.holiday_hours[i]); 

     for (var j = 0; j < 7; j++) { 
      var fixdate = next7days[j].date.getFullYear() + '-' + (next7days[j].date.getMonth() + 1) + '-' + (next7days[j].date.getDate()); 
      if (fixdate == data.hours.holiday_hours[i].date) { 
       next7days[j].open_time = data.hours.holiday_hours[i].open_time; 
       next7days[j].close_time = data.hours.holiday_hours[i].close_time; 
       next7days[j].day_name = data.hours.holiday_hours[i].day_name; 
       next7days[j].type = data.hours.holiday_hours[i].type; 

       // the first seven holidays are NOT successful 
       console.log('successful:'); 
       console.log(next7days[j]); 
      } 
     } 
    } 

这出色的作品,虽然不是针对前七的度假日期。该脚本在信息正常(请参阅console.log)中引用,但它不是通过假日常规比较运行,或者它不能识别日期匹配。

作为参考,第一个节日的日期是12月3日至12月9日,但这些似乎在我的假期小时比较中被忽略。从12月10日起,一切似乎都很顺利。

任何人都可以看到为什么?在此先感谢

前几个日期不起作用,因为他们缺少您的假期日期有前导0。然后以两位数的方式工作,因为日期相等。

+0

这就是它!这个在这里!谢谢你,我很感激。 以下是更新的小提琴,以防其他人想要查看修正:http://jsfiddle.net/chicgeek/3SKYx/54/ – chicgeek

+0

+1为用户名和头像 –