blob: a13039df513cd7775f43ef307816f1fdbb3a36c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
function getPeriodBy(session, period, type = null)
{
const Type = ['trimester', 'semester', 'year'];
const periods = session.params.periods;
if (!type || Type.indexOf(type) === -1) {
type = 'trimester'
}
if (!period) {
const now = Date.now();
return periods.find(p => now >= p.from && now <= p.to && p.kind === type) || periods[5];
} else if (typeof period === 'string') {
for (const p of periods) {
if (p.name === period) {
return p;
}
}
}
return period;
}
module.exports = {
getPeriodBy
};
|