UNPKG

@koalarx/utils

Version:

Biblioteca com validadores, conversores e abstrações de algumas problemáticas

38 lines (37 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KlCron = void 0; const KlDate_1 = require("./KlDate"); class KlCron { startDate; endDate; /** * Inicia o cronômetro, registrando a data e hora de início. * @returns A instância atual de `KlCron` para permitir encadeamento de chamadas. */ start() { this.startDate = new KlDate_1.KlDate(); return this; } /** * Finaliza o cronômetro, registrando a data e hora de término. * @returns A instância atual de `KlCron` para permitir encadeamento de chamadas. */ end() { this.endDate = new KlDate_1.KlDate(); return this; } /** * Calcula a duração entre o início e o término do cronômetro em segundos. * @returns A duração em segundos. * @throws Erro caso o cronômetro não tenha sido iniciado ou finalizado. */ duration() { if (!this.startDate) throw new Error('The cron is not started.'); if (!this.endDate) throw new Error('The cron is not ended.'); return this.startDate.diff(this.endDate, 'seconds'); } } exports.KlCron = KlCron;