diff options
Diffstat (limited to 'modern/src/common/formatter.js')
-rw-r--r-- | modern/src/common/formatter.js | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index 0ff4e74..f8a55da 100644 --- a/modern/src/common/formatter.js +++ b/modern/src/common/formatter.js @@ -4,9 +4,12 @@ export const formatBoolean = (value, t) => (value ? t('sharedYes') : t('sharedNo export const formatNumber = (value, precision = 1) => Number(value.toFixed(precision)); -export const formatDate = (value, format = 'YYYY-MM-DD HH:mm') => moment(value).format(format); +export const formatDate = (value, locale) => new Intl.DateTimeFormat(locale, { + dateStyle: 'medium', + timeStyle: 'short', +}).format(Date.parse(value)); -export const formatPosition = (value, key, t) => { +export const formatPosition = (value, key, t, locale = 'es') => { if (value != null && typeof value === 'object') { value = value[key]; } @@ -15,7 +18,7 @@ export const formatPosition = (value, key, t) => { case 'deviceTime': case 'serverTime': case 'eventTime': - return moment(value).format('LLL'); + return formatDate(value, locale); case 'latitude': case 'longitude': return value.toFixed(5); @@ -47,15 +50,7 @@ export const formatDistance = (value, 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')}`; - } + return `${(value * 1).toFixed(0)} ${t('sharedKmh')}`; }; export const formatVolume = (value, unit, t) => { @@ -70,7 +65,10 @@ export const formatVolume = (value, unit, t) => { } }; -export const formatHours = (value) => moment.duration(value).humanize(); +export const formatHours = (value, t) => { + moment.locale('es'); + return `${moment.duration(value).asHours().toFixed(0)} ${t('sharedHours')}`; +} export const formatCoordinate = (key, value, unit) => { let hemisphere; |