UNPKG

@stryker-mutator/core

Version:

The extendable JavaScript mutation testing framework

53 lines 1.65 kB
export class Timer { now; start; markers = Object.create(null); constructor(now = () => new Date()) { this.now = now; this.start = this.now(); } humanReadableElapsed(sinceMarker) { const elapsedSeconds = this.elapsedSeconds(sinceMarker); return new Intl.ListFormat('en').format([ Timer.humanReadableElapsedMinutes(elapsedSeconds), Timer.humanReadableElapsedSeconds(elapsedSeconds), ].filter(Boolean)); } 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) { return elapsed.toLocaleString('en', { unit: word, style: 'unit', unitDisplay: 'long', }); } } //# sourceMappingURL=timer.js.map