diff --git a/components/date-picker/__tests__/__snapshots__/demo.test.js.snap b/components/date-picker/__tests__/__snapshots__/demo.test.js.snap index d586dcfe6d909d5a6fdadabc12edabbff645b5c6..9e2a09d1ee7caa58342f8ef64b37f82702bf2833 100644 --- a/components/date-picker/__tests__/__snapshots__/demo.test.js.snap +++ b/components/date-picker/__tests__/__snapshots__/demo.test.js.snap @@ -2011,6 +2011,7 @@ exports[`renders ./components/date-picker/demo/format.md correctly 1`] = `
+
+
+
+ + + + + + + + + + + +
+
+
`; diff --git a/components/date-picker/demo/format.md b/components/date-picker/demo/format.md index 84489a07ec92d63ab96c620b2c9e0c14a98f95bd..dbad230d8478c5099adb44e0c90b4eef2e5bf29e 100644 --- a/components/date-picker/demo/format.md +++ b/components/date-picker/demo/format.md @@ -24,6 +24,10 @@ const monthFormat = 'YYYY/MM'; const dateFormatList = ['DD/MM/YYYY', 'DD/MM/YY']; +const customFormat = value => { + return `custom format: ${value.format(dateFormat)}`; +}; + ReactDOM.render( @@ -33,6 +37,7 @@ ReactDOM.render( defaultValue={[moment('2015/01/01', dateFormat), moment('2015/01/01', dateFormat)]} format={dateFormat} /> + , mountNode, ); diff --git a/components/date-picker/generatePicker/index.tsx b/components/date-picker/generatePicker/index.tsx index 0e97e3fe84b1d605582138eecbcabded4b3e1550..c0768780c4d1e833e9f33f445579b18ed56f3a37 100644 --- a/components/date-picker/generatePicker/index.tsx +++ b/components/date-picker/generatePicker/index.tsx @@ -36,7 +36,7 @@ export function getTimeProps( const firstFormat = toArray(format)[0]; const showTimeObj: SharedTimeProps = { ...props }; - if (firstFormat) { + if (firstFormat && typeof firstFormat === 'string') { if (!firstFormat.includes('s') && showSecond === undefined) { showTimeObj.showSecond = false; } diff --git a/components/date-picker/index.en-US.md b/components/date-picker/index.en-US.md index 64f17e28038d531e19cfbc1fea874f6d41e5c7ae..bc5f6b0493b45d7d12b0355ed4019592e5d80ad5 100644 --- a/components/date-picker/index.en-US.md +++ b/components/date-picker/index.en-US.md @@ -89,7 +89,7 @@ The following APIs are shared by DatePicker, RangePicker. | defaultValue | To set default date, if start time or end time is null or undefined, the date range will be an open interval | [moment](http://momentjs.com/) | - | | | defaultPickerValue | To set default picker date | [moment](http://momentjs.com/) | - | | | disabledTime | To specify the time that cannot be selected | function(date) | - | | -| format | To set the date format, refer to [moment.js](http://momentjs.com/). When an array is provided, all values are used for parsing and first value is used for formatting | string \| string[] | `YYYY-MM-DD` | | +| format | To set the date format, refer to [moment.js](http://momentjs.com/). When an array is provided, all values are used for parsing and first value is used for formatting, support [Custom Format](#components-date-picker-demo-format) | string \| (value: moment) => string \| (string \| (value: moment) => string)[] | `YYYY-MM-DD` | | | renderExtraFooter | Render extra footer in panel | (mode) => React.ReactNode | - | | | showTime | To provide an additional time selection | object \| boolean | [TimePicker Options](/components/time-picker/#API) | | | showTime.defaultValue | To set default time of selected date, [demo](#components-date-picker-demo-disabled-date) | [moment](http://momentjs.com/) | moment() | | diff --git a/components/date-picker/index.zh-CN.md b/components/date-picker/index.zh-CN.md index aad5d41c72515dc90f743fbc011345283e4e9418..8f6a50dfa4600ade7c89828eb5425e9144c4342a 100644 --- a/components/date-picker/index.zh-CN.md +++ b/components/date-picker/index.zh-CN.md @@ -90,7 +90,7 @@ import locale from 'antd/es/locale/zh_CN'; | defaultValue | 默认日期,如果开始时间或结束时间为 `null` 或者 `undefined`,日期范围将是一个开区间 | [moment](http://momentjs.com/) | - | | | defaultPickerValue | 默认面板日期 | [moment](http://momentjs.com/) | - | | | disabledTime | 不可选择的时间 | function(date) | - | | -| format | 设置日期格式,为数组时支持多格式匹配,展示以第一个为准。配置参考 [moment.js](http://momentjs.com/) | string \| string[] | `YYYY-MM-DD` | | +| format | 设置日期格式,为数组时支持多格式匹配,展示以第一个为准。配置参考 [moment.js](http://momentjs.com/),支持[自定义格式](#components-date-picker-demo-format) | string \| (value: moment) => string \| (string \| (value: moment) => string)[] | `YYYY-MM-DD` | | | renderExtraFooter | 在面板中添加额外的页脚 | (mode) => React.ReactNode | - | | | showTime | 增加时间选择功能 | Object \| boolean | [TimePicker Options](/components/time-picker/#API) | | | showTime.defaultValue | 设置用户选择日期时默认的时分秒,[例子](#components-date-picker-demo-disabled-date) | [moment](http://momentjs.com/) | moment() | | diff --git a/package.json b/package.json index f621bfdddf4dac9fe8bfea1b6580fb65c4e382eb..e6768007985b261491884d8cd3be9d2963f1ac04 100644 --- a/package.json +++ b/package.json @@ -132,7 +132,7 @@ "rc-motion": "^2.0.0", "rc-notification": "~4.4.0", "rc-pagination": "~3.0.3", - "rc-picker": "~2.1.0", + "rc-picker": "~2.2.1", "rc-progress": "~3.1.0", "rc-rate": "~2.8.2", "rc-resize-observer": "^0.2.3",