diff options
Diffstat (limited to 'modern/src/common/util/formatter.js')
-rw-r--r-- | modern/src/common/util/formatter.js | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/modern/src/common/util/formatter.js b/modern/src/common/util/formatter.js index b00896c2..370542d1 100644 --- a/modern/src/common/util/formatter.js +++ b/modern/src/common/util/formatter.js @@ -1,4 +1,8 @@ -import moment from 'moment'; +import dayjs from 'dayjs'; +import 'dayjs/plugin/duration'; +import duration from 'dayjs/plugin/duration'; +import relativeTime from 'dayjs/plugin/relativeTime'; + import { altitudeFromMeters, altitudeUnitString, @@ -11,6 +15,9 @@ import { } from './converter'; import { prefixString } from './stringUtils'; +dayjs.extend(duration) +dayjs.extend(relativeTime) + export const formatBoolean = (value, t) => (value ? t('sharedYes') : t('sharedNo')); export const formatNumber = (value, precision = 1) => Number(value.toFixed(precision)); @@ -25,16 +32,16 @@ export const formatConsumption = (value, t) => `${value} ${t('sharedLiterPerHour export const formatTime = (value, format, hours12) => { if (value) { - const m = moment(value); + const d = dayjs(value); switch (format) { case 'date': - return m.format('YYYY-MM-DD'); + return d.format('YYYY-MM-DD'); case 'time': - return m.format(hours12 ? 'hh:mm:ss A' : 'HH:mm:ss'); + return d.format(hours12 ? 'hh:mm:ss A' : 'HH:mm:ss'); case 'minutes': - return m.format(hours12 ? 'YYYY-MM-DD hh:mm A' : 'YYYY-MM-DD HH:mm'); + return d.format(hours12 ? 'YYYY-MM-DD hh:mm A' : 'YYYY-MM-DD HH:mm'); default: - return m.format(hours12 ? 'YYYY-MM-DD hh:mm:ss A' : 'YYYY-MM-DD HH:mm:ss'); + return d.format(hours12 ? 'YYYY-MM-DD hh:mm:ss A' : 'YYYY-MM-DD HH:mm:ss'); } } return ''; @@ -60,7 +67,7 @@ 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) => moment.duration(value).humanize(); +export const formatHours = (value) => dayjs.duration(value).humanize(); export const formatNumericHours = (value, t) => { const hours = Math.floor(value / 3600000); |