Add config.defaults.hadLunch and rework lunch messages
This commit is contained in:
parent
91a7362495
commit
b08ab097ba
8 changed files with 60 additions and 24 deletions
|
@ -4,7 +4,7 @@
|
|||
"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"
|
||||
"description": "Comment out or remove if you don't have an unpaid lunch break or if you normally log your lunch break hours"
|
||||
},
|
||||
"language": {
|
||||
"type": "string",
|
||||
|
@ -23,7 +23,8 @@
|
|||
"stopTime": {
|
||||
"type": ["string", "null"],
|
||||
"description": "The time you stop working. Can either be 'now' or a time"
|
||||
}
|
||||
},
|
||||
"hadLunch": { "type": "boolean", "description": "Wether you had lunch already or not" }
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"description": "Default values for inputs"
|
||||
|
@ -37,8 +38,7 @@
|
|||
},
|
||||
"startTime": { "type": "boolean", "description": "Disable prompt for start time if set to false" },
|
||||
"stopTime": { "type": "boolean", "description": "Disable prompt for stop time if set to false" },
|
||||
"logged": { "type": "boolean", "description": "Disable prompt for logged time if set to false" },
|
||||
"hadLunch": { "type": "boolean", "description": "Assumed that you didn't have lunch if this is false" }
|
||||
"logged": { "type": "boolean", "description": "Disable prompt for logged time if set to false" }
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"description": "Settings to disable prompts"
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
# usually ~/.config/wtc/config.toml
|
||||
# For windows, I don't know.
|
||||
|
||||
# Remove or set as "00:00" if you don't have an unpaid lunch break
|
||||
# Comment out or remove if you don't have an unpaid lunch break
|
||||
# or if you normally log your lunch break hours
|
||||
lunchBreakDuration = "00:30"
|
||||
unpaidLunchBreakDuration = "00:30"
|
||||
|
||||
# The language of the application.
|
||||
# Currently supported languages are "en", "fi"
|
||||
|
|
|
@ -6,23 +6,25 @@ import { parseDuration, parseTimestamp } from './parse.js';
|
|||
import WtcConfig from './types/WtcConfig.js';
|
||||
import Language from './types/Language.js';
|
||||
|
||||
interface RawConfig extends Omit<WtcConfig, 'lunchBreakDuration' | 'defaults'> {
|
||||
lunchBreakDuration: string;
|
||||
interface RawConfig extends Omit<WtcConfig, 'unpaidLunchBreakDuration' | 'defaults'> {
|
||||
unpaidLunchBreakDuration: string;
|
||||
defaults: {
|
||||
workDayDuration: string;
|
||||
startTime: string;
|
||||
stopTime: string;
|
||||
hadLunch: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
const defaultConfig: RawConfig = {
|
||||
language: Language.en,
|
||||
timestampFormat: 'YYYY-MM-DD HH:mm',
|
||||
lunchBreakDuration: '00:30',
|
||||
unpaidLunchBreakDuration: '00:30',
|
||||
defaults: {
|
||||
workDayDuration: '07:30',
|
||||
startTime: '08:00',
|
||||
stopTime: 'now',
|
||||
hadLunch: true,
|
||||
},
|
||||
askInput: {
|
||||
workDayLength: true,
|
||||
|
@ -46,13 +48,14 @@ const getConfig = (): WtcConfig => {
|
|||
return {
|
||||
language: configData.language ?? defaultConfig.language,
|
||||
timestampFormat: configData.timestampFormat ?? defaultConfig.timestampFormat,
|
||||
lunchBreakDuration: parseDuration(configData.lunchBreakDuration),
|
||||
unpaidLunchBreakDuration: !configData.unpaidLunchBreakDuration ? undefined : parseDuration(configData.unpaidLunchBreakDuration),
|
||||
defaults: {
|
||||
workDayDuration: parseDuration(
|
||||
configData.defaults.workDayDuration ?? defaultConfig.defaults.workDayDuration,
|
||||
),
|
||||
startTime: parseTimestamp(configData.defaults.startTime ?? defaultConfig.defaults.startTime),
|
||||
stopTime: parseTimestamp(configData.defaults.stopTime ?? defaultConfig.defaults.stopTime),
|
||||
hadLunch: configData.defaults.hadLunch ?? defaultConfig.defaults.hadLunch,
|
||||
},
|
||||
askInput: {
|
||||
workDayLength: configData.askInput.workDayLength ?? defaultConfig.askInput.workDayLength,
|
||||
|
|
|
@ -7,7 +7,8 @@ export const formatTime = (time: Dayjs): string => time.format('HH:mm');
|
|||
|
||||
export const formatDuration =
|
||||
(language: Language) =>
|
||||
(duration: Duration, short?: boolean): string => {
|
||||
(duration?: Duration, short?: boolean): string => {
|
||||
duration = duration ?? dayjs.duration(0, 'minutes');
|
||||
if (duration.hours() === 0 && duration.minutes() === 0) {
|
||||
return 'none';
|
||||
}
|
||||
|
|
28
src/i18n.ts
28
src/i18n.ts
|
@ -1,12 +1,16 @@
|
|||
import Language from './types/Language';
|
||||
|
||||
|
||||
export enum MessageKey {
|
||||
promptWorkDayDuration,
|
||||
excludingLunch,
|
||||
promptStartTime,
|
||||
promptStopTime,
|
||||
parseTimeFailed,
|
||||
startTimeBeforeStopTimeError,
|
||||
promptLunchBreak,
|
||||
promptYesNoYes,
|
||||
promptYesNoNo,
|
||||
unpaidLunch,
|
||||
promptLogged,
|
||||
none,
|
||||
|
@ -24,8 +28,12 @@ export enum MessageKey {
|
|||
|
||||
const messages: Record<MessageKey, Record<Language, string>> = {
|
||||
[MessageKey.promptWorkDayDuration]: {
|
||||
[Language.en]: 'How long is your work day today, excluding the lunch break? [{0}]: ',
|
||||
[Language.fi]: 'Kuinka pitkä työpäiväsi on tänään, poisluettuna lounastauko? [{0}]: ',
|
||||
[Language.en]: 'How long is your work day today{0}? [{1}]: ',
|
||||
[Language.fi]: 'Kuinka pitkä työpäiväsi on tänään{0}? [{1}]: ',
|
||||
},
|
||||
[MessageKey.excludingLunch]: {
|
||||
[Language.en]: ', excluding the lunch break',
|
||||
[Language.fi]: ', poisluettuna lounastauko',
|
||||
},
|
||||
[MessageKey.promptStartTime]: {
|
||||
[Language.en]: 'What time did you start work today? [{0}]: ',
|
||||
|
@ -44,12 +52,20 @@ const messages: Record<MessageKey, Record<Language, string>> = {
|
|||
[Language.fi]: 'Aloitusaika ({0}) pitää olla ennen lopetusaikaa ({1}). Ohjelma sammuu',
|
||||
},
|
||||
[MessageKey.promptLunchBreak]: {
|
||||
[Language.en]: 'Did you have a lunch break? [y/N]: ',
|
||||
[Language.fi]: 'Piditkö jo lounastauon? [k/E]: ',
|
||||
[Language.en]: 'Did you have a lunch break? [{0}]: ',
|
||||
[Language.fi]: 'Piditkö jo lounastauon? [{0}]: ',
|
||||
},
|
||||
[MessageKey.promptYesNoYes]: {
|
||||
[Language.en]: 'Y/n',
|
||||
[Language.fi]: 'K/e',
|
||||
},
|
||||
[MessageKey.promptYesNoNo]: {
|
||||
[Language.en]: 'y/N',
|
||||
[Language.fi]: 'k/E',
|
||||
},
|
||||
[MessageKey.unpaidLunch]: {
|
||||
[Language.en]: 'Unpaid lunch duration:',
|
||||
[Language.fi]: 'Palkattoman lounaan pituus:',
|
||||
[Language.en]: 'Unpaid lunch:',
|
||||
[Language.fi]: 'Palkaton lounas:',
|
||||
},
|
||||
[MessageKey.promptLogged]: {
|
||||
[Language.en]: 'How many hours did you log already? [00:00] ',
|
||||
|
|
25
src/input.ts
25
src/input.ts
|
@ -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, lunchBreakDuration } = config;
|
||||
const { defaults, askInput, unpaidLunchBreakDuration: lunchBreakDuration } = config;
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
|
@ -32,7 +32,11 @@ const input = async (config: WtcConfig): Promise<WtcPromptResult> => {
|
|||
|
||||
if (askInput.workDayLength) {
|
||||
const durationAnswer = await rl.question(
|
||||
msg(MessageKey.promptWorkDayDuration, fmtDuration(defaults.workDayDuration, true)),
|
||||
msg(
|
||||
MessageKey.promptWorkDayDuration,
|
||||
config.unpaidLunchBreakDuration ? msg(MessageKey.excludingLunch) : '',
|
||||
fmtDuration(defaults.workDayDuration, true),
|
||||
),
|
||||
);
|
||||
if (durationAnswer !== '') {
|
||||
workDayDuration = parseDuration(durationAnswer);
|
||||
|
@ -92,10 +96,21 @@ const input = async (config: WtcConfig): Promise<WtcPromptResult> => {
|
|||
|
||||
let hadLunch = false;
|
||||
if (lunchBreakDuration) {
|
||||
const lunchAnswer = (await rl.question(msg(MessageKey.promptLunchBreak))).toLowerCase();
|
||||
const lunchAnswer = (
|
||||
await rl.question(
|
||||
msg(
|
||||
MessageKey.promptLunchBreak,
|
||||
msg(config.defaults.hadLunch ? MessageKey.promptYesNoYes : MessageKey.promptYesNoNo),
|
||||
),
|
||||
)
|
||||
).toLowerCase();
|
||||
|
||||
if (lunchAnswer === 'y' || lunchAnswer === 'k') {
|
||||
hadLunch = true
|
||||
if (
|
||||
lunchAnswer === 'y' ||
|
||||
lunchAnswer === 'k' ||
|
||||
(config.defaults.hadLunch && lunchAnswer !== 'n' && lunchAnswer !== 'e')
|
||||
) {
|
||||
hadLunch = true;
|
||||
worked = worked.subtract(lunchBreakDuration);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ const output = (result: WtcPromptResult, config: WtcConfig) => {
|
|||
log(msg(MessageKey.workedToday), chalk.green(fmtDuration(worked)), chalk.yellow(hoursRounded(worked)));
|
||||
|
||||
if (hadLunch) {
|
||||
log(msg(MessageKey.unpaidLunch), chalk.green(fmtDuration(config.defaults.lunchBreakDuration)));
|
||||
log(msg(MessageKey.unpaidLunch), chalk.green(fmtDuration(config.unpaidLunchBreakDuration)));
|
||||
}
|
||||
|
||||
const unLoggedMinutes = unLogged.asMinutes();
|
||||
|
|
|
@ -5,11 +5,12 @@ import Language from './Language.js';
|
|||
export default interface WtcConfig {
|
||||
language: Language,
|
||||
timestampFormat: string,
|
||||
lunchBreakDuration?: Duration;
|
||||
unpaidLunchBreakDuration?: Duration;
|
||||
defaults: {
|
||||
workDayDuration: Duration;
|
||||
startTime: Dayjs;
|
||||
stopTime: Dayjs;
|
||||
hadLunch: boolean;
|
||||
};
|
||||
askInput: {
|
||||
workDayLength: boolean;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue