mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-23 17:40:35 +03:00
fix: fix the selectTime 'am' and 'pm'
This commit is contained in:
@@ -63,6 +63,7 @@
|
|||||||
:time-picker-options="timePickerOptions"
|
:time-picker-options="timePickerOptions"
|
||||||
:value="value"
|
:value="value"
|
||||||
:disabled-time="isDisabledTime"
|
:disabled-time="isDisabledTime"
|
||||||
|
:time-type="timeType"
|
||||||
@select="selectTime" />
|
@select="selectTime" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -162,6 +163,11 @@ export default {
|
|||||||
this.calendarMonth = now.getMonth()
|
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 () {
|
timeHeader () {
|
||||||
if (this.type === 'time') {
|
if (this.type === 'time') {
|
||||||
return this.$parent.format
|
return this.$parent.format
|
||||||
|
|||||||
+2
-1
@@ -15,6 +15,7 @@ export default {
|
|||||||
validator: val => val >= 0 && val <= 60
|
validator: val => val >= 0 && val <= 60
|
||||||
},
|
},
|
||||||
value: null,
|
value: null,
|
||||||
|
timeType: Array,
|
||||||
disabledTime: Function
|
disabledTime: Function
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -64,7 +65,7 @@ export default {
|
|||||||
}
|
}
|
||||||
result.push({
|
result.push({
|
||||||
value,
|
value,
|
||||||
label: formatTime(value)
|
label: formatTime(value, ...this.timeType)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -38,14 +38,18 @@ export function parseTime (time) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatTime (time, type = '24') {
|
export function formatTime (time, type = '24', a = 'a') {
|
||||||
let hours = time.hours
|
let hours = time.hours
|
||||||
hours = (type === '24') ? hours : (hours % 12 || 12)
|
hours = (type === '24') ? hours : (hours % 12 || 12)
|
||||||
hours = hours < 10 ? '0' + hours : hours
|
hours = hours < 10 ? '0' + hours : hours
|
||||||
let minutes = time.minutes < 10 ? '0' + time.minutes : time.minutes
|
let minutes = time.minutes < 10 ? '0' + time.minutes : time.minutes
|
||||||
let result = hours + ':' + minutes
|
let result = hours + ':' + minutes
|
||||||
if (type === '12') {
|
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
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user