diff options
Diffstat (limited to 'modern/src/common/formatter.js')
-rw-r--r-- | modern/src/common/formatter.js | 37 |
1 files changed, 4 insertions, 33 deletions
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index bc3af6fb..06e3b12f 100644 --- a/modern/src/common/formatter.js +++ b/modern/src/common/formatter.js @@ -1,4 +1,5 @@ import moment from 'moment'; +import { distanceFromMeters, distanceUnitString, speedFromKnots, speedUnitString, volumeFromLiters, volumeUnitString } from './converter'; import { prefixString } from './stringUtils'; export const formatBoolean = (value, t) => (value ? t('sharedYes') : t('sharedNo')); @@ -18,41 +19,11 @@ export const formatCourse = (value) => { return courseValues[Math.floor(value / 45)]; }; -export const formatDistance = (value, unit, t) => { - switch (unit) { - case 'mi': - return `${(value * 0.000621371).toFixed(2)} ${t('sharedMi')}`; - case 'nmi': - return `${(value * 0.000539957).toFixed(2)} ${t('sharedNmi')}`; - case 'km': - default: - return `${(value * 0.001).toFixed(2)} ${t('sharedKm')}`; - } -}; +export const formatDistance = (value, unit, t) => `${distanceFromMeters(value, unit).toFixed(2)} ${distanceUnitString(unit, t)}`; -export const formatSpeed = (value, unit, t) => { - switch (unit) { - case 'kmh': - return `${(value * 1.852).toFixed(2)} ${t('sharedKmh')}`; - case 'mph': - return `${(value * 1.15078).toFixed(2)} ${t('sharedMph')}`; - case 'kn': - default: - return `${(value * 1).toFixed(2)} ${t('sharedKn')}`; - } -}; +export const formatSpeed = (value, unit, t) => `${speedFromKnots(value, unit).toFixed(2)} ${speedUnitString(unit, t)}`; -export const formatVolume = (value, unit, t) => { - switch (unit) { - case 'impGal': - return `${(value / 4.546).toFixed(2)} ${t('sharedGallonAbbreviation')}`; - case 'usGal': - return `${(value / 3.785).toFixed(2)} ${t('sharedGallonAbbreviation')}`; - case 'ltr': - default: - return `${(value / 1).toFixed(2)} ${t('sharedLiterAbbreviation')}`; - } -}; +export const formatVolume = (value, unit, t) => `${volumeFromLiters(value, unit).toFixed(2)} ${volumeUnitString(unit, t)}`; export const formatHours = (value) => moment.duration(value).humanize(); |