Commit fb81d2f6 authored by Jiawen Lyu's avatar Jiawen Lyu

find all days by week

parent bc118b45
......@@ -36,19 +36,71 @@ const data = [
},
];
const toDays = dayString => (
{
"LUNDI": 1,
"MARDI": 2,
"MERCREDI": 3,
"JEUDI": 4,
"VENDREDI": 5,
"SAMEDI": 6,
"DIMANCHE": 7,
}[dayString]
)
const semestreP20 = [
"2020-02-24",
"2020-06-27"
]
const getAllDays = (term, day) => {
let currentDay = term[0]
let days = []
while (currentDay !== term[1]) {
if (new Date(currentDay).getDay() === day) {
days = [...days, currentDay]
}
const semestreP20 = {
start_date: "2020-02-24",
end_date: "2020-06-27"
let dayArr = currentDay.split("-")
if ((dayArr[2] == 30 && dayArr[1] % 2 == 0) || (dayArr[2] == 31 && dayArr[1] % 2 == 1)) {
dayArr[2] = 1
dayArr[1]++
} else {
dayArr[2]++
}
currentDay = dayArr.map((elem, index) => {
if (index !== 0) {
return elem.toString().length === 1 ? "0" + elem : elem
} else return elem
}).join("-")
}
if (new Date(currentDay).getDay() === day) {
days = [...days, term[1]]
}
return days
}
const extractUvDateInfo = uvs => uvs.map(uv => ({
start_date: uv.begin,
end_date: uv.end,
day: uv.day,
const extractUvDateInfo = (uvs, login) => {
let uvInAllTerm = []
uvs.map(uv => {
const daysInTerm = getAllDays(semestreP20, toDays(uv.day))
daysInTerm.map(day => {
uvInAllTerm = [...uvInAllTerm,
{
start_date: day + " " + uv.begin,
end_date: day + " " + uv.end,
text: uv.uv,
id: uvs.indexOf(uv)
}))
id: uvInAllTerm.length + 1,
login: login
}
]
})
})
return uvInAllTerm
}
const getCurrentStudents = data => Array.from(new Set(data.map(elem => elem.login)))
......@@ -84,7 +136,8 @@ class App extends Component {
(result) => {
this.setState({
isLoaded: true,
uvs: result
uvs: result,
login: "jbarthel"
});
},
// Remarque : il est important de traiter les erreurs ici
......@@ -99,8 +152,8 @@ class App extends Component {
)
}
render() {
const { currentTimeFormatState, messages, error, isLoaded, uvs } = this.state;
// const data = extractUvDateInfo(uvs)
const { currentTimeFormatState, messages, error, isLoaded, uvs, login } = this.state;
const data = extractUvDateInfo(uvs, login)
const currentStudents = getCurrentStudents(data)
if (error) {
return <div>Erreur : {error.message}</div>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment