Add output for lunch break duration and rework config lunch option
This commit is contained in:
parent
29ded9426b
commit
71e8352ecf
7 changed files with 31 additions and 30 deletions
|
@ -8,6 +8,10 @@
|
||||||
},
|
},
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"lunchBreakDuration": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Remove or set as \"00:00\" if you don't have an unpaid lunch break or if you normally log your lunch break hours"
|
||||||
|
},
|
||||||
"language": {
|
"language": {
|
||||||
"$ref": "#/definitions/language",
|
"$ref": "#/definitions/language",
|
||||||
"description": "The language of the application. Currently supported languages are 'en', 'fi'"
|
"description": "The language of the application. Currently supported languages are 'en', 'fi'"
|
||||||
|
@ -19,10 +23,6 @@
|
||||||
"defaults": {
|
"defaults": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"lunchBreakDuration": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Set as \"00:00\" if you don't have an unpaid lunch break or if you normally log your lunch break hours"
|
|
||||||
},
|
|
||||||
"workDayDuration": { "type": "string", "description": "Your work day duration" },
|
"workDayDuration": { "type": "string", "description": "Your work day duration" },
|
||||||
"startTime": { "type": "string", "description": "The time you start working" },
|
"startTime": { "type": "string", "description": "The time you start working" },
|
||||||
"stopTime": {
|
"stopTime": {
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
# usually ~/.config/wtc/config.toml
|
# usually ~/.config/wtc/config.toml
|
||||||
# For windows, I don't know.
|
# For windows, I don't know.
|
||||||
|
|
||||||
|
# Remove or set as "00:00" if you don't have an unpaid lunch break
|
||||||
|
# or if you normally log your lunch break hours
|
||||||
|
lunchBreakDuration = "00:30"
|
||||||
|
|
||||||
# The language of the application.
|
# The language of the application.
|
||||||
# Currently supported languages are "en", "fi"
|
# Currently supported languages are "en", "fi"
|
||||||
language = "en"
|
language = "en"
|
||||||
|
@ -20,10 +24,6 @@ timestampFormat = "YYYY-MM-DD HH:mm"
|
||||||
# This section is for default values for inputs
|
# This section is for default values for inputs
|
||||||
[defaults]
|
[defaults]
|
||||||
|
|
||||||
# Set as "00:00" if you don't have an unpaid lunch break
|
|
||||||
# or if you normally log your lunch break hours
|
|
||||||
lunchBreakDuration = "00:30"
|
|
||||||
|
|
||||||
# Your work day duration
|
# Your work day duration
|
||||||
workDayDuration = "07:30"
|
workDayDuration = "07:30"
|
||||||
|
|
||||||
|
@ -41,6 +41,3 @@ workDayDuration = true
|
||||||
startTime = true
|
startTime = true
|
||||||
stopTime = true
|
stopTime = true
|
||||||
logged = true
|
logged = true
|
||||||
|
|
||||||
# It is assumed that you didn't have lunch if this is false
|
|
||||||
hadLunch = true
|
|
||||||
|
|
|
@ -6,10 +6,10 @@ import { parseDuration, parseTimestamp } from './parse.js';
|
||||||
import WtcConfig from './types/WtcConfig.js';
|
import WtcConfig from './types/WtcConfig.js';
|
||||||
import Language from './types/Language.js';
|
import Language from './types/Language.js';
|
||||||
|
|
||||||
interface RawConfig extends Omit<WtcConfig, 'defaults'> {
|
interface RawConfig extends Omit<WtcConfig, 'lunchBreakDuration' | 'defaults'> {
|
||||||
|
lunchBreakDuration: string;
|
||||||
defaults: {
|
defaults: {
|
||||||
workDayDuration: string;
|
workDayDuration: string;
|
||||||
lunchBreakDuration: string;
|
|
||||||
startTime: string;
|
startTime: string;
|
||||||
stopTime: string;
|
stopTime: string;
|
||||||
};
|
};
|
||||||
|
@ -18,9 +18,9 @@ interface RawConfig extends Omit<WtcConfig, 'defaults'> {
|
||||||
const defaultConfig: RawConfig = {
|
const defaultConfig: RawConfig = {
|
||||||
language: Language.en,
|
language: Language.en,
|
||||||
timestampFormat: 'YYYY-MM-DD HH:mm',
|
timestampFormat: 'YYYY-MM-DD HH:mm',
|
||||||
|
lunchBreakDuration: '00:30',
|
||||||
defaults: {
|
defaults: {
|
||||||
workDayDuration: '07:30',
|
workDayDuration: '07:30',
|
||||||
lunchBreakDuration: '00:30',
|
|
||||||
startTime: '08:00',
|
startTime: '08:00',
|
||||||
stopTime: 'now',
|
stopTime: 'now',
|
||||||
},
|
},
|
||||||
|
@ -29,7 +29,6 @@ const defaultConfig: RawConfig = {
|
||||||
startTime: true,
|
startTime: true,
|
||||||
stopTime: true,
|
stopTime: true,
|
||||||
logged: true,
|
logged: true,
|
||||||
hadLunch: true,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,13 +46,11 @@ const getConfig = (): WtcConfig => {
|
||||||
return {
|
return {
|
||||||
language: configData.language ?? defaultConfig.language,
|
language: configData.language ?? defaultConfig.language,
|
||||||
timestampFormat: configData.timestampFormat ?? defaultConfig.timestampFormat,
|
timestampFormat: configData.timestampFormat ?? defaultConfig.timestampFormat,
|
||||||
|
lunchBreakDuration: parseDuration(configData.lunchBreakDuration),
|
||||||
defaults: {
|
defaults: {
|
||||||
workDayDuration: parseDuration(
|
workDayDuration: parseDuration(
|
||||||
configData.defaults.workDayDuration ?? defaultConfig.defaults.workDayDuration,
|
configData.defaults.workDayDuration ?? defaultConfig.defaults.workDayDuration,
|
||||||
),
|
),
|
||||||
lunchBreakDuration: parseDuration(
|
|
||||||
configData.defaults.lunchBreakDuration ?? defaultConfig.defaults.workDayDuration,
|
|
||||||
),
|
|
||||||
startTime: parseTimestamp(configData.defaults.startTime ?? defaultConfig.defaults.startTime),
|
startTime: parseTimestamp(configData.defaults.startTime ?? defaultConfig.defaults.startTime),
|
||||||
stopTime: parseTimestamp(configData.defaults.stopTime ?? defaultConfig.defaults.stopTime),
|
stopTime: parseTimestamp(configData.defaults.stopTime ?? defaultConfig.defaults.stopTime),
|
||||||
},
|
},
|
||||||
|
@ -62,7 +59,6 @@ const getConfig = (): WtcConfig => {
|
||||||
startTime: configData.askInput.startTime ?? defaultConfig.askInput.startTime,
|
startTime: configData.askInput.startTime ?? defaultConfig.askInput.startTime,
|
||||||
stopTime: configData.askInput.stopTime ?? defaultConfig.askInput.stopTime,
|
stopTime: configData.askInput.stopTime ?? defaultConfig.askInput.stopTime,
|
||||||
logged: configData.askInput.logged ?? defaultConfig.askInput.logged,
|
logged: configData.askInput.logged ?? defaultConfig.askInput.logged,
|
||||||
hadLunch: configData.askInput.hadLunch ?? defaultConfig.askInput.hadLunch,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,7 @@ export enum MessageKey {
|
||||||
parseTimeFailed,
|
parseTimeFailed,
|
||||||
startTimeBeforeStopTimeError,
|
startTimeBeforeStopTimeError,
|
||||||
promptLunchBreak,
|
promptLunchBreak,
|
||||||
|
unpaidLunch,
|
||||||
promptLogged,
|
promptLogged,
|
||||||
none,
|
none,
|
||||||
startedWorking,
|
startedWorking,
|
||||||
|
@ -46,6 +47,10 @@ const messages: Record<MessageKey, Record<Language, string>> = {
|
||||||
[Language.en]: 'Did you have a lunch break? [y/N]: ',
|
[Language.en]: 'Did you have a lunch break? [y/N]: ',
|
||||||
[Language.fi]: 'Piditkö jo lounastauon? [k/E]: ',
|
[Language.fi]: 'Piditkö jo lounastauon? [k/E]: ',
|
||||||
},
|
},
|
||||||
|
[MessageKey.unpaidLunch]: {
|
||||||
|
[Language.en]: 'Unpaid lunch duration:',
|
||||||
|
[Language.fi]: 'Palkattoman lounaan pituus:',
|
||||||
|
},
|
||||||
[MessageKey.promptLogged]: {
|
[MessageKey.promptLogged]: {
|
||||||
[Language.en]: 'How many hours did you log already? [00:00] ',
|
[Language.en]: 'How many hours did you log already? [00:00] ',
|
||||||
[Language.fi]: 'Kuinka monta tuntia kirjasit jo? [00:00] ',
|
[Language.fi]: 'Kuinka monta tuntia kirjasit jo? [00:00] ',
|
||||||
|
|
12
src/input.ts
12
src/input.ts
|
@ -16,7 +16,7 @@ const { error } = console;
|
||||||
const input = async (config: WtcConfig): Promise<WtcPromptResult> => {
|
const input = async (config: WtcConfig): Promise<WtcPromptResult> => {
|
||||||
const msg = message(config.language);
|
const msg = message(config.language);
|
||||||
const fmtDuration = formatDuration(config.language);
|
const fmtDuration = formatDuration(config.language);
|
||||||
const { defaults, askInput } = config;
|
const { defaults, askInput, lunchBreakDuration } = config;
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout,
|
output: process.stdout,
|
||||||
|
@ -91,13 +91,13 @@ const input = async (config: WtcConfig): Promise<WtcPromptResult> => {
|
||||||
let worked = dayjs.duration(stoppedAt.diff(startedAt));
|
let worked = dayjs.duration(stoppedAt.diff(startedAt));
|
||||||
|
|
||||||
let hadLunch = false;
|
let hadLunch = false;
|
||||||
if (askInput.hadLunch) {
|
if (lunchBreakDuration) {
|
||||||
const lunchAnswer = (await rl.question(msg(MessageKey.promptLunchBreak))).toLowerCase();
|
const lunchAnswer = (await rl.question(msg(MessageKey.promptLunchBreak))).toLowerCase();
|
||||||
hadLunch = lunchAnswer === 'y' || lunchAnswer === 'k';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hadLunch) {
|
if (lunchAnswer === 'y' || lunchAnswer === 'k') {
|
||||||
worked = worked.subtract(defaults.lunchBreakDuration);
|
hadLunch = true
|
||||||
|
worked = worked.subtract(lunchBreakDuration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate unlogged time
|
// Calculate unlogged time
|
||||||
|
|
|
@ -7,21 +7,25 @@ import WtcConfig from './types/WtcConfig';
|
||||||
const { log } = console;
|
const { log } = console;
|
||||||
|
|
||||||
const output = (result: WtcPromptResult, config: WtcConfig) => {
|
const output = (result: WtcPromptResult, config: WtcConfig) => {
|
||||||
const {language, timestampFormat} = config;
|
const { language, timestampFormat } = config;
|
||||||
const msg = message(language);
|
const msg = message(language);
|
||||||
const fmtDuration = formatDuration(language);
|
const fmtDuration = formatDuration(language);
|
||||||
const hoursRounded = getHoursRoundedStr(language);
|
const hoursRounded = getHoursRoundedStr(language);
|
||||||
const { startedAt, stoppedAt, stoppedWorking, worked, unLogged, workLeft, workedOvertime } = result;
|
const { startedAt, stoppedAt, stoppedWorking, worked, unLogged, workLeft, workedOvertime, hadLunch } = result;
|
||||||
|
|
||||||
log();
|
log();
|
||||||
log(msg(MessageKey.startedWorking), startedAt.format(timestampFormat));
|
log(msg(MessageKey.startedWorking), startedAt.format(timestampFormat));
|
||||||
log(
|
log(
|
||||||
(stoppedWorking ? msg(MessageKey.stoppedWorking) : msg(MessageKey.hoursCalculated)) +
|
(stoppedWorking ? msg(MessageKey.stoppedWorking) : msg(MessageKey.hoursCalculated)) +
|
||||||
` ${msg(MessageKey.klo)}:`,
|
` ${msg(MessageKey.klo)}:`,
|
||||||
stoppedAt.format(timestampFormat)
|
stoppedAt.format(timestampFormat),
|
||||||
);
|
);
|
||||||
log(msg(MessageKey.workedToday), chalk.green(fmtDuration(worked)), chalk.yellow(hoursRounded(worked)));
|
log(msg(MessageKey.workedToday), chalk.green(fmtDuration(worked)), chalk.yellow(hoursRounded(worked)));
|
||||||
|
|
||||||
|
if (hadLunch) {
|
||||||
|
log(msg(MessageKey.unpaidLunch), chalk.green(fmtDuration(config.defaults.lunchBreakDuration)));
|
||||||
|
}
|
||||||
|
|
||||||
const unLoggedMinutes = unLogged.asMinutes();
|
const unLoggedMinutes = unLogged.asMinutes();
|
||||||
if (unLoggedMinutes >= 0) {
|
if (unLoggedMinutes >= 0) {
|
||||||
log(
|
log(
|
||||||
|
|
|
@ -5,9 +5,9 @@ import Language from './Language.js';
|
||||||
export default interface WtcConfig {
|
export default interface WtcConfig {
|
||||||
language: Language,
|
language: Language,
|
||||||
timestampFormat: string,
|
timestampFormat: string,
|
||||||
|
lunchBreakDuration?: Duration;
|
||||||
defaults: {
|
defaults: {
|
||||||
workDayDuration: Duration;
|
workDayDuration: Duration;
|
||||||
lunchBreakDuration: Duration;
|
|
||||||
startTime: Dayjs;
|
startTime: Dayjs;
|
||||||
stopTime: Dayjs;
|
stopTime: Dayjs;
|
||||||
};
|
};
|
||||||
|
@ -16,6 +16,5 @@ export default interface WtcConfig {
|
||||||
startTime: boolean;
|
startTime: boolean;
|
||||||
stopTime: boolean;
|
stopTime: boolean;
|
||||||
logged: boolean;
|
logged: boolean;
|
||||||
hadLunch: boolean;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue