Skip to content

Commit

Permalink
Merge pull request #279 from UofA-Blueprint/fix/mst-to-utc
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
royayush1 authored Dec 23, 2023
2 parents 8e6f41e + a018208 commit eb99cc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion backend/src/controllers/cron/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export const getEmail = async (req: Request, res: Response) => {
})

const utcExpr = cron?.expression.split(" ")
const days = utcExpr[utcExpr.length-1].split(",")
let days = utcExpr[utcExpr.length-1]
if (days.length > 3) {
days = days.split(",")
} else {
days = [days]
}
const minutes = parseInt(utcExpr[1])
const hours = parseInt(utcExpr[2])

Expand All @@ -42,6 +47,11 @@ export const getEmail = async (req: Request, res: Response) => {
}
const tuple = convertToMT(minutes, hours, "MON")
let cronExpression = `0 ${tuple[0]} ${tuple[1]} * * `
if (setDays.length > 1) {
cronExpression += setDays.join(",")
} else {
cronExpression += setDays[0]
}
return res.status(200).json({ cron : {
...cron,
expression: cronExpression
Expand Down
2 changes: 1 addition & 1 deletion backend/src/services/cron/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const convertToMT = (minute: number, hour: number, day: string) : [number
}

const newHour = (hour+increment+24)%24
if (newHour < hour) day = days[day]
if (newHour > hour) day = days[day]

return [minute, newHour, day]
}

0 comments on commit eb99cc5

Please sign in to comment.