Constructor
new Clock(params)
Parameters:
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object | Object containing all configurable parameters.
Properties
|
Members
Theme
User Convenience theme selection property.
(readonly) timezoneGroups
Get all currently available timezone parts.
Returns a product of *this.getAllAvailableTimezones()*,
because that is saved to the Clock at the initialization time.
Methods
(private) _checkMomentDependancies() → {Boolean}
Widget checks if website already has necessary dependancies - **moment.js**, **moment-timezone.js**.
Returns:
are dependancies fulfilled.
- Type
- Boolean
(private) _createWidget()
Method generates HTML for the widget and then calls *this._showWidget*,
which updates time and date text.
(private) _findReconstructedTimezoneObject(reconstructedTimezoneObject) → {null|TimezoneObject}
Allows to verify if reconstructed TimezoneObject from LocalStorage (or user input) is valid or not.
Parameters:
Name | Type | Description |
---|---|---|
reconstructedTimezoneObject |
TimezoneObject | TimezoneObject which is constructed from storage or user input. |
Returns:
null - if TimezoneObject was not recognized. TimezoneObject - otherwise.
- Type
- null | TimezoneObject
(private) _importMomentDependancies() → {Promise}
Dinamically import dependancies - **moment.js**, **moment-timezone.js**, if they were not found in the website.
This method is called after *this._checkMomentDependancies()*.
Returns:
fulfilled or rejected Promise, which is being waited in the initialization of the widget.
- Type
- Promise
(private) _importOtherDependancies()
Dinamically import CSS of the widget.
(async, private) _init()
Initialize widget.
Throws:
-
if initialization has failed.
- Type
- WorldClockError
(private) _parseParams(params)
Method to parse all given by user parameters.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object | Object containing all configurable parameters.
Properties
|
Throws:
-
if required parameter was wrong (not defined, not a String).
- Type
- WorldClockError
(private) _render(timestamp)
Every second updates widget text (time, date, timezone).
Parameters:
Name | Type | Description |
---|---|---|
timestamp |
DOMHighResTimeStamp | used to track render time from requestAnimationFrame. |
(private) _setContainer(params)
Method to parse all given by user parameters.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object | Object containing all configurable parameters.
Properties
|
Throws:
-
if required parameter - 'container' was wrong (not defined, not a String or no element exist in DOM).
- Type
- WorldClockError
(private) _showWidget()
Display current time and date in the widget.
(private) _updateClock()
Updates widget text (time, date, timezone) with the current widget configuration.
(private) _updateWidgetDateTime(timeFrame)
Invokes widget to update text (time, date) from a specified moment timeframe.
Parameters:
Name | Type | Description |
---|---|---|
timeFrame |
moment | equivalent to *moment()* timeframe. |
findCity(name) → {null|TimezoneCity}
Search for a TimezoneCity in all available timezones.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | TimezoneCity name, which is being searched. |
Returns:
null - if city was not found, TimezoneCity - otherwise.
- Type
- null | TimezoneCity
findGroup(name) → {null|TimezoneGroup}
Search for a TimezoneGroup in all available timezones.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | TimezoneGroup name, which is being searched. |
Returns:
null - if group was not found, TimezoneGroup - otherwise.
- Type
- null | TimezoneGroup
findRegion(name) → {null|TimezoneRegion}
Search for a TimezoneRegion in all available timezones.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | TimezoneRegion name, which is being searched. |
Returns:
null - if region was not found, TimezoneRegion - otherwise.
- Type
- null | TimezoneRegion
findTimezonePart(type, name) → {null|TimezoneObject}
Find TimezoneObject within the available timezones given by *type* and *name*.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | one of the types from ["group", "region", "city"]. |
name |
String | name of the part that is being searched. For example - "Vilnius". |
Returns:
null - if part was not found. TimezoneObject - otherwise.
- Type
- null | TimezoneObject
getAllAvailableTimezones() → {Object}
Show all available timezones, which are hierarchically related.
At the top of hierarchy lies TimezoneGroup Objects.
Returns this data structure:
{
'timezone_group_name': TimezoneGroup()
...
}
TimezoneRegion Objects are included into TimezoneGroup.
TimezoneCity Objects are included into TimezoneRegion.
Returns:
hierarchical object.
- Type
- Object
getTimezoneGroups() → {Array}
Get all available timezone groups from moment-timezone.
In moment-timezone group, region, city is marked in this format: "Group/Region/City".
Method splits all strings by "/" and then collects all parts at index 0.
So we get a list of timezone group names.
Returns:
array of timezone group names.
- Type
- Array
selectCurrentTimezone(part)
In order to set current timezone one of the timezone parts must be passed.
We automatically detect type of timezone part, then detect if input is recognized.
If input is recognized current selected timezone is updated.
Otherwise we throw WorldClockError.
Parameters:
Name | Type | Description |
---|---|---|
part |
TimezoneObject | TimezoneObject part, which should be selected. |
setDateShow(value)
Validate and set flag, which controls if widget should show date field.
Default value = true.
Parameters:
Name | Type | Description |
---|---|---|
value |
Boolean | controls if widget should show date field. |
setTheme(themeValue)
Validate and set widget theme.
If given value is not valid, light theme will be selected.
Parameters:
Name | Type | Description |
---|---|---|
themeValue |
String | controls which widget theme should be selected. |
setTimeSecondsShow(value)
Validate and set flag, which controls if widget should show seconds.
Default = true.
Parameters:
Name | Type | Description |
---|---|---|
value |
Boolean | controls if widget should show seconds. |