The starting time to countdown from. Methods like Timer.reset uses this value as the initial time.
function to run when the time reaches 0. this
is the timer instance, allowing the function to call methods on the timer.
function to run on every interval (by default, every 1 second). Useful for updating UI elements.
set various beheivors on the timer. Pass as an object as the 2nd argument.
Starting time of the timer. Other methods, such as Timer.reset uses this as its target to reset to.
the id of the underlying setInterval, which controls the countdown "ticks". It's often unnecessary to use this.
whether or not the timer is paused.
Unpauses the timer. If the timer is already unpaused, this has no effect.
Unpauses the timer. If the timer is already unpaused, this has no effect.
Formats the current time as a string, depending on the value of fmt.
a template string that will be used to populate with time values.
fmtTime looks for special characters in the string that start with %
, depending on the next value, fmtTime will replace it with the following
%Y
- years
%D
- days
%H
- hours
%M
- minutes
%S
- seconds
%m
- milliseconds
%n
where n is a number, format the following token to be padded with n zeros if all places can't be filled. E.g. a timer with 5 seconds left, the string "%2%S"
will render as "05"
Pauses the timer. If the timer is already paused, this has no effect.
Resets the timer back to its initial time. [[Timer.onTimeout]] does not get called.
Does not change whether the timer is paused or not.
Like Timer.reset, but unpauses the timer as well.
an expression of a time.
Manually decrement the timer by its interval (by default 1 second), triggering the [[Timer.onInterval]] if defined, unless paused.
do this even if paused (timer will still remain paused)
Returns time in "YY:DD:hh:ss:mm.mills" format, optionally truncating some units.
Lowest unit of time to show. Units lower than minUnit
will not be shown. 'ms' or '' means
include every unit.
Largest unit of time to show. All units of time larger than this are added to the maxUnit. E.g. '01:01:01.000'.toString('', 'm') returns '61:01.000'
Formatted string representing the time. If maxUnit is greater than minUnit, returns ''
Flips the timer to paused if unpaused, and to unpaused if paused.
Unpauses the timer. If the timer is already unpaused, this has no effect.
Generated using TypeDoc
The main timer class.
Example:
See Timer.constructor for more uses