From 6358fbbe968e6a158f9dafba65083c992c66bdb4 Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Thu, 25 May 2023 10:42:41 -0400 Subject: [PATCH] CSR-1149 | Fix AM/PM Bug and Formatting --- src/layouts/schedule/schedule.vue | 37 ++++++++++++------- .../time-slot-modal-question.vue | 14 +++++-- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/layouts/schedule/schedule.vue b/src/layouts/schedule/schedule.vue index 540e7a955..b43be23ad 100644 --- a/src/layouts/schedule/schedule.vue +++ b/src/layouts/schedule/schedule.vue @@ -272,16 +272,28 @@ export default { if (!timeSlotData.id) { funnelFooterButtonText = "Continue"; } else { - funnelFooterButtonText = "Select " + this.convertSelectedDateToShortMonthAndDay(this.selectedDate); - + funnelFooterButtonText = + "Select " + this.convertSelectedDateToShortMonthAndDay(this.selectedDate); + if (this.appointmentType === AppointmentTypeStrings.IN_SHOP) { - funnelFooterButtonText += " at " + this.getDisplayTextForMilitaryTime(this.appointmentDateAndTime.startTime); - } else if (this.appointmentType === AppointmentTypeStrings.MOBILE && !timeSlotData.isPremiumAppointment) { funnelFooterButtonText += - " at " + - this.getDisplayTextForMilitaryTime(this.appointmentDateAndTime.startTime, true) + - " - " + - this.getDisplayTextForMilitaryTime(this.appointmentDateAndTime.endTime, true); + " at " + + this.getDisplayTextForMilitaryTime(this.appointmentDateAndTime.startTime); + } else if ( + this.appointmentType === AppointmentTypeStrings.MOBILE && + !timeSlotData.isPremiumAppointment + ) { + funnelFooterButtonText += + " at " + + this.getDisplayTextForMilitaryTime( + this.appointmentDateAndTime.startTime, + true + ) + + " - " + + this.getDisplayTextForMilitaryTime( + this.appointmentDateAndTime.endTime, + true + ); } } @@ -290,16 +302,15 @@ export default { convertSelectedDateToShortMonthAndDay(selectedDate) { // This conversion ensures we don't get get GMT induced date changes const dateObject = new Date(`${selectedDate.dateString}T00:00:00`); - return dateObject.toLocaleDateString("en-us", {month:"short", day:"numeric"}); + return dateObject.toLocaleDateString("en-us", { month: "short", day: "numeric" }); }, // Expected input: "HH:MM:SS" getDisplayTextForMilitaryTime(militaryTimeInput, shouldTrimMinutesIfEmpty = false) { let hours = parseInt(militaryTimeInput.split(":")[0]); const minutes = militaryTimeInput.split(":")[1]; - let meridianNotation = "AM"; - if (militaryTimeInput.split(":")[0] > 12) { + let meridianNotation = hours > 11 ? "PM" : "AM"; + if (hours > 12) { hours -= 12; - meridianNotation = "PM"; } if (shouldTrimMinutesIfEmpty && minutes === "00") { return `${hours} ${meridianNotation}`; @@ -338,7 +349,7 @@ export default { }, selectedTimeSlotData() { this.updateFooterButtonText(this.selectedTimeSlotData); - } + }, }, components: { funnelHeader, diff --git a/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.vue b/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.vue index f6f85ccae..bcfd56bb3 100644 --- a/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.vue +++ b/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.vue @@ -253,10 +253,9 @@ export default { getDisplayTextForMilitaryTime(militaryTimeInput) { let hours = parseInt(militaryTimeInput.split(":")[0]); const minutes = militaryTimeInput.split(":")[1]; - let meridianNotation = "AM"; - if (militaryTimeInput.split(":")[0] > 12) { + let meridianNotation = hours > 11 ? "PM" : "AM"; + if (hours > 12) { hours -= 12; - meridianNotation = "PM"; } return `${hours}:${minutes} ${meridianNotation}`; }, @@ -273,7 +272,14 @@ export default { }, autoSelectTimeSlotIfOnlyOneIsAvailable(newdateAndTimeSlotDataValue) { const numberOfOptions = newdateAndTimeSlotDataValue?.timeSlots.length; - if (numberOfOptions === 1 && !(this.appointmentType === AppointmentTypeStrings.MOBILE && this.premiumAppointmentFee && newdateAndTimeSlotDataValue.timeSlots[0].offerPremium)) { + if ( + numberOfOptions === 1 && + !( + this.appointmentType === AppointmentTypeStrings.MOBILE && + this.premiumAppointmentFee && + newdateAndTimeSlotDataValue.timeSlots[0].offerPremium + ) + ) { this.selectedTimeSlotId = newdateAndTimeSlotDataValue.timeSlots[0].id; } },