diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ddf3599c..0c801acd 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -16,6 +16,7 @@ "http-status-codes": "^2.2.0", "lodash": "^4.17.21", "moment": "^2.29.4", + "moment-timezone": "^0.5.45", "pinia": "^2.1.6", "rfdc": "^1.3.0", "sass": "^1.66.1", @@ -3161,6 +3162,17 @@ "node": "*" } }, + "node_modules/moment-timezone": { + "version": "0.5.45", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.45.tgz", + "integrity": "sha512-HIWmqA86KcmCAhnMAN0wuDOARV/525R2+lOLotuGFzn4HO+FH+/645z2wx0Dt3iDv6/p61SIvKnDstISainhLQ==", + "dependencies": { + "moment": "^2.29.4" + }, + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -7084,6 +7096,14 @@ "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" }, + "moment-timezone": { + "version": "0.5.45", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.45.tgz", + "integrity": "sha512-HIWmqA86KcmCAhnMAN0wuDOARV/525R2+lOLotuGFzn4HO+FH+/645z2wx0Dt3iDv6/p61SIvKnDstISainhLQ==", + "requires": { + "moment": "^2.29.4" + } + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", diff --git a/frontend/package.json b/frontend/package.json index 02d31b94..5981d8b8 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -22,6 +22,7 @@ "http-status-codes": "^2.2.0", "lodash": "^4.17.21", "moment": "^2.29.4", + "moment-timezone": "^0.5.45", "pinia": "^2.1.6", "rfdc": "^1.3.0", "sass": "^1.66.1", diff --git a/frontend/src/components/licences/LicenceDetails.vue b/frontend/src/components/licences/LicenceDetails.vue index 4e3dc1ae..314b149b 100644 --- a/frontend/src/components/licences/LicenceDetails.vue +++ b/frontend/src/components/licences/LicenceDetails.vue @@ -266,7 +266,7 @@ import AppLabel from '@/components/ui/AppLabel.vue' import AppNumberInput from '@/components/ui/AppNumberInput.vue' import AppTimeInput from '@/components/ui/AppTimeInput.vue' import AppYesNoInput from '@/components/ui/AppYesNoInput.vue' -import LicenceService from '@/services/licenceService' +import format from '@/utils/format' import rules from '@/utils/rules' import { useAppStore } from '@/stores/app' import { BLANK_FIELD, DAYS_OF_WEEK } from '@/utils/constants' @@ -385,8 +385,8 @@ export default { }, getErrorMessagesForOperationTime(licenceDetail) { - const from = LicenceService.convertToCRMOperationDateTimeFormat(licenceDetail?.operationFromTime) - const to = LicenceService.convertToCRMOperationDateTimeFormat(licenceDetail?.operationToTime) + const from = format.convertTimeToDateTimeFormat(licenceDetail?.operationFromTime) + const to = format.convertTimeToDateTimeFormat(licenceDetail?.operationToTime) return from >= to ? 'Hours To must be after Hours From' : '' }, }, diff --git a/frontend/src/services/licenceService.js b/frontend/src/services/licenceService.js index 118c2c44..a40db53b 100644 --- a/frontend/src/services/licenceService.js +++ b/frontend/src/services/licenceService.js @@ -54,11 +54,4 @@ export default { isSplitClassRoomInfoValid(licenceDetail) { return !licenceDetail.applyRoomSplitCondition || !isEmpty(licenceDetail.roomSplitDetails) }, - convertToCRMOperationDateTimeFormat(time) { - const hours = time?.split(':')[0] - const minutes = time?.split(':')[1] - const convertedTime = new Date() - convertedTime.setHours(hours, minutes, 0, 0) - return convertedTime - }, } diff --git a/frontend/src/utils/constants.js b/frontend/src/utils/constants.js index 212ba84c..e68013d5 100644 --- a/frontend/src/utils/constants.js +++ b/frontend/src/utils/constants.js @@ -295,3 +295,5 @@ export const DAYS_OF_WEEK = Object.freeze([ value: 7, }, ]) + +export const TIME_ZONE = 'America/Vancouver' diff --git a/frontend/src/utils/format.js b/frontend/src/utils/format.js index 3f98f702..94607141 100644 --- a/frontend/src/utils/format.js +++ b/frontend/src/utils/format.js @@ -1,7 +1,8 @@ import { isEmpty } from 'lodash' import moment from 'moment' +import momentTZ from 'moment-timezone' -import { BLANK_FIELD } from '@/utils/constants' +import { BLANK_FIELD, TIME_ZONE } from '@/utils/constants' function formatDate(date) { if (!date) return BLANK_FIELD @@ -31,6 +32,16 @@ function convertUTCDatetoPSTDate(date) { return pstDate.toISOString().split('.')[0] + 'Z' } +/* Example +- Input: 13:00 +- Output: 2024-08-06 13:00:00 PDT +*/ +function convertTimeToDateTimeFormat(time) { + const hours = time?.split(':')[0] + const minutes = time?.split(':')[1] + return momentTZ().tz(TIME_ZONE).hours(hours).minutes(minutes).seconds(0).milliseconds(0) +} + function formatTime12to24(time12h) { if (isEmpty(time12h) || !is12hFormat(time12h)) return time12h const [time, modifier] = time12h.split(' ') @@ -69,6 +80,7 @@ function formatDecimalNumber(decimalNumber, numberOfFractionDigits = 2) { } export default { + convertTimeToDateTimeFormat, convertUTCDatetoPSTDate, formatDate, formatDateTime, diff --git a/frontend/src/views/applications/ServiceDeliveryView.vue b/frontend/src/views/applications/ServiceDeliveryView.vue index 7b7b8800..9bbaf840 100644 --- a/frontend/src/views/applications/ServiceDeliveryView.vue +++ b/frontend/src/views/applications/ServiceDeliveryView.vue @@ -67,6 +67,7 @@ import ApplicationService from '@/services/applicationService' import LicenceService from '@/services/licenceService' import { useApplicationsStore } from '@/stores/applications' import { APPLICATION_ERROR_MESSAGES, APPLICATION_ROUTES, OFM_PROGRAM_CODES } from '@/utils/constants' +import format from '@/utils/format' import rules from '@/utils/rules' import alertMixin from '@/mixins/alertMixin' @@ -214,8 +215,8 @@ export default { updateLicenceDetails(updatedModel) { const clonedModel = cloneDeep(updatedModel) - clonedModel.updatableOperationFromTime = LicenceService.convertToCRMOperationDateTimeFormat(clonedModel.operationFromTime) - clonedModel.updatableOperationToTime = LicenceService.convertToCRMOperationDateTimeFormat(clonedModel.operationToTime) + clonedModel.updatableOperationFromTime = format.convertTimeToDateTimeFormat(clonedModel.operationFromTime) + clonedModel.updatableOperationToTime = format.convertTimeToDateTimeFormat(clonedModel.operationToTime) clonedModel.weekDays = clonedModel?.weekDays?.toString() const index = this.changedLicences.findIndex((el) => el.licenceDetailId == clonedModel.licenceDetailId) if (index === -1) {