UNPKG

stryker

Version:
56 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Timer = /** @class */ (function () { function Timer(now) { if (now === void 0) { now = function () { return new Date(); }; } this.now = now; this.reset(); } Timer.prototype.reset = function () { this.markers = Object.create(null); this.start = this.now(); }; Timer.prototype.humanReadableElapsed = function () { var elapsedSeconds = this.elapsedSeconds(); return Timer.humanReadableElapsedMinutes(elapsedSeconds) + Timer.humanReadableElapsedSeconds(elapsedSeconds); }; Timer.prototype.elapsedSeconds = function () { var elapsedMs = this.elapsedMs(); return Math.floor(elapsedMs / 1000); }; Timer.prototype.elapsedMs = function (sinceMarker) { if (sinceMarker && this.markers[sinceMarker]) { return this.now().getTime() - this.markers[sinceMarker].getTime(); } else { return this.now().getTime() - this.start.getTime(); } }; Timer.prototype.mark = function (name) { this.markers[name] = this.now(); }; Timer.humanReadableElapsedSeconds = function (elapsedSeconds) { var restSeconds = elapsedSeconds % 60; if (restSeconds === 1) { return restSeconds + " second"; } else { return restSeconds + " seconds"; } }; Timer.humanReadableElapsedMinutes = function (elapsedSeconds) { var elapsedMinutes = Math.floor(elapsedSeconds / 60); if (elapsedMinutes > 1) { return elapsedMinutes + " minutes "; } else if (elapsedMinutes > 0) { return elapsedMinutes + " minute "; } else { return ''; } }; return Timer; }()); exports.default = Timer; //# sourceMappingURL=Timer.js.map