Skip to content

Commit

Permalink
fix: time format only support HH:mm:ss (#1924)
Browse files Browse the repository at this point in the history
* fix: time format only support HH:mm:ss

* chore: add test unit
  • Loading branch information
myronliu347 authored Sep 15, 2024
1 parent 056e162 commit 562f93e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions js/date-picker/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ export function flagActive(data: any[], { ...args }: any) {

// extract time format from a completed date format 'YYYY-MM-DD HH:mm' -> 'HH:mm'
export function extractTimeFormat(dateFormat: string = '') {
const res = dateFormat.match(/(a\s)?h{1,2}(:m{1,2})?(:s{1,2})?(\sa)?/i);
if (!res) return null;
return res[0];
return dateFormat
.replace(/\W?Y{2,4}|\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
.trim();
}

/**
Expand Down
20 changes: 20 additions & 0 deletions test/unit/date-picker/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { extractTimeFormat } from '../../../js/date-picker/utils';

describe('utils', () => {
describe(' extractTimeFormat', () => {
it('YYYY-MM-DD HH:mm:ss', () => {
const res = extractTimeFormat('YYYY-MM-DD HH:mm:ss');
expect(res).toBe('HH:mm:ss');
});

it('YYYY-MM-DD HH时mm分ss秒', () => {
const res = extractTimeFormat('YYYY-MM-DD HH时mm分ss秒');
expect(res).toBe('HH时mm分ss秒');
});

it('YYYY-MM-DD HH时mm分ss秒SSS毫秒', () => {
const res = extractTimeFormat('YYYY-MM-DD HH时mm分ss秒SSS毫秒');
expect(res).toBe('HH时mm分ss秒SSS毫秒');
});
});
});

0 comments on commit 562f93e

Please sign in to comment.