From b6dd542cb37ca3f42684e152941e29815e567d91 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Fri, 26 Aug 2022 08:25:09 +0800 Subject: [PATCH] update time format --- src/libs/utils.js | 19 +++++++++++++++++++ src/views/Blocks.vue | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/libs/utils.js b/src/libs/utils.js index 5e02543e..bcf271c8 100644 --- a/src/libs/utils.js +++ b/src/libs/utils.js @@ -12,6 +12,7 @@ import { ethToEvmos } from '@tharsis/address-converter' import dayjs from 'dayjs' import duration from 'dayjs/plugin/duration' import relativeTime from 'dayjs/plugin/relativeTime' +import updateLocale from 'dayjs/plugin/updateLocale' import utc from 'dayjs/plugin/utc' import RIPEMD160 from 'ripemd160' import localeData from 'dayjs/plugin/localeData' @@ -25,7 +26,25 @@ import { EthereumLedgerSigner } from './client/EthereumLedgerSigner.ts' dayjs.extend(localeData) dayjs.extend(duration) dayjs.extend(relativeTime) +dayjs.extend(updateLocale) dayjs.extend(utc) +dayjs.updateLocale('en', { + relativeTime: { + future: 'in %s', + past: '%s ago', + s: '%ds', + m: '1m', + mm: '%dm', + h: 'an hour', + hh: '%d hours', + d: 'a day', + dd: '%d days', + M: 'a month', + MM: '%d months', + y: 'a year', + yy: '%d years', + }, +}) export function getLocalObject(name) { const text = localStorage.getItem(name) diff --git a/src/views/Blocks.vue b/src/views/Blocks.vue index 07db1106..3735602d 100644 --- a/src/views/Blocks.vue +++ b/src/views/Blocks.vue @@ -120,7 +120,7 @@ export default { ], txFields: [ { key: 'hash' }, - { key: 'time', formatter: v => toDay(v, 'time') }, + { key: 'time', formatter: v => toDay(v, 'from') }, { key: 'fee', formatter: v => tokenFormatter(v) }, { key: 'messages', formatter: v => abbrMessage(v) }, { key: 'memo' }, @@ -162,7 +162,7 @@ export default { methods: { length: v => (Array.isArray(v) ? v.length : 0), shortHash: v => abbr(v), - formatTime: v => toDay(v, 'time'), + formatTime: v => toDay(v, 'from'), formatProposer(v) { return getStakingValidatorByHex(this.$http.config.chain_name, v) },