Add support for configurable timestamp format
This commit is contained in:
parent
aee473b93b
commit
b76700923d
5 changed files with 16 additions and 8 deletions
|
@ -9,6 +9,11 @@
|
|||
# Currently supported languages are "en", "fi"
|
||||
language = "en"
|
||||
|
||||
# Time format used to display timestamps (started, stopped etc.)
|
||||
# Refer to the dayjs documentation on how to set this https://day.js.org/docs/en/display/format
|
||||
# For example, the finnish format would be "MM.DD.YYYY [kello] HH.mm"
|
||||
timestampFormat = "YYYY-MM-DD HH:mm"
|
||||
|
||||
# This section is for default values for inputs
|
||||
[defaults]
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ interface RawConfig extends Omit<WtcConfig, 'defaults'> {
|
|||
|
||||
const defaultConfig: RawConfig = {
|
||||
language: Language.en,
|
||||
timestampFormat: 'YYYY-MM-DD HH:mm',
|
||||
defaults: {
|
||||
workDayDuration: '07:30',
|
||||
lunchBreakDuration: '00:30',
|
||||
|
@ -45,6 +46,7 @@ const getConfig = (): WtcConfig => {
|
|||
|
||||
return {
|
||||
language: configData.language ?? defaultConfig.language,
|
||||
timestampFormat: configData.timestampFormat ?? defaultConfig.timestampFormat,
|
||||
defaults: {
|
||||
workDayDuration: parseDuration(
|
||||
configData.defaults.workDayDuration ?? defaultConfig.defaults.workDayDuration,
|
||||
|
|
|
@ -3,8 +3,6 @@ import { Duration } from 'dayjs/plugin/duration.js';
|
|||
import Language from './types/Language';
|
||||
import { MessageKey, message } from './i18n';
|
||||
|
||||
export const formatTimestamp = (timestamp: Dayjs): string => timestamp.format('YYYY-MM-DD HH:mm');
|
||||
|
||||
export const formatTime = (time: Dayjs): string => time.format('HH:mm');
|
||||
|
||||
export const formatDuration =
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import chalk from 'chalk';
|
||||
import { formatDuration, formatTimestamp, getHoursRoundedStr } from './format';
|
||||
import { formatDuration, getHoursRoundedStr } from './format';
|
||||
import { WtcPromptResult } from './types/WtcPromptResult';
|
||||
import { MessageKey, message } from './i18n.js';
|
||||
import WtcConfig from './types/WtcConfig';
|
||||
|
@ -7,16 +7,18 @@ import WtcConfig from './types/WtcConfig';
|
|||
const { log } = console;
|
||||
|
||||
const output = (result: WtcPromptResult, config: WtcConfig) => {
|
||||
const msg = message(config.language);
|
||||
const fmtDuration = formatDuration(config.language);
|
||||
const hoursRounded = getHoursRoundedStr(config.language);
|
||||
const {language, timestampFormat} = config;
|
||||
const msg = message(language);
|
||||
const fmtDuration = formatDuration(language);
|
||||
const hoursRounded = getHoursRoundedStr(language);
|
||||
const { startedAt, stoppedAt, stoppedWorking, worked, unLogged, workLeft, workedOvertime } = result;
|
||||
|
||||
log();
|
||||
log(msg(MessageKey.startedWorking), formatTimestamp(startedAt));
|
||||
log(msg(MessageKey.startedWorking), startedAt.format(timestampFormat));
|
||||
log(
|
||||
(stoppedWorking ? msg(MessageKey.stoppedWorking) : msg(MessageKey.hoursCalculated)) +
|
||||
` ${msg(MessageKey.klo)}:`,
|
||||
formatTimestamp(stoppedAt),
|
||||
stoppedAt.format(timestampFormat)
|
||||
);
|
||||
log(msg(MessageKey.workedToday), chalk.green(fmtDuration(worked)), chalk.yellow(hoursRounded(worked)));
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import Language from './Language.js';
|
|||
|
||||
export default interface WtcConfig {
|
||||
language: Language,
|
||||
timestampFormat: string,
|
||||
defaults: {
|
||||
workDayDuration: Duration;
|
||||
lunchBreakDuration: Duration;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue