CSR-1417
remove getFullDayName and getFullMonthName from date-helper and use from schedule helper
This commit is contained in:
parent
c6916d51fb
commit
bd7be85511
4 changed files with 12 additions and 45 deletions
|
|
@ -7,22 +7,6 @@ export function getDateDifferenceInDays(startDate, endDate) {
|
||||||
// Convert milliseconds to days and return the result
|
// Convert milliseconds to days and return the result
|
||||||
return difference / (1000 * 3600 * 24);
|
return difference / (1000 * 3600 * 24);
|
||||||
}
|
}
|
||||||
export function getFullDayName(date) {
|
|
||||||
// Use a ternary operator to check if the input is a valid date object
|
|
||||||
return date instanceof Date
|
|
||||||
? // Use the built-in method toLocaleDateString() to get the full day name in the current locale
|
|
||||||
date.toLocaleDateString(undefined, { weekday: "long" })
|
|
||||||
: // Return undefined if the input is not a valid date object
|
|
||||||
undefined;
|
|
||||||
}
|
|
||||||
export function getFullMonthName(date) {
|
|
||||||
// Use a ternary operator to check if the input is a valid date object
|
|
||||||
return date instanceof Date
|
|
||||||
? // Use the built-in method toLocaleDateString() to get the full month name in the current locale
|
|
||||||
date.toLocaleDateString(undefined, { month: "long" })
|
|
||||||
: // Return undefined if the input is not a valid date object
|
|
||||||
undefined;
|
|
||||||
}
|
|
||||||
export function get12HourTimeFormat(time) {
|
export function get12HourTimeFormat(time) {
|
||||||
// Check correct time format and split into components
|
// Check correct time format and split into components
|
||||||
time = time.toString().match(/^([01]\d|2[0-3])(:)([0-5]\d)?$/) || [time];
|
time = time.toString().match(/^([01]\d|2[0-3])(:)([0-5]\d)?$/) || [time];
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import {
|
import {
|
||||||
getFullDayName,
|
|
||||||
getFullMonthName,
|
|
||||||
get12HourTimeFormat,
|
get12HourTimeFormat,
|
||||||
get12HourTimeMobileFormat,
|
get12HourTimeMobileFormat,
|
||||||
getDateFormat,
|
getDateFormat,
|
||||||
|
|
@ -49,22 +47,6 @@ describe("date-helper.js", () => {
|
||||||
expect(result).toEqual(testCase.expected);
|
expect(result).toEqual(testCase.expected);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
it("getFullMonthName should return full month format.", () => {
|
|
||||||
// Arrange / Act
|
|
||||||
const date = new Date("2023-10-01");
|
|
||||||
const monthName = getFullMonthName(date);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(monthName).toEqual("October");
|
|
||||||
});
|
|
||||||
it("getFullDayName should return full Day Name format.", () => {
|
|
||||||
// Arrange / Act
|
|
||||||
const date = new Date("2023-10-01");
|
|
||||||
const dayName = getFullDayName(date);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(dayName).toEqual("Sunday");
|
|
||||||
});
|
|
||||||
it("getDateFormat should return date in the given format.", () => {
|
it("getDateFormat should return date in the given format.", () => {
|
||||||
// Arrange / Act
|
// Arrange / Act
|
||||||
const date = new Date("2023-10-01");
|
const date = new Date("2023-10-01");
|
||||||
|
|
@ -74,6 +56,7 @@ describe("date-helper.js", () => {
|
||||||
// Assert
|
// Assert
|
||||||
expect(formattedDate).toEqual("2023-10-01");
|
expect(formattedDate).toEqual("2023-10-01");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return the correct difference in days", function () {
|
it("should return the correct difference in days", function () {
|
||||||
// Define some sample dates and their expected differences
|
// Define some sample dates and their expected differences
|
||||||
const testCases = [
|
const testCases = [
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ export default {
|
||||||
serviceType() {
|
serviceType() {
|
||||||
const isRepair = store.getters.order.damage.isRepair;
|
const isRepair = store.getters.order.damage.isRepair;
|
||||||
const funnelHasRecalibrationPart = store.getters.funnelHasRecalibrationPart;
|
const funnelHasRecalibrationPart = store.getters.funnelHasRecalibrationPart;
|
||||||
if (isRepair) {
|
if (!isRepair) {
|
||||||
if (funnelHasRecalibrationPart) {
|
if (funnelHasRecalibrationPart) {
|
||||||
return "replacement and recalibration";
|
return "replacement and recalibration";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -55,15 +55,11 @@ import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
||||||
import { AppointmentTypeStrings } from "@/constants/schedule-constants";
|
import { AppointmentTypeStrings } from "@/constants/schedule-constants";
|
||||||
import { settleAllPromises } from "@/helpers/layout-helper";
|
import { settleAllPromises } from "@/helpers/layout-helper";
|
||||||
import { applicationConfig } from "@/constants/application-config.js";
|
import { applicationConfig } from "@/constants/application-config.js";
|
||||||
|
import { convertDateStringToDate } from "@/layouts/schedule/helpers/schedule-helper";
|
||||||
import { Form } from "vee-validate";
|
import { Form } from "vee-validate";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
|
|
||||||
import {
|
import { get12HourTimeFormat, get12HourTimeMobileFormat } from "@/helpers/date-helper";
|
||||||
getFullDayName,
|
|
||||||
getFullMonthName,
|
|
||||||
get12HourTimeFormat,
|
|
||||||
get12HourTimeMobileFormat,
|
|
||||||
} from "@/helpers/date-helper";
|
|
||||||
export default {
|
export default {
|
||||||
name: "confirmation",
|
name: "confirmation",
|
||||||
async beforeRouteEnter(to, from, next) {
|
async beforeRouteEnter(to, from, next) {
|
||||||
|
|
@ -174,10 +170,14 @@ export default {
|
||||||
return `${this.ProviderAddress},<br/> ${this.ProviderCity}, ${this.ProviderState} ${this.ProviderZipCode}`;
|
return `${this.ProviderAddress},<br/> ${this.ProviderCity}, ${this.ProviderState} ${this.ProviderZipCode}`;
|
||||||
},
|
},
|
||||||
ScheduleDateFormatted() {
|
ScheduleDateFormatted() {
|
||||||
const scheduleDate = new Date(this.ScheduleDate);
|
// This conversion ensures we don't get get GMT induced date changes
|
||||||
return `${getFullDayName(scheduleDate)}, ${getFullMonthName(
|
const dateObject = convertDateStringToDate(this.ScheduleDate);
|
||||||
scheduleDate
|
// Ex: Tuesday, April 22
|
||||||
)} ${scheduleDate.getDate()}`;
|
return dateObject.toLocaleDateString("en-us", {
|
||||||
|
weekday: "long",
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
});
|
||||||
},
|
},
|
||||||
ScheduleTimeFormatted() {
|
ScheduleTimeFormatted() {
|
||||||
if (this.AppointmentType == AppointmentTypeStrings.MOBILE) {
|
if (this.AppointmentType == AppointmentTypeStrings.MOBILE) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue