UNPKG

@egodigital/egoose

Version:

Helper classes and functions for Node.js 10 or later.

66 lines 1.88 kB
"use strict"; /** * This file is part of the @egodigital/egoose distribution. * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/) * * @egodigital/egoose is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, version 3. * * @egodigital/egoose is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ Object.defineProperty(exports, "__esModule", { value: true }); const moment = require("moment"); /** * A stopwatch. */ class StopWatch { constructor() { this._startTime = false; } /** * Gets if the stop watch is running or not. */ get isRunning() { return moment.isMoment(this._startTime); } /** * (Re-)Starts the stop watch. * * @return this */ start() { this._startTime = moment.utc(); return this; } /** * Stops the watch. * * @return {number} The number of milliseconds. */ stop() { const NOW = moment.utc(); const START_TIME = this._startTime; this._startTime = false; if (moment.isMoment(START_TIME)) { return NOW.diff(START_TIME, 'ms', true); } } } exports.StopWatch = StopWatch; /** * Creates and starts a new stop watch. * * @return {StopWatch} The new, started watch. */ function startWatch() { return (new StopWatch()).start(); } exports.startWatch = startWatch; //# sourceMappingURL=stopwatch.js.map