Class: WorldClock

pbs.WorldClock

A prototype to represent a single world clock.

The timezone can be specified either as an argument to the constructor, or by specifying it with the data attribute data-timezone on the span to be converted into a clock. An argument to the constructor takes precedence over the data attribute.

The markup produced to represent the clock is very simple:

<span class="pbs-worldclock">
 <span class="pbs-worldclock-hours">HH</span>
 <span class="pbs-worldclock-separator">:</span>
 <span class="pbs-worldclock-minutes">MM</span>
</span>

No CSS attributes are set on any of the elements, so all styling is left to the user. Below is a sample style:

.pbs-worldclock{
   font-weight: bold;
   display: inline-block;
   border: 1px solid green;
   border-radius: 3px;
   padding: 3px;
   background-color: black;
   color: lightgreen;
   font-family: monospace;
}

Constructor

new WorldClock($span, tzopt)

Parameters:
Name Type Attributes Default Description
$span jQuerySingleSpan

a jQuery object representing the HTML span element to be transformed into a clock. Note that all existing content within the span will be will be removed.

tz TimeZoneString <optional>
Europe/London

The timezone for the clock.

Throws:

An error is thrown when an invalid value is passed for any of the arguments.

Type
TypeError

Methods

(static) autoInitialise($containersopt)

Initialise all spans with the class pbs-worldclock-auto within a given set of containers.

Parameters:
Name Type Attributes Default Description
$containers jQueryObject <optional>
$(document)

the container(s) to search for spans to be automatially transformed into clocks. By default the entire document is searched.

Throws:

An error is thrown if the first argument is present, but not a jQuery object.

Type
TypeError

start()

Start the clock.

stop()

Stop the clock.

timezone(tzopt) → {TimeZoneString}

Get and/or set the clock's timezone.

Parameters:
Name Type Attributes Description
tz TimeZoneString <optional>
Throws:

An error is thrown if an argument is passed that is not valid.

Type
TypeError
Returns:
Type
TimeZoneString