Skip to content

Commit

Permalink
fix: fix the selectTime 'am' and 'pm'
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 committed Sep 8, 2018
1 parent e0776b6 commit 8e475b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
:time-picker-options="timePickerOptions"
:value="value"
:disabled-time="isDisabledTime"
:time-type="timeType"
@select="selectTime" />
</div>
</div>
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/panel/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {
validator: val => val >= 0 && val <= 60
},
value: null,
timeType: Array,
disabledTime: Function
},
computed: {
Expand Down Expand Up @@ -64,7 +65,7 @@ export default {
}
result.push({
value,
label: formatTime(value)
label: formatTime(value, ...this.timeType)
})
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8e475b3

Please sign in to comment.