Skip to content

Instantly share code, notes, and snippets.

@oscarcs
Created March 16, 2020 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarcs/ab910e91572dba95b2e7f2774c1654ea to your computer and use it in GitHub Desktop.
Save oscarcs/ab910e91572dba95b2e7f2774c1654ea to your computer and use it in GitHub Desktop.
{
timeChanged: function() {
this.timeHours = this.claim.Time.split(':')[0];
this.timeMinutes = this.claim.Time.split(':')[1].split(' ')[0];
this.timeOfDay = this.claim.Time.split(' ')[1];
console.log(this.timeHours, this.timeMinutes, this.timeOfDay);
},
timeEdited: function() {
let hours = parseInt(this.timeHours);
if (isNaN(hours) || hours > 12 || hours <= 0) {
if (hours > 12 && hours < 24) {
hours = hours - 12;
this.timeOfDay = 'PM';
}
else {
hours = '01';
}
}
let minutes = parseInt(this.timeMinutes);
if (isNaN(this.timeMinutes) || minutes > 59 || minutes < 0) {
minutes = '00';
}
hours.toString().padStart(2, '0');
minutes.toString().padStart(2, '0');
this.claim.Time = hours + ':' + minutes + ' ' + this.timeOfDay;
this.propertyEdited('Time');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment