Skip to main content

Class: LegacyTimer

A class to create, start, and stop named timers that measure elapsed time in milliseconds.

Deprecated

Use Timer class instead. To migrate to the Timer class, use Timer.startNew() to create and start a new timer instead of LegacyTimer.start().

Constructors

new LegacyTimer()

new LegacyTimer(name): LegacyTimer

Parameters

name: string

Returns

LegacyTimer

Source

LegacyTimer.ts:22

Properties

cumulativeElapsed

private cumulativeElapsed: number = NaN

cumulativeElapsed is a cumulative total of elapsed time while the timer was in previous started (running) states, NOT INCLUDING the possibly active run's duration

Source

LegacyTimer.ts:17


name

private name: string

Source

LegacyTimer.ts:18


startTime

private startTime: number = NaN

Source

LegacyTimer.ts:9


stopTime

private stopTime: number = NaN

Source

LegacyTimer.ts:10


stopped

private stopped: boolean = true

Source

LegacyTimer.ts:11


_timers

static private _timers: LegacyTimer[]

Source

LegacyTimer.ts:20

Methods

elapsed()

static elapsed(name): number

Returns the total time elapsed, in milliseconds, of the timer.

Parameters

name: string

The name of the timer whose elapsed duration is requested

Returns

number

Remarks

The total time elapsed will include all durations from multiple starts and stops of the timer, if applicable. A timer's elapsed duration can be read while it is in started or stopped state. The method throws an error if a timer with the given name does not exist.

Deprecated

Use Timer class.

Source

LegacyTimer.ts:140


exists()

static exists(name): boolean

Checks if a timer of the given name exists.

Parameters

name: string

The name of the timer to check for existence

Returns

boolean

boolean

Remarks

The method checks if there is a timer with the given name.

Deprecated

Use Timer class.

Source

LegacyTimer.ts:203


now()

static now(): number

Aliases performance.now()

Returns

number

a DOMHighResTimeStamp

Remarks

The m2c2kit Timer class is designed to measure elapsed durations after a designated start point for a uniquely named timer. However, if a timestamp based on the time origin is needed, this method can be used.

Deprecated

Use Timer class.

Source

LegacyTimer.ts:39


remove()

static remove(name): void

Removes a timer.

Parameters

name: string

The name of the timer to be removed

Returns

void

Remarks

After removal, no additional methods can be used with a timer of the given name, other than to start a new timer with the given name, whose duration will begin at 0 again. The method throws an error if a timer with the given name does not exist.

Deprecated

Use Timer class.

Source

LegacyTimer.ts:168


removeAll()

static removeAll(): void

Remove all timers.

Returns

void

Remarks

This method will remove any timers in a started or stopped state. This method is idempotent; method is safe to call even if there are no timers to remove; no errors are thrown if there are not any timers that can be removed.

Deprecated

Use Timer class.

Source

LegacyTimer.ts:189


restart()

static restart(name): void

Restarts a timer.

Parameters

name: string

The name of the timer to be restarted

Returns

void

Remarks

The timer elapsed duration is set to 0 and it starts anew. The method throws an error if a timer with the given name does not exist (if there is not a started or stopped timer with the given name).

Deprecated

Use Timer class. Use Timer.startNew() to create and start a new timer with the same name.

Source

LegacyTimer.ts:115


start()

static start(name): void

Starts a millisecond-resolution timer based on performance.now().

Parameters

name: string

The name of the timer to be started

Returns

void

Remarks

The method throws an error if a timer with the given name is already in a started state.

Deprecated

Use Timer class. Use Timer.startNew() to create and start a new timer or Timer.new() to create a new timer without starting it.

Source

LegacyTimer.ts:54


stop()

static stop(name): void

Stops a timer.

Parameters

name: string

The name of the timer to be stopped

Returns

void

Remarks

The method throws an error if a timer with the given name is already in a stopped state, or if a timer with the given name has not been started.

Deprecated

Use Timer class.

Source

LegacyTimer.ts:83