From 950c321b25091ef31b130b83674478974590d7f3 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Thu, 29 Jun 2017 11:22:12 +0800 Subject: [PATCH] fix: should generate showHour from format `k` --- components/date-picker/demo/time.md | 4 ++-- components/date-picker/wrapPicker.tsx | 5 ++--- components/time-picker/index.tsx | 17 ++++++++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/components/date-picker/demo/time.md b/components/date-picker/demo/time.md index 91a857cb03..1e02d1db6e 100644 --- a/components/date-picker/demo/time.md +++ b/components/date-picker/demo/time.md @@ -37,8 +37,8 @@ ReactDOM.render( />
= 0, - showMinute: timeFormat.indexOf('mm') >= 0, - showHour: timeFormat.indexOf('HH') >= 0, use12Hours: (props.showTime && props.showTime.use12Hours), }; const columns = getColumns(rcTimePickerProps); diff --git a/components/time-picker/index.tsx b/components/time-picker/index.tsx index 84e3329ae7..35b999059a 100644 --- a/components/time-picker/index.tsx +++ b/components/time-picker/index.tsx @@ -6,6 +6,19 @@ import assign from 'object-assign'; import injectLocale from '../locale-provider/injectLocale'; import defaultLocale from './locale/zh_CN'; +export function generateShowHourMinuteSecond(format: string) { + // Ref: http://momentjs.com/docs/#/parsing/string-format/ + return { + showHour: ( + format.indexOf('H') > -1 || + format.indexOf('h') > -1 || + format.indexOf('k') > -1 + ), + showMinute: format.indexOf('m') > -1, + showSecond: format.indexOf('s') > -1, + }; +} + export interface TimePickerProps { className?: string; size?: 'large' | 'default' | 'small'; @@ -120,9 +133,7 @@ abstract class TimePicker extends React.Component { return ( -1 || format.indexOf('h') > -1} - showMinute={format.indexOf('mm') > -1} - showSecond={format.indexOf('ss') > -1} + {...generateShowHourMinuteSecond(format)} {...props} ref={this.saveTimePicker} format={format}