Skip to content

Commit

Permalink
Added aws-lti-middleware directory containing code for AWS LTI middle…
Browse files Browse the repository at this point in the history
…ware
  • Loading branch information
apai25 committed Jul 11, 2024
1 parent 82e9f39 commit f6e949c
Show file tree
Hide file tree
Showing 5,800 changed files with 1,066,289 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
66 changes: 66 additions & 0 deletions aws-lti-middleware/calculateSemester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const { SESSION_SYSTEM } = require('@common/global-config')

const calculateSemester = (ms) => {
const date = new Date(ms)
const semesters = [
{
name: "Fall",
start: 70,
end: 100
},
{
name: "Spring",
start: 0,
end: 45
},
{
name: "Summer",
start: 45,
end: 70
}
]
const quarters = [
{
name: "Fall",
start: 75,
end: 100
},
{
name: "Winter",
start: 0,
end: 30
},
{
name: "Spring",
start: 30,
end: 55
},
{
name: "Summer",
start: 55,
end: 75
}
]

const currentYear = date.getUTCFullYear()
const nextYear = date.getUTCFullYear() + 1

const _baseline = new Date(0)
_baseline.setUTCFullYear(currentYear)
const baseline = _baseline.getTime()

const _eoy = new Date(0)
_eoy.setUTCFullYear(nextYear)
const eoy = _eoy.getTime()

const progress = (ms - baseline) / (eoy - baseline) * 100

const session = (SESSION_SYSTEM === "SEMESTER" ? semesters : quarters)
.find(({ start, end }) => progress >= start && progress < end);

return `${session.name} ${currentYear}`
}

module.exports = {
calculateSemester
}
Loading

0 comments on commit f6e949c

Please sign in to comment.