diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Combobox.jsx | 32 | ||||
-rw-r--r-- | src/TimePicker.jsx | 13 |
2 files changed, 26 insertions, 19 deletions
diff --git a/src/Combobox.jsx b/src/Combobox.jsx index 339764c..d2c934c 100644 --- a/src/Combobox.jsx +++ b/src/Combobox.jsx | |||
@@ -44,10 +44,10 @@ const Combobox = React.createClass({ | |||
44 | 44 | ||
45 | if (type === 'hour') { | 45 | if (type === 'hour') { |
46 | if (use12Hours) { | 46 | if (use12Hours) { |
47 | if (value.hour() > 12 || !value.hour()) { | 47 | if (this.isAM()) { |
48 | value.hour(+itemValue + 12); | 48 | value.hour(+itemValue % 12); |
49 | } else { | 49 | } else { |
50 | value.hour(+itemValue); | 50 | value.hour((+itemValue % 12) + 12); |
51 | } | 51 | } |
52 | } else { | 52 | } else { |
53 | value.hour(+itemValue); | 53 | value.hour(+itemValue); |
@@ -85,22 +85,14 @@ const Combobox = React.createClass({ | |||
85 | return null; | 85 | return null; |
86 | } | 86 | } |
87 | const disabledOptions = disabledHours(); | 87 | const disabledOptions = disabledHours(); |
88 | let hourAdj; | ||
89 | if (use12Hours) { | ||
90 | if (hour > 12) { | ||
91 | hourAdj = hour - 12; | ||
92 | } else { | ||
93 | hourAdj = hour || 12; | ||
94 | } | ||
95 | } else { | ||
96 | hourAdj = hour; | ||
97 | } | ||
98 | |||
99 | let hourOptionsAdj; | 88 | let hourOptionsAdj; |
89 | let hourAdj; | ||
100 | if (use12Hours) { | 90 | if (use12Hours) { |
101 | hourOptionsAdj = hourOptions.filter(h => h <= 12 && h > 0); | 91 | hourOptionsAdj = [12].concat(hourOptions.filter(h => h < 12 && h > 0)); |
92 | hourAdj = (hour % 12) || 12; | ||
102 | } else { | 93 | } else { |
103 | hourOptionsAdj = hourOptions; | 94 | hourOptionsAdj = hourOptions; |
95 | hourAdj = hour; | ||
104 | } | 96 | } |
105 | 97 | ||
106 | return ( | 98 | return ( |
@@ -156,13 +148,12 @@ const Combobox = React.createClass({ | |||
156 | }, | 148 | }, |
157 | 149 | ||
158 | getAMPMSelect() { | 150 | getAMPMSelect() { |
159 | const { prefixCls, use12Hours, defaultOpenValue } = this.props; | 151 | const { prefixCls, use12Hours } = this.props; |
160 | if (!use12Hours) { | 152 | if (!use12Hours) { |
161 | return null; | 153 | return null; |
162 | } | 154 | } |
163 | const value = this.props.value || defaultOpenValue; | ||
164 | const AMPMOptions = [{ value: 'AM' }, { value: 'PM' }]; | 155 | const AMPMOptions = [{ value: 'AM' }, { value: 'PM' }]; |
165 | const selected = (!value.hour() || value.hour() > 12) ? 1 : 0; | 156 | const selected = this.isAM() ? 0 : 1; |
166 | 157 | ||
167 | return ( | 158 | return ( |
168 | <Select | 159 | <Select |
@@ -176,6 +167,11 @@ const Combobox = React.createClass({ | |||
176 | ); | 167 | ); |
177 | }, | 168 | }, |
178 | 169 | ||
170 | isAM() { | ||
171 | const { value } = this.props; | ||
172 | return value.hour() >= 0 && value.hour() < 12; | ||
173 | }, | ||
174 | |||
179 | render() { | 175 | render() { |
180 | const { prefixCls, defaultOpenValue } = this.props; | 176 | const { prefixCls, defaultOpenValue } = this.props; |
181 | const value = this.props.value || defaultOpenValue; | 177 | const value = this.props.value || defaultOpenValue; |
diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx index 6b76223..7065333 100644 --- a/src/TimePicker.jsx +++ b/src/TimePicker.jsx | |||
@@ -128,10 +128,21 @@ const Picker = React.createClass({ | |||
128 | }, | 128 | }, |
129 | 129 | ||
130 | getFormat() { | 130 | getFormat() { |
131 | const { format, showHour, showMinute, showSecond } = this.props; | 131 | const { format, showHour, showMinute, showSecond, use12Hours } = this.props; |
132 | if (format) { | 132 | if (format) { |
133 | return format; | 133 | return format; |
134 | } | 134 | } |
135 | |||
136 | if (use12Hours) { | ||
137 | const fmtString = ([ | ||
138 | showHour ? 'h' : '', | ||
139 | showMinute ? 'mm' : '', | ||
140 | showSecond ? 'ss' : '', | ||
141 | ].filter(item => !!item).join(':')); | ||
142 | |||
143 | return fmtString.concat(' a'); | ||
144 | } | ||
145 | |||
135 | return [ | 146 | return [ |
136 | showHour ? 'HH' : '', | 147 | showHour ? 'HH' : '', |
137 | showMinute ? 'mm' : '', | 148 | showMinute ? 'mm' : '', |