From c9910c97b0018da75fe3070ca4178f01232525e2 Mon Sep 17 00:00:00 2001 From: hdmr14 <58992133+hdmr14@users.noreply.github.com> Date: Sun, 3 May 2020 22:17:38 +0900 Subject: [PATCH] fix: time format localization (#471) --- src/utils/package.test.ts | 10 +++++----- src/utils/package.ts | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/utils/package.test.ts b/src/utils/package.test.ts index 3c23787..1770d1b 100644 --- a/src/utils/package.test.ts +++ b/src/utils/package.test.ts @@ -50,7 +50,7 @@ describe('formatRepository', (): void => { describe('formatDate', (): void => { test('should format the date', (): void => { const date = 1532211072138; - expect(formatDate(date)).toEqual('21.07.2018, 22:11:12'); + expect(formatDate(date)).toEqual('07/21/2018 10:11:12 PM'); }); }); @@ -78,7 +78,7 @@ describe('formatDateDistance', (): void => { describe('getLastUpdatedPackageTime', (): void => { test('should get the last update time', (): void => { const lastUpdated = packageMeta._uplinks; - expect(getLastUpdatedPackageTime(lastUpdated)).toEqual('22.07.2018, 22:11:12'); + expect(getLastUpdatedPackageTime(lastUpdated)).toEqual('07/22/2018 10:11:12 PM'); }); test('should get the last update time for blank uplink', (): void => { @@ -91,9 +91,9 @@ describe('getRecentReleases', (): void => { test('should get the recent releases', (): void => { const { time } = packageMeta; const result = [ - { time: '14.12.2017, 15:43:27', version: '2.7.1' }, - { time: '05.12.2017, 23:25:06', version: '2.7.0' }, - { time: '08.11.2017, 22:47:16', version: '2.6.6' }, + { time: '12/14/2017 3:43:27 PM', version: '2.7.1' }, + { time: '12/05/2017 11:25:06 PM', version: '2.7.0' }, + { time: '11/08/2017 10:47:16 PM', version: '2.6.6' }, ]; expect(getRecentReleases(time)).toEqual(result); expect(getRecentReleases()).toEqual([]); diff --git a/src/utils/package.ts b/src/utils/package.ts index a0617d3..567b53e 100644 --- a/src/utils/package.ts +++ b/src/utils/package.ts @@ -5,12 +5,14 @@ import { UpLinks } from '@verdaccio/types'; import isString from 'lodash/isString'; import dayjs from 'dayjs'; import relativeTime from 'dayjs/plugin/relativeTime'; +import localizedFormat from 'dayjs/plugin/localizedFormat'; import { Time } from '../../types/packageMeta'; -export const TIMEFORMAT = 'DD.MM.YYYY, HH:mm:ss'; +export const TIMEFORMAT = 'L LTS'; dayjs.extend(relativeTime); +dayjs.extend(localizedFormat); /** * Formats license field for webui.