Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a time counting object, that is able to determine temporal differences between start and end, inclusing pauses.

example

Timing and pausing

import {Timer} from "timecount";

const timer = new Timer({ autoStart: true });

// Operation code...

timer.pause();

// Do something while timer is paused (like reading CLI input)

cli.read(response => {
    // The time it takes for the user to enter is not logged
    timer.resume();

    // And later, pause to ask another input...
    timer.pause();

    cli.read(response2 => {
        timer.end();

        const result = timer.result;
        const resultIncludingPaused = timer.getTimeIncludingPaused();

        console.log(`Processing: ${result.toString()}`);
        console.log(`Total: ${resultIncludingPaused.toString()}`);
    });
});

Hierarchy

Index

Constructors

constructor

  • Initializes a new instance of the Timer class, optionally passing a configuration object as parameter.

    Parameters

    • Optional options: TimerOptions

      An object with the options to configure the timer execution and output.

    Returns Timer

Accessors

elapsedTime

elapsedTime:

Gets the time span with the elapsed time so far, minus the paused time.

endTime

endTime:

Gets a value representing the end time, in nanoseconds.

ended

ended:

Gets whether or not the time counting has ended.

lastResumeTime

lastResumeTime:

Gets a value representing the last time the object resumed from a pause, in nanoseconds.

options

options:

Gets the output options object used by this timer.

paused

paused:

Gets whether or not the time counting is paused.

result

result:

Gets the result time span object from the time counting.

startTime

startTime:

Gets a value representing the start time, in nanoseconds.

started

started:

Gets whether or not the time counting has started.

totalPauseTime

totalPauseTime:

Gets a value representing the total paused time, in nanoseconds.

Methods

end

  • Finishes the time counting, adjusting the time values and properties accordingly.

    Returns TimeSpan

    An object with the time span between start and end, minus the paused time.

getTimeIncludingPaused

  • Gets the timer total timespan, including the time it was paused.

    Returns TimeSpan

    A timespan object with the total time of the object.

pause

  • pause(): void
  • Pauses the time counting.

    Returns void

resume

  • resume(): number
  • Resumes the time counting from a paused state.

    Returns number

    A number with the paused time, in nanoseconds.

Protected setEndTime

  • setEndTime(value: number): void

Protected setResult

Protected setStartTime

  • setStartTime(value: number): void

start

  • start(): void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc