Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export default () => {
<Picker<Moment>
{...sharedProps}
locale={zhCN}
format="YYYY-Wo"
allowClear
picker="week"
renderExtraFooter={() => 'I am footer!!!'}
Expand All @@ -105,7 +104,7 @@ export default () => {
<h3>Week</h3>
<Picker<Moment>
generateConfig={momentGenerateConfig}
locale={zhCN}
locale={enUS}
picker="week"
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion examples/rtl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default () => {
<Picker<Moment>
{...sharedProps}
locale={zhCN}
format="YYYY-Wo"
format="gggg-Wo"
allowClear
picker="week"
renderExtraFooter={() => 'I am footer!!!'}
Expand Down
7 changes: 4 additions & 3 deletions src/generate/moment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ const generateConfig: GenerateConfig<Moment> = {
let format = formats[i];
let formatText = text;

if (format.includes('o')) {
const matchFormat = format.match(/[YyMmDdHhSsWw]+/g);
const matchText = formatText.match(/\d+/g);
if (format.includes('wo') || format.includes('Wo')) {
format = format.replace(/wo/g, 'ww').replace(/Wo/g, 'WW');
const matchFormat = format.match(/[-YyMmDdHhSsWwGg]+/g);
const matchText = formatText.match(/[-\d]+/g);

if (matchFormat && matchText) {
format = matchFormat.join('');
Expand Down
2 changes: 1 addition & 1 deletion src/utils/uiUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export function getDefaultFormat(
break;

case 'week':
mergedFormat = 'YYYY-Wo';
mergedFormat = 'gggg-wo';
break;

case 'month':
Expand Down
14 changes: 12 additions & 2 deletions tests/picker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,16 @@ describe('Picker.Basic', () => {
name: 'basic',
value: '2000-11-11',
selected: '.rc-picker-cell-selected',
matchDate: '2000-11-11',
},
{
name: 'week',
picker: 'week',
value: '2000-45th',
matchDate: '2000-10-29',
selected: '.rc-picker-week-panel-row-selected',
},
].forEach(({ name, picker, value, selected }) => {
].forEach(({ name, picker, value, matchDate, selected }) => {
it(name, () => {
const onChange = jest.fn();
const wrapper = mount(
Expand Down Expand Up @@ -226,7 +228,7 @@ describe('Picker.Basic', () => {
expect(onChange).not.toHaveBeenCalled();
wrapper.keyDown(KeyCode.ENTER);
expect(
isSame(onChange.mock.calls[0][0], '2000-11-11', picker as any),
isSame(onChange.mock.calls[0][0], matchDate, picker as any),
).toBeTruthy();
expect(wrapper.find(selected).length).toBeTruthy();
onChange.mockReset();
Expand Down Expand Up @@ -528,4 +530,12 @@ describe('Picker.Basic', () => {
const wrapper = mount(<MomentPicker direction="rtl" allowClear />);
expect(wrapper.render()).toMatchSnapshot();
});

it('week picker show correct year', () => {
const wrapper = mount(
<MomentPicker value={getMoment('2019-12-31')} picker="week" />,
);

expect(wrapper.find('input').prop('value')).toEqual('2020-1st');
});
});