diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-11-13 22:07:43 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-13 22:07:43 -0800 |
commit | ad304bdb881bf2abc0ad477482b321208f343c43 (patch) | |
tree | 6c316a5c0774ef0b57907dc677c8cb6c0ae02a06 /modern/src/common/formatter.js | |
parent | 2ead5e0a6ab859ac3436f378a1fec126e493c69b (diff) | |
parent | 37ff59bbdc540bf2293a96ecbedcf210f6b4548a (diff) | |
download | etbsa-traccar-web-ad304bdb881bf2abc0ad477482b321208f343c43.tar.gz etbsa-traccar-web-ad304bdb881bf2abc0ad477482b321208f343c43.tar.bz2 etbsa-traccar-web-ad304bdb881bf2abc0ad477482b321208f343c43.zip |
Merge pull request #792 from mail2bishnoi/trip-stop-summary-dailysummary-reports
Implementing Trip Report with attribute formating
Diffstat (limited to 'modern/src/common/formatter.js')
-rw-r--r-- | modern/src/common/formatter.js | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index f04bb43..e41e591 100644 --- a/modern/src/common/formatter.js +++ b/modern/src/common/formatter.js @@ -27,12 +27,56 @@ export const formatPosition = (value, key) => { return value; } } -} +}; export const formatBoolean = (value) => { return value ? t('sharedYes') : t('sharedNo'); -} +}; export const formatNumber = (value, precision = 1) => { return Number(value.toFixed(precision)); +}; + +export const formatDate = (value, format = 'YYYY-MM-DD HH:mm') => { + return moment(value).format(format); +}; + +export const formatDistance = (value, unit) => { + 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 formatSpeed = (value, unit) => { + 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 formatVolume = (value, unit) => { + 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 formatHours = (value) => { + return moment.duration(value).humanize(); +}; |