diff --git a/.eslintrc.json b/.eslintrc.json index f5bb0882ae..80cad90ffc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -20,7 +20,7 @@ "dist", ".next", ".turbo", - "exbamples", + "examples", "coverage", ".changeset", "playwright-report" diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index e4b37c38d7..43db3bf9f7 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -101,5 +101,8 @@ jobs: ui-test: uses: ./.github/workflows/ui_tests.yml secrets: inherit + permissions: + contents: write + pull-requests: write with: branch: ${{ github.ref }} diff --git a/packages/common/src/utils/DateUtil.ts b/packages/common/src/utils/DateUtil.ts index 52f03fe5fc..eb50bbd4d0 100644 --- a/packages/common/src/utils/DateUtil.ts +++ b/packages/common/src/utils/DateUtil.ts @@ -1,15 +1,18 @@ import dayjs from 'dayjs' -import updateLocale from 'dayjs/plugin/updateLocale.js' +import englishLocale from 'dayjs/locale/en' import relativeTime from 'dayjs/plugin/relativeTime.js' +import updateLocale from 'dayjs/plugin/updateLocale.js' dayjs.extend(relativeTime) dayjs.extend(updateLocale) -dayjs.updateLocale('en', { +const localeObject = { + ...englishLocale, + name: 'en-web3-modal', relativeTime: { future: 'in %s', past: '%s ago', - s: '%s sec', + s: '%d sec', m: '1 min', mm: '%d min', h: '1 hr', @@ -21,7 +24,9 @@ dayjs.updateLocale('en', { y: '1 yr', yy: '%d yr' } -}) +} + +dayjs.locale('en-web3-modal', localeObject) export const DateUtil = { getYear(date: string = new Date().toISOString()) { @@ -29,7 +34,7 @@ export const DateUtil = { }, getRelativeDateFromNow(date: string | number) { - return dayjs(date).fromNow(true) + return dayjs(date).locale('en-web3-modal').fromNow(true) }, formatDate(date: string | number, format = 'DD MMM') { diff --git a/packages/common/tests/DateUtil.test.ts b/packages/common/tests/DateUtil.test.ts index 57735effc8..e5ccd46357 100644 --- a/packages/common/tests/DateUtil.test.ts +++ b/packages/common/tests/DateUtil.test.ts @@ -3,6 +3,8 @@ import { DateUtil } from '../src/utils/DateUtil.js' const fakeDateTime = new Date(2023, 1, 1, 12) const fakeDateTimeOneHourAgo = new Date(2023, 1, 1, 11) +const fakeDateTimeOneTwoMinsAgo = new Date(2023, 1, 1, 12, 2) +const fakeDateTimeOneSecondAgo = new Date(2023, 1, 1, 12, 0, 30) // -- Tests -------------------------------------------------------------------- describe('DateUtil', () => { @@ -26,6 +28,18 @@ describe('DateUtil', () => { expect(DateUtil.getRelativeDateFromNow(fakeDateTimeOneHourAgo.getTime())).toEqual('1 hr') }) + it('should return relative time for minutes ago', () => { + vi.setSystemTime(fakeDateTime) + + expect(DateUtil.getRelativeDateFromNow(fakeDateTimeOneTwoMinsAgo.getTime())).toEqual('2 min') + }) + + it('should return relative time for seconds ago', () => { + vi.setSystemTime(fakeDateTime) + + expect(DateUtil.getRelativeDateFromNow(fakeDateTimeOneSecondAgo.getTime())).toEqual('30 sec') + }) + it('should format date correctly', () => { expect(DateUtil.formatDate(fakeDateTime.toDateString())).toEqual('01 Feb') })