2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-09 17:32:27 +03:00

fix: fix the selectTime 'am' and 'pm'

This commit is contained in:
mxie
2018-09-08 12:04:08 +08:00
parent e0776b6c83
commit 8e475b39a1
3 changed files with 14 additions and 3 deletions
+6
View File
@@ -63,6 +63,7 @@
:time-picker-options="timePickerOptions"
:value="value"
:disabled-time="isDisabledTime"
:time-type="timeType"
@select="selectTime" />
</div>
</div>
@@ -162,6 +163,11 @@ export default {
this.calendarMonth = now.getMonth()
}
},
timeType () {
const h = /h+/.test(this.$parent.format) ? '12' : '24'
const a = /A/.test(this.$parent.format) ? 'A' : 'a'
return [h, a]
},
timeHeader () {
if (this.type === 'time') {
return this.$parent.format
+2 -1
View File
@@ -15,6 +15,7 @@ export default {
validator: val => val >= 0 && val <= 60
},
value: null,
timeType: Array,
disabledTime: Function
},
computed: {
@@ -64,7 +65,7 @@ export default {
}
result.push({
value,
label: formatTime(value)
label: formatTime(value, ...this.timeType)
})
}
}
+6 -2
View File
@@ -38,14 +38,18 @@ export function parseTime (time) {
return null
}
export function formatTime (time, type = '24') {
export function formatTime (time, type = '24', a = 'a') {
let hours = time.hours
hours = (type === '24') ? hours : (hours % 12 || 12)
hours = hours < 10 ? '0' + hours : hours
let minutes = time.minutes < 10 ? '0' + time.minutes : time.minutes
let result = hours + ':' + minutes
if (type === '12') {
result += time.hours >= 12 ? ' pm' : ' am'
let suffix = time.hours >= 12 ? 'pm' : 'am'
if (a === 'A') {
suffix = suffix.toUpperCase()
}
result = `${result} ${suffix}`
}
return result
}