Skip to content

Commit

Permalink
ofmcc-5446 - fix timezone bug in LicenceDetails Operation Hour input
Browse files Browse the repository at this point in the history
  • Loading branch information
vietle-cgi committed Aug 6, 2024
1 parent 34e5016 commit 2b7226e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
20 changes: 20 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/licences/LicenceDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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' : ''
},
},
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/services/licenceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
2 changes: 2 additions & 0 deletions frontend/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,5 @@ export const DAYS_OF_WEEK = Object.freeze([
value: 7,
},
])

export const TIME_ZONE = 'America/Vancouver'
16 changes: 15 additions & 1 deletion frontend/src/utils/format.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,6 +32,18 @@ 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]
console.log(time)
console.log(momentTZ().tz(TIME_ZONE).hours(hours).minutes(minutes).seconds(0).milliseconds(0).format('YYYY-MM-DD HH:mm:ss z'))
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(' ')
Expand Down Expand Up @@ -69,6 +82,7 @@ function formatDecimalNumber(decimalNumber, numberOfFractionDigits = 2) {
}

export default {
convertTimeToDateTimeFormat,
convertUTCDatetoPSTDate,
formatDate,
formatDateTime,
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/views/applications/ServiceDeliveryView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2b7226e

Please sign in to comment.