FANDOM


TZclock is a JavaScript application that displays timezone-adjusted clocks.

  • Supports any timezone, not just the user's or UTC
  • Supports multiple clocks per page
  • Supports optional daylight saving time

It produces, with the basic styling provided, a clock that looks (without the border) like:

New York
1 Sep 2016, 8:21:36 (EDT)

Installation

Add the snippet below to the site's MediaWiki:Common.js.

importArticles({
	type: 'style',
	articles: [
		'u:dev:MediaWiki:TZclock.css'
	]
}, {
	type: 'script',
	articles: [
		'u:dev:TZclock.js'
	]
});

MediaWiki: is required in the CSS article name for the CSS to load.

importArticles — Best Practices for installing JavaScript on FANDOM
The importArticles statement is designed to combine multiple HTTP requests into a single data transfer, allowing multiple scripts to load and execute faster. If you've been installing several different scripts, your JavaScript file has probably accumulated unnecessary import statements. Click "Expand" to learn how to efficiently batch import scripts to speed up performance and make your code look cleaner. One other approach is by using the MediaWiki:ImportJS.
If your JavaScript file has several lines of code that say importScript, importScriptPage, or importArticles, you may be able to combine them! By batch importing a collection of scripts with a single import, your JavaScript code will load faster and look cleaner. Consider the example below. On the left is an example of what your JavaScript file might currently look like. On the right is how you could improve that code.
Multiple imports — messy and slow One import — clean and efficient
importScriptPage('AjaxRC/code.js','dev');
 
importScript('MediaWiki:localScript.js');
 
importArticle({
  type: 'script',
  article: 'u:dev:FloatingToc/code.js'
});
 
importScriptPage('page1.js', 'wikiname');
 
importScriptPage('page2.js', 'wikiname');
importArticles({
    type: 'script',
    articles: [
        'u:dev:AjaxRC/code.js',
        'MediaWiki:localScript.js',
        'u:dev:FloatingToc/code.js',
        'u:wikiname:page1.js',
        'u:wikiname:page2.js'
    ]
});
Note: In this example, pay close attention to the placement of commas and other punctuation. For people who aren't familiar with programming (and even those who are!), a common mistake when writing code is to accidentally delete, forget, or misplace critical symbols like commas or quotation marks. This can cause a syntax error that breaks the code. Carefully follow the convention shown here when using importArticles.
But there's much more to importArticles than just this! For more examples and advanced usage, see the help page at Help:Including additional JavaScript and CSS.


Use

This application looks for HTML elements [usually <div>, but they could be <span> or (rendered) <td>] with the class js-tzclock on the page. If it doesn't find any, it exits. If it finds any, it runs.

Configuration

Configuration of each clock is included on the wiki page inside each element with class js-tzclock. The syntax of the configuration is adapted from tzdata.

  • Optional comments begin with # (pound/octothorpe)
  • Spaces in strings must use _ (underscore)
    Underscore is replaced with a space when running
  • + (plus) is optional for positive time offsets
  • Basic zone definition must come before any rules
    • NAME is location name displayed in clock (any string)
    • UTCOFF is offset from UTC ([+|-]hh[:mm])
    • ZONE is the timezone name (any string)
  • Rules for daylight saving, if there are any, must be in chronological order
    • IN is the month name for a rule (3-letter English abbreviation)
    • ON is the date (numerical date, lastDay, or Day>=date)
      If used, Day is the 3-letter English abbreviation
    • AT is the standard time at which the rule takes effect (24-hour)
    • SAVE is the amount of time added to standard time (hh[:mm])
    • LETTERS is the zone name when the rule is in effect (any string)

Styling

The stylesheet TZclock.css provides basic styling, facilitating centering the clock text inside the js-tzclock element and underlining the location name. There are three additional classes available for further styling the clocks. Additional styling, if any, should be done in your site's MediaWiki:Common.css.

  1. js-tzclock-wrap - child of js-tzclock, wraps both the location name and the time
  2. js-tzclock-lctn - child of js-tzclock-wrap, applies to the location name only
  3. js-tzclock-time - child of js-tzclock-wrap, applies to the time only

Example clock configurations

New York

<div class="js-tzclock"><nowiki>
# NAME          UTCOFF  ZONE
New_York        -5:00   EST
# IN    ON      AT      SAVE    LETTERS
Mar     Sun>=8  2:00    1       EDT # 2nd Sunday in March
Nov     Sun>=1  2:00    0       EST # 1st Sunday in November
</nowiki></div>


London

<div class="js-tzclock"><nowiki>
# NAME          UTCOFF  ZONE
London          0:00    GMT
# IN    ON      AT      SAVE    LETTERS
Mar     lastSun 1:00    1       BST # last Sunday in March
Oct     lastSun 1:00    0       GMT # last Sunday in October
</nowiki></div>


Tokyo

<div class="js-tzclock"><nowiki>
# NAME          UTCOFF  ZONE
Tokyo           9:00    JST # no daylight time in Japan
</nowiki></div>


Adelaide

<div class="js-tzclock"><nowiki>
# NAME          UTCOFF  ZONE
Adelaide        +9:30   CST
# IN    ON      AT      SAVE    LETTERS
Apr     Sun>=1  2:00    0       CST # 1st Sunday in April
Oct     Sun>=1  2:00    1       CDT # 1st Sunday in October
</nowiki></div>


<nowiki> may not be essential for all clock configurations, but it is recommended to stop MediaWiki from interfering with them.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.