简体   繁体   中英

Display all upcoming items and not past items with Javascript and XML

I have an interactive map that displays dates of events in different regions of the United States. The map works great parsing the XML document and getting the data and actually displaying it. However my issue is I cannot get items from 2014 to display. The map pulls data from the XML document and checks it against the current month/day/year. If the data equals today or later it displays it. But it is not showing any data from 2014.

Here is my conditional statement checking the dates against each other -- this is where the problem lies:

if (Number(currentYear) <= findCourseYear || Number(currentYear) <= findCourseYear2){

    if (Number(currentYear) <= findCourseYear && Number(currentMonth) + 1 <= findCourseMonth || Number(currentYear) <= findCourseYear2 && Number(currentMonth) + 1 <= findCourseMonth2){

            if (Number(currentMonth) + 1 == findCourseMonth && Number(currentDay) <= findCourseDay || Number(currentMonth) + 1 < findCourseMonth || Number(currentMonth) + 1 == findCourseMonth2 && Number(currentDay) <= findCourseDay2 || Number(currentMonth) + 1 < findCourseMonth2){

                courseType.push($(this).find('type').text());
                courseName.push($(this).find('name').text());
                courseCity.push($(this).find('city').text());
                courseState.push($(this).find('state').text());
                courseDate.push($(this).find('date').text());
                courseLink.push($(this).find('link').text());
                courseGeo.push($(this).find('geo').text());
             }
     }
} 

What in this conditional is preventing the map from displaying data from next year?

NOTE: The years are entered as 2 digits. EX: 10/22/13 or 5/10/13

Use JavaScript's Date() constructor. Looks like your check could be simplified to:

var now = Date.now();
var courseDate1 = new Date("20" + findCourseYear, +findCourseMonth - 1, findCourseDay);
var courseDate2 = new Date("20" + findCourseYear2, +findCourseMonth2 - 1, findCourseDay2);
if (courseDate1 >= now || courseDate2 >= now) {
    // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM