Extract formatDuration to separate file
This commit is contained in:
parent
62723823ed
commit
481ae9c8a7
|
|
@ -1,27 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { stats, Workout, Duration, Intensity } from 'make-workout';
|
import { stats, Workout, Intensity } from 'make-workout';
|
||||||
|
import { formatDuration } from './formatDuration';
|
||||||
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 `-`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatIntensity = (intensity: Intensity): string => `${Math.round(intensity.value * 100)}%`;
|
const formatIntensity = (intensity: Intensity): string => `${Math.round(intensity.value * 100)}%`;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 `-`;
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue