diff --git a/packages/date-picker/src/basic/time-spinner.vue b/packages/date-picker/src/basic/time-spinner.vue
index fd5a680fa..8c3612536 100644
--- a/packages/date-picker/src/basic/time-spinner.vue
+++ b/packages/date-picker/src/basic/time-spinner.vue
@@ -13,9 +13,8 @@
- {{ hour === undefined ? '' : ('0' + hour).slice(-2) }}
-
+ v-for="hour in arrowHourList">{{ hour === undefined ? '' : ('0' + (amPmMode ? (hour % 12 || 12) : hour )).slice(-2) + amPm(hour) }}
this.maxDate.getTime();
+ },
+ amPmMode() {
+ if ((this.format || '').indexOf('A') !== -1) return 'A';
+ if ((this.format || '').indexOf('a') !== -1) return 'a';
+ return '';
}
},
diff --git a/packages/date-picker/src/panel/time.vue b/packages/date-picker/src/panel/time.vue
index fc4cc0914..e5bef1f81 100644
--- a/packages/date-picker/src/panel/time.vue
+++ b/packages/date-picker/src/panel/time.vue
@@ -10,6 +10,7 @@
@change="handleChange"
:arrow-control="useArrow"
:show-seconds="showSeconds"
+ :am-pm-mode="amPmMode"
@select-range="setSelectionRange"
:date="date">
@@ -104,6 +105,11 @@
},
useArrow() {
return this.arrowControl || this.timeArrowControl || false;
+ },
+ amPmMode() {
+ if ((this.format || '').indexOf('A') !== -1) return 'A';
+ if ((this.format || '').indexOf('a') !== -1) return 'a';
+ return '';
}
},
diff --git a/test/unit/specs/time-picker.spec.js b/test/unit/specs/time-picker.spec.js
index c4fb073fb..e635928d7 100644
--- a/test/unit/specs/time-picker.spec.js
+++ b/test/unit/specs/time-picker.spec.js
@@ -26,6 +26,30 @@ describe('TimePicker', () => {
expect(vm.$el.querySelector('input').value).to.equal('18-40-00');
});
+ it('set AM/PM format', done => {
+ vm = createTest(TimePicker, {
+ format: 'hh:mm:ss A',
+ value: new Date(2016, 9, 10, 18, 40)
+ }, true);
+
+ const input = vm.$el.querySelector('input');
+
+ expect(vm.$el.querySelector('input').value).to.equal('06:40:00 PM');
+
+ input.blur();
+ input.focus();
+
+ setTimeout(_ => {
+ const list = vm.picker.$el.querySelectorAll('.el-time-spinner__list');
+ const hoursEl = list[0];
+ expect(hoursEl.querySelectorAll('.el-time-spinner__item')[0].textContent).to.equal('12 AM');
+ expect(hoursEl.querySelectorAll('.el-time-spinner__item')[1].textContent).to.equal('01 AM');
+ expect(hoursEl.querySelectorAll('.el-time-spinner__item')[12].textContent).to.equal('12 PM');
+ expect(hoursEl.querySelectorAll('.el-time-spinner__item')[15].textContent).to.equal('03 PM');
+ done();
+ }, DELAY);
+ });
+
it('default value', done => {
vm = createTest(TimePicker, {
value: new Date(2016, 9, 10, 18, 40)