aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Combobox.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Combobox.jsx')
-rw-r--r--src/Combobox.jsx32
1 files changed, 14 insertions, 18 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;