diff --git a/src/components/WorkoutStats.tsx b/src/components/WorkoutStats.tsx index 945878d..6359679 100644 --- a/src/components/WorkoutStats.tsx +++ b/src/components/WorkoutStats.tsx @@ -1,27 +1,6 @@ import React from 'react'; -import { stats, Workout, Duration, Intensity } from 'make-workout'; - -const splitDuration = (duration: Duration) => ({ - hours: Math.floor(duration.seconds / 60 / 60), - minutes: Math.floor(duration.seconds / 60) % 60, - seconds: duration.seconds % 60, -}); - -const formatDuration = (duration: Duration): string => { - const {hours, minutes, seconds} = splitDuration(duration); - if (hours > 0) { - return `${hours}h ${minutes}min`; - } - else if (minutes > 0) { - return `${minutes}min`; - } - else if (seconds > 0) { - return `${seconds}sec`; - } - else { - return `-`; - } -}; +import { stats, Workout, Intensity } from 'make-workout'; +import { formatDuration } from './formatDuration'; const formatIntensity = (intensity: Intensity): string => `${Math.round(intensity.value * 100)}%`; diff --git a/src/components/formatDuration.ts b/src/components/formatDuration.ts new file mode 100644 index 0000000..877b0ab --- /dev/null +++ b/src/components/formatDuration.ts @@ -0,0 +1,23 @@ +import { Duration } from "make-workout"; + +const splitDuration = (duration: Duration) => ({ + hours: Math.floor(duration.seconds / 60 / 60), + minutes: Math.floor(duration.seconds / 60) % 60, + seconds: duration.seconds % 60, +}); + +export const formatDuration = (duration: Duration): string => { + const {hours, minutes, seconds} = splitDuration(duration); + if (hours > 0) { + return `${hours}h ${minutes}min`; + } + else if (minutes > 0) { + return `${minutes}min`; + } + else if (seconds > 0) { + return `${seconds}sec`; + } + else { + return `-`; + } +};