API에서 근무 시간을 가져 와서 구문 분석하는 스크립트 작업 중입니다. 다음 7 일 동안 정규 시간 인을 사용하여 개체를 만든 다음 우리의 공휴일 목록과 비교합니다.내 스크립트가 API 데이터를 성공적으로 가져 왔지만 내 스크립트가 처음 몇 인스턴스를 무시합니다.
이 7 일 중 하나에 휴일이 발생하면이 데이터로 영업 시간을 덮어 씁니다. 하지 처음 7 휴가가 날짜 불구하고
// 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 참조), holiday-regular 비교를 통해 실행되지 않거나 날짜가 일치한다는 것을 인식하지 못합니다. 여기
- 내 바이올린입니다 :http://jsfiddle.net/chicgeek/3SKYx/48/
- 그리고 여기에 참조 할 수 있도록 API 소스입니다 : 참고로http://www.mec.ca/api/v1/stores/1
, 첫 휴가 날짜 12 월 3입니다 - 년 12 월 9 그러나 이들은 보인다 내 휴일 시간 비교에 의해 무시됩니다. 모든 것이 12 월 10 일 이후부터 제대로 작동하는 것으로 보입니다.
누구나 볼 수 있습니까? 미리 감사드립니다.
여기까지입니다! 여기 하나! 고마워, 고마워. 다른 사람이 수정 프로그램을보고 싶은 경우를 대비하여 다음과 같은 업데이트 된 바이올린이 있습니다. http://jsfiddle.net/chicgeek/3SKYx/54/ – chicgeek
+1 사용자 이름과 아바타 –