« I "googled" for some news from the CEBIT in Germany ... | Main | RE: "Iteration 1 (late) Review - MapYourBuddies" (Juweria's Blog) »

Formula One Tracks & News - Working on Iteration 3 - Calculate Dates with JavaScript

Yesterday I worked a little bit on my TODO list for iteration 3 of my Formula One Tracks & News Mini-Project.

Actually I worked on the "Highlight and focus the next racetrack + focus GMap InfoWindow" mentioned in my "Formula One Tracks & News - Iteration 3 - Adjusted Scope" blog post.

To highlight the next race, I needed to calculate the smallest difference between today and the upcoming racetracks (+ all the possible exceptions). Actually I used this very useful GERMAN - sorry for that ;) - "JavaScript - Beispiele: Datum und Uhrzeit" tutorial to get started.

And this is my nice JavaScript function, that highlights the next upcoming racetrack:

// global Variables used in checkNextRace funcion var difsmall = -9999999999999999999999999; var t1 = new Date(); var tday = t1.getDate(); var tmonth = t1.getMonth(); var tyear = t1.getUTCFullYear(); var today = new Date(tyear, tmonth, tday);

and

function checkNextRace(racedate,nn_a) { var month = racedate.substring(5,7); var day = racedate.substring(8,10); var year = racedate.substring(0,4); var month = month-1; var rday = new Date(year, month, day); var difcur = today - rday; if(difcur > difsmall && difcur <=0) { nn_a.id = "current"; difsmall = difcur; } }

This tiny JavaScript is the reason, that e.g. today (03/19/07) the "04/08 - Sepang International Circuit" is marked/highlighted (because it's the next race track):

F1TracksNews_I3_JavaScriptTrackHighlight.jpg

Furthermore I decided NOT to "focus the next racetrack + focus GMap InfoWindow" because I like it more to see all racetracks, when loading the page.

So far the status update from my Formula One Tracks & News Mini-Project.

If you have any questions, feel free to trackback or refer to my work in progress version.

-Joern

Comments (1)

Quite impressive. Thanks for the explanation.