mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-15 12:23:51 +00:00
de9a7a87fd
* refactor(project structure): UI * refactor(project structure): extract utilities * refactor(project structure): remove unused * refactor(project structure): electron * refactor(project structure): server refactor: migrate to vitest refactor: monorepo config * refactor: extract application menu * refactor: exit process * refactor: extract tray menu * chore: electron build * Added Seconds in studio clock #282 --------- Co-authored-by: Fabian Posenau <fabian@fphome.de> --------- Co-authored-by: Fabian Posenau <fabian.p99@gmx.de> Co-authored-by: Fabian Posenau <fabian@fphome.de>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
export type TimeEntryField = 'timeStart' |'timeEnd' | 'durationOverride';
|
|
|
|
/**
|
|
* @description Milliseconds in a day
|
|
*/
|
|
export const DAY_TO_MS = 86400000;
|
|
|
|
/**
|
|
* @description calculates duration from given values
|
|
*/
|
|
export const calculateDuration = (start: number, end: number): number =>
|
|
start > end ? end + DAY_TO_MS - start : end - start;
|
|
|
|
/**
|
|
* @description Checks which field the value relates to
|
|
*/
|
|
export const handleTimeEntry = (field: TimeEntryField, val: number, timeStart: number, timeEnd: number): {start: number, end: number, durationOverride: boolean} => {
|
|
let start = timeStart;
|
|
let end = timeEnd;
|
|
let durationOverride = false;
|
|
|
|
if (field === 'timeStart') {
|
|
start = val;
|
|
} else if (field === 'timeEnd') {
|
|
end = val;
|
|
} else {
|
|
durationOverride = field === 'durationOverride';
|
|
}
|
|
return { start, end, durationOverride };
|
|
};
|
|
|
|
/**
|
|
* @description Validates time entry
|
|
*/
|
|
export const validateEntry = (field: TimeEntryField, value: number, timeStart: number, timeEnd: number): { value: boolean, catch: string } => {
|
|
const validate = { value: true, catch: '' };
|
|
|
|
const { start, end } = handleTimeEntry(field, value, timeStart, timeEnd);
|
|
|
|
if (end < start) {
|
|
validate.catch = 'Start time later than end time';
|
|
}
|
|
|
|
return validate;
|
|
};
|