fix: fix quarter variables (#2648)

This commit is contained in:
被雨水过滤的空气-Rain 2023-09-14 17:56:42 +08:00 committed by GitHub
parent feaf4cd80a
commit 34b0ce06ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -21,8 +21,11 @@ describe('parse date', () => {
it('should parse quarter', async () => { it('should parse quarter', async () => {
expectDate('2023Q1').toEqual(['2023-01-01T00:00:00.000Z', '2023-04-01T00:00:00.000Z']); 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('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('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 () => { it('should parse iso week', async () => {

View File

@ -26,10 +26,11 @@ function parseYear(value) {
} }
function parseQuarter(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 { return {
unit: 'quarter', 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'),
}; };
} }
} }