diff options
author | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2020-11-12 16:03:33 +0530 |
---|---|---|
committer | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2020-11-12 16:03:33 +0530 |
commit | d7bfb9ac6fabf09f4675ea58bc58e12dbd04eee9 (patch) | |
tree | 6bd72c1b2a353740cfa4db24288ec906b6a8eaa8 /modern/src/common/formatter.js | |
parent | 2ead5e0a6ab859ac3436f378a1fec126e493c69b (diff) | |
download | trackermap-web-d7bfb9ac6fabf09f4675ea58bc58e12dbd04eee9.tar.gz trackermap-web-d7bfb9ac6fabf09f4675ea58bc58e12dbd04eee9.tar.bz2 trackermap-web-d7bfb9ac6fabf09f4675ea58bc58e12dbd04eee9.zip |
Implementing Trip Report with attribute formating
Diffstat (limited to 'modern/src/common/formatter.js')
-rw-r--r-- | modern/src/common/formatter.js | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index f04bb434..6705221a 100644 --- a/modern/src/common/formatter.js +++ b/modern/src/common/formatter.js @@ -9,6 +9,8 @@ export const formatPosition = (value, key) => { case 'fixTime': case 'deviceTime': case 'serverTime': + case 'startTime': + case 'endTime': return moment(value).format('LLL'); case 'latitude': case 'longitude': @@ -27,12 +29,44 @@ 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 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 formatHours = (value) => { + let hours, minutes; + hours = Math.floor(value / 3600000); + minutes = Math.floor(value % 3600000 / 60000); + + return `${hours} ${t('sharedHourAbbreviation')} ${minutes} ${t('sharedMinuteAbbreviation')}`; +}; |