Separate parse and format functions to their own files

This commit is contained in:
Marko Korhonen 2023-11-11 17:11:38 +02:00
parent 409c6c2739
commit 4835f4878e
Signed by: FunctionalHacker
GPG key ID: A7F78BCB859CD890
3 changed files with 33 additions and 27 deletions

17
src/format.ts Normal file
View file

@ -0,0 +1,17 @@
import dayjs, { Dayjs } from 'dayjs';
import { Duration } from 'dayjs/plugin/duration.js';
export const formatTimestamp = (timestamp: Dayjs): string => timestamp.format('YYYY-MM-DD HH:mm');
export const formatDuration = (unLogged: Duration): string => unLogged.format('HH[ hours and ]mm [minutes]');
export const getHoursRoundedStr = (duration: Duration) =>
`(${getHoursRounded(duration)} as hours rounded to next even 15 minutes)`;
const getHoursRounded = (duration: Duration) => {
// Round up to the next multiple of 15
const minutes = Math.ceil(duration.as('minutes') / 15) * 15;
// Return as hours
return dayjs.duration(minutes, 'minutes').asHours();
};