]> git.immae.eu Git - github/fretlink/time-picker.git/blobdiff - src/Combobox.jsx
Merge branch 'shaleynikov-master'
[github/fretlink/time-picker.git] / src / Combobox.jsx
index d2c934c5388d30168db3e882c9e8f35957cb7bc5..36b61cca13712b78fe33f1977823daa8d5d5c815 100644 (file)
@@ -55,16 +55,14 @@ const Combobox = React.createClass({
     } else if (type === 'minute') {
       value.minute(+itemValue);
     } else if (type === 'ampm') {
+      const ampm = itemValue.toUpperCase();
       if (use12Hours) {
-        if (itemValue === 'PM' && value.hour() <= 12) {
-          value.hour(value.hour() + 12);
+        if (ampm === 'PM' && value.hour() < 12) {
+          value.hour((value.hour() % 12) + 12);
         }
 
-        if (itemValue === 'AM') {
-          if (!value.hour()) {
-            value.hour(12);
-          } else
-          if (value.hour() > 12) {
+        if (ampm === 'AM') {
+          if (value.hour() >= 12) {
             value.hour(value.hour() - 12);
           }
         }
@@ -148,11 +146,15 @@ const Combobox = React.createClass({
   },
 
   getAMPMSelect() {
-    const { prefixCls, use12Hours } = this.props;
+    const { prefixCls, use12Hours, format } = this.props;
     if (!use12Hours) {
       return null;
     }
-    const AMPMOptions = [{ value: 'AM' }, { value: 'PM' }];
+
+    const AMPMOptions = ['am', 'pm'] // If format has A char, then we should uppercase AM/PM
+                          .map(c => format.match(/\sA/) ? c.toUpperCase() : c)
+                          .map(c => ({ value: c }));
+
     const selected = this.isAM() ? 0 : 1;
 
     return (