The adjustdate() function that runs inside my collectschedule() function
This function works very simply. It takes in the datetime information collected in my previous function, and simply alters it so that it is easier to use. First it uses the Date() function which changes the datetime information given into something more manageable. Then it separates this new information provided by the Date() function, into date and year variables.
function adjustdate(datetime){
var d = new Date(datetime);
var cdate = new Date();
var cyear = cdate.getFullYear();
d.setYear(cyear);
if (d.toDateString().slice(0,3) != datetime.slice(0,3)){
if (d.getMonth() >= 9){
d.setYear(cyear - 1);
}else {
d.setYear(cyear + 1);
}
};
return d;
};
I start by setting my year (in the date information), to the current year as based on Internet time. That way I have my year, and I can process the following if block. The beginning question in my if block asks whether or not the day of the week provided from the website is the same day of the week of the year recently set. If it is not, then I adjust the current year as appropriate.
My soccer game schedules can sometimes span two years as they are eight weeks in length and can sometimes start in November but continue through till end of January. In order to determine the year variable I start by asking if the current month is the months of October through December, and if it is then I change the year to make it one less than it is now. Otherwise if the month is between January and March I increase the year by one.
Once all of these items are created I finish my variable d (the datetime information) and return it from the function. Woo for a week full of programming blogs! Expect more for next week!