Template:Countdown/doc

This is the documentation page for Template:Countdown, which features on the main page. It details the syntax and inner-workings of the template, and describes how to adjust it, add more races, or remove old races. NOTE: This is quite a complex template, and adjustments should not be made without prior authorisation from one of this wiki's Administrators or a member of Wikia Staff.

Template Summary
Template:Countdown is a self-updating countdown which shows the days, hours, minutes and seconds until the start of the next Grand Prix. Using Javascript and information about dates and times, it is set to always update to the next race once the previous date and time have passed. If there are no remaining races loaded, it will show "No race data loaded". In order to do this, it utilizes a nested if-statement to work out which race to load.

#ifexpr and nested-ifexpr
An IFEXPR statement takes a piece of information and function, and executed one command if the statement is true, or another if the statement is false, for example:

A nested IFEXPR takes one if statement and nests it within another, so that the inner-if statement will be executed if the outer-if statement is false (or true, depending on which part it is nested into). An example of a nested false-ifexpr statement is:

Here, the first if-statement will be executed and, if it is false, the second if-statement will then be executed. If the first is true, the result will be shown, and the second if-statement will be skipped.

It is possible to nest several if-statements within each other, or to nest both TRUE and FALSE sides if necessary. Please note, however, that each statement must be ended with }}. The following example is a complex version of this, but it follows the same rules. It is followed by a flowchart diagram of the statement to illustrate its output. The nested if-statement is of the same style which will be used in the Countdown template.



Countdown Statements
Each IF statement of Template:Countdown compares the current date and time (given by with a 14 digit stamp representing the start time of a particular event (in yyyymmddhhmmss format) by the GMT timezone.  For example, for the event occurring at 7pm GMT on 23rd November 2012, the stamp would be 20121123190000. The TRUE branch of this statement leads to a countdown to this date (discussed shortly).  The FALSE branch leads to another IF statement for the following event.  NOTE: These events must be entered in order, from earliest to latest.  Placing them into the wrong order may lead to events being skipped.  The syntax of this part is:

The countdown code contains a number of necessary code snippets, which turn the raw date into a countdown. The actual javascript program is installed to MediaWiki:Common.js and should not be altered except by admins. The code is as follows: event date in long format with time zone. until the EVENT NAME

While this may look very complicated, in reality the only changes to make for a new event are to the Event Date and Event Name. For example, for the 2013 Australianb Grand Prix at 6am GMT on the 17th March 2013:

March 17 2013 06:00:00 GMT. until the 2013 Australian Grand Prix

The final part is just an identical IF statement for another event.

After all known races have been entered, the template needs a default output in case it runs out of events. For this, we have:

No race data loaded

This simply places "No race data loaded" in the countdown box if there are no more races to show.

So, for example, if the next two races were:
 * 2012 Brazilian Grand Prix: 25th November 2012 at 4pm GMT
 * 2013 Australian Grand Prix: 17th March 2013 at 6am GMT

then the code would be:

The number of }s at the end is equal to twice the number of events in the list.

A more complicated version (for the entire 2013 season) would be:

NOTE:All dates are currently provisional. Times are currently unavailable, and are estimates based on the 2012 events.

Finally, the box which surrounds the countdown is produced by adding: 

at the top, an  at the end.