Skip to content

Commit

Permalink
Update duration formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Feb 19, 2024
1 parent d25a7b4 commit 32302e6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 0 additions & 2 deletions modern/src/common/util/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ export const formatSpeed = (value, unit, t) => `${speedFromKnots(value, unit).to

export const formatVolume = (value, unit, t) => `${volumeFromLiters(value, unit).toFixed(2)} ${volumeUnitString(unit, t)}`;

export const formatHours = (value) => dayjs.duration(value).humanize();

export const formatNumericHours = (value, t) => {
const hours = Math.floor(value / 3600000);
const minutes = Math.floor((value % 3600000) / 60000);
Expand Down
6 changes: 3 additions & 3 deletions modern/src/reports/StopReportPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import GpsFixedIcon from '@mui/icons-material/GpsFixed';
import LocationSearchingIcon from '@mui/icons-material/LocationSearching';
import {
formatDistance, formatHours, formatVolume, formatTime,
formatDistance, formatVolume, formatTime, formatNumericHours,
} from '../common/util/formatter';
import ReportFilter from './components/ReportFilter';
import { useAttributePreference, usePreference } from '../common/util/preferences';
Expand Down Expand Up @@ -95,9 +95,9 @@ const StopReportPage = () => {
case 'startOdometer':
return formatDistance(item[key], distanceUnit, t);
case 'duration':
return formatHours(item[key]);
return formatNumericHours(item[key], t);
case 'engineHours':
return formatHours(item[key]);
return formatNumericHours(item[key], t);
case 'spentFuel':
return formatVolume(item[key], volumeUnit, t);
case 'address':
Expand Down
4 changes: 2 additions & 2 deletions modern/src/reports/SummaryReportPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
FormControl, InputLabel, Select, MenuItem, Table, TableHead, TableRow, TableBody, TableCell,
} from '@mui/material';
import {
formatDistance, formatHours, formatSpeed, formatVolume, formatTime,
formatDistance, formatSpeed, formatVolume, formatTime, formatNumericHours,
} from '../common/util/formatter';
import ReportFilter from './components/ReportFilter';
import { useAttributePreference, usePreference } from '../common/util/preferences';
Expand Down Expand Up @@ -101,7 +101,7 @@ const SummaryReportPage = () => {
case 'maxSpeed':
return formatSpeed(item[key], speedUnit, t);
case 'engineHours':
return formatHours(item[key]);
return formatNumericHours(item[key], t);
case 'spentFuel':
return formatVolume(item[key], volumeUnit, t);
default:
Expand Down
4 changes: 2 additions & 2 deletions modern/src/reports/TripReportPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import GpsFixedIcon from '@mui/icons-material/GpsFixed';
import LocationSearchingIcon from '@mui/icons-material/LocationSearching';
import {
formatDistance, formatSpeed, formatHours, formatVolume, formatTime,
formatDistance, formatSpeed, formatVolume, formatTime, formatNumericHours,
} from '../common/util/formatter';
import ReportFilter from './components/ReportFilter';
import { useAttributePreference, usePreference } from '../common/util/preferences';
Expand Down Expand Up @@ -142,7 +142,7 @@ const TripReportPage = () => {
case 'maxSpeed':
return formatSpeed(item[key], speedUnit, t);
case 'duration':
return formatHours(item[key]);
return formatNumericHours(item[key], t);
case 'spentFuel':
return formatVolume(item[key], volumeUnit, t);
case 'startAddress':
Expand Down

0 comments on commit 32302e6

Please sign in to comment.