Add output for lunch break duration and rework config lunch option

This commit is contained in:
Marko Korhonen 2023-11-23 19:13:39 +02:00
parent 29ded9426b
commit 71e8352ecf
Signed by: FunctionalHacker
GPG key ID: A7F78BCB859CD890
7 changed files with 31 additions and 30 deletions

View file

@ -16,7 +16,7 @@ const { error } = console;
const input = async (config: WtcConfig): Promise<WtcPromptResult> => {
const msg = message(config.language);
const fmtDuration = formatDuration(config.language);
const { defaults, askInput } = config;
const { defaults, askInput, lunchBreakDuration } = config;
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
@ -91,13 +91,13 @@ const input = async (config: WtcConfig): Promise<WtcPromptResult> => {
let worked = dayjs.duration(stoppedAt.diff(startedAt));
let hadLunch = false;
if (askInput.hadLunch) {
if (lunchBreakDuration) {
const lunchAnswer = (await rl.question(msg(MessageKey.promptLunchBreak))).toLowerCase();
hadLunch = lunchAnswer === 'y' || lunchAnswer === 'k';
}
if (hadLunch) {
worked = worked.subtract(defaults.lunchBreakDuration);
if (lunchAnswer === 'y' || lunchAnswer === 'k') {
hadLunch = true
worked = worked.subtract(lunchBreakDuration);
}
}
// Calculate unlogged time