fix: should generate showHour from format k

This commit is contained in:
Benjy Cui 2017-06-29 11:22:12 +08:00
parent c79557b810
commit 950c321b25
3 changed files with 18 additions and 8 deletions

View File

@ -37,8 +37,8 @@ ReactDOM.render(
/>
<br />
<RangePicker
showTime
format="YYYY-MM-DD HH:mm:ss"
showTime={{ format: 'HH:mm' }}
format="YYYY-MM-DD HH:mm"
placeholder={['Start Time', 'End Time']}
onChange={onChange}
onOk={onOk}

View File

@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import TimePickerPanel from 'rc-time-picker/lib/Panel';
import classNames from 'classnames';
import { generateShowHourMinuteSecond } from '../time-picker';
import warning from '../_util/warning';
import { getComponentLocale } from '../_util/getLocale';
declare const require: Function;
@ -78,10 +79,8 @@ export default function wrapPicker(Picker, defaultFormat?: string): any {
const timeFormat = (props.showTime && props.showTime.format) || 'HH:mm:ss';
const rcTimePickerProps = {
...generateShowHourMinuteSecond(timeFormat),
format: timeFormat,
showSecond: timeFormat.indexOf('ss') >= 0,
showMinute: timeFormat.indexOf('mm') >= 0,
showHour: timeFormat.indexOf('HH') >= 0,
use12Hours: (props.showTime && props.showTime.use12Hours),
};
const columns = getColumns(rcTimePickerProps);

View File

@ -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<TimePickerProps, any> {
return (
<RcTimePicker
showHour={format.indexOf('HH') > -1 || format.indexOf('h') > -1}
showMinute={format.indexOf('mm') > -1}
showSecond={format.indexOf('ss') > -1}
{...generateShowHourMinuteSecond(format)}
{...props}
ref={this.saveTimePicker}
format={format}