UNPKG

@stryker-mutator/core

Version:

The extendable JavaScript mutation testing framework

46 lines 1.56 kB
export class Timer { constructor(now = () => new Date()) { this.now = now; this.markers = Object.create(null); this.start = this.now(); } humanReadableElapsed(sinceMarker) { const elapsedSeconds = this.elapsedSeconds(sinceMarker); return Timer.humanReadableElapsedMinutes(elapsedSeconds) + Timer.humanReadableElapsedSeconds(elapsedSeconds); } elapsedSeconds(sinceMarker) { const elapsedMs = this.elapsedMs(sinceMarker); return Math.floor(elapsedMs / 1000); } elapsedMs(sinceMarker) { const marker = sinceMarker && this.markers[sinceMarker]; if (marker) { return this.now().getTime() - marker.getTime(); } else { return this.now().getTime() - this.start.getTime(); } } mark(name) { this.markers[name] = this.now(); } static humanReadableElapsedSeconds(elapsedSeconds) { const restSeconds = elapsedSeconds % 60; return this.formatTime('second', restSeconds); } static humanReadableElapsedMinutes(elapsedSeconds) { const elapsedMinutes = Math.floor(elapsedSeconds / 60); if (elapsedMinutes === 0) { return ''; } else { return this.formatTime('minute', elapsedMinutes); } } static formatTime(word, elapsed) { const s = elapsed === 1 ? '' : 's'; const blank = word === 'minute' ? ' ' : ''; return `${elapsed} ${word}${s}${blank}`; } } //# sourceMappingURL=timer.js.map