]> git.immae.eu Git - github/fretlink/time-picker.git/blobdiff - src/Combobox.jsx
Added support for lower/uppercase of AM/PM selectors
[github/fretlink/time-picker.git] / src / Combobox.jsx
index d2c934c5388d30168db3e882c9e8f35957cb7bc5..00f122f357131ac4ada00df20594c5b62493a5a8 100644 (file)
@@ -56,15 +56,12 @@ const Combobox = React.createClass({
       value.minute(+itemValue);
     } else if (type === 'ampm') {
       if (use12Hours) {
-        if (itemValue === 'PM' && value.hour() <= 12) {
-          value.hour(value.hour() + 12);
+        if (itemValue === '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 (value.hour() >= 12) {
             value.hour(value.hour() - 12);
           }
         }
@@ -148,11 +145,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 (