Skip to content

Commit

Permalink
Added parseTime method to Calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Aug 21, 2019
1 parent 4f8676d commit 047c1c5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/components/calendar/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ export default {
}
this.updateModel(value);
this.updateInputFieldValue(value);
this.$emit('select', value);
},
toggleAMPM(event) {
Expand Down Expand Up @@ -1315,6 +1316,29 @@ export default {
value.setMinutes(time.minute);
value.setSeconds(time.second);
},
parseTime(value) {
let tokens = value.split(':');
let validTokenLength = this.showSeconds ? 3 : 2;
if (tokens.length !== validTokenLength) {
throw "Invalid time";
}
let h = parseInt(tokens[0]);
let m = parseInt(tokens[1]);
let s = this.showSeconds ? parseInt(tokens[2]) : null;
if (isNaN(h) || isNaN(m) || h > 23 || m > 59 || (this.hourFormat == '12' && h > 12) || (this.showSeconds && (isNaN(s) || s > 59))) {
throw "Invalid time";
}
else {
if (this.hourFormat == '12' && h !== 12 && this.pm) {
h+= 12;
}
return {hour: h, minute: m, second: s};
}
},
parseDate(value, format) {
if (format == null || value == null) {
throw "Invalid arguments";
Expand Down

0 comments on commit 047c1c5

Please sign in to comment.