From 34b0ce06ba4841e2bd86270b45795b351b6f6a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com> Date: Thu, 14 Sep 2023 17:56:42 +0800 Subject: [PATCH] fix: fix quarter variables (#2648) --- packages/core/utils/src/__tests__/parse-date.test.ts | 3 +++ packages/core/utils/src/parse-date.ts | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/utils/src/__tests__/parse-date.test.ts b/packages/core/utils/src/__tests__/parse-date.test.ts index 2cf1f5b2e..7965e30b8 100644 --- a/packages/core/utils/src/__tests__/parse-date.test.ts +++ b/packages/core/utils/src/__tests__/parse-date.test.ts @@ -21,8 +21,11 @@ describe('parse date', () => { it('should parse quarter', async () => { expectDate('2023Q1').toEqual(['2023-01-01T00:00:00.000Z', '2023-04-01T00:00:00.000Z']); + expectDate('2023Q2').toEqual(['2023-04-01T00:00:00.000Z', '2023-07-01T00:00:00.000Z']); expectDate('2023Q1+08:00').toEqual(['2022-12-31T16:00:00.000Z', '2023-03-31T16:00:00.000Z']); + expectDate('2023Q2+08:00').toEqual(['2023-03-31T16:00:00.000Z', '2023-06-30T16:00:00.000Z']); expectDate('2023Q1', { timezone: '+08:00' }).toEqual(['2022-12-31T16:00:00.000Z', '2023-03-31T16:00:00.000Z']); + expectDate('2023Q2', { timezone: '+08:00' }).toEqual(['2023-03-31T16:00:00.000Z', '2023-06-30T16:00:00.000Z']); }); it('should parse iso week', async () => { diff --git a/packages/core/utils/src/parse-date.ts b/packages/core/utils/src/parse-date.ts index 99aea68af..2a9171575 100644 --- a/packages/core/utils/src/parse-date.ts +++ b/packages/core/utils/src/parse-date.ts @@ -26,10 +26,11 @@ function parseYear(value) { } function parseQuarter(value) { - if (/^\d\d\d\d\Q\d$/.test(value)) { + if (/^\d\d\d\dQ\d$/.test(value)) { + const [year, q] = value.split('Q'); return { unit: 'quarter', - start: dayjs(value, 'YYYY[Q]Q').format('YYYY-MM-DD HH:mm:ss'), + start: dayjs(year, 'YYYY').quarter(q).format('YYYY-MM-DD HH:mm:ss'), }; } }