forked from github/szkolny
[API/Usos] Fix detecting term start and end date.
This commit is contained in:
parent
8424414317
commit
6628b97faf
@ -41,24 +41,18 @@ class UsosApiTerms(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun processResponse(json: JsonArray): Boolean {
|
private fun processResponse(json: JsonArray): Boolean {
|
||||||
val dates = mutableSetOf<Date>()
|
val today = Date.getToday()
|
||||||
for (term in json.asJsonObjectList()) {
|
for (term in json.asJsonObjectList()) {
|
||||||
if (!term.getBoolean("is_active", false))
|
if (!term.getBoolean("is_active", false))
|
||||||
continue
|
continue
|
||||||
val startDate = term.getString("start_date")?.let { Date.fromY_m_d(it) }
|
val startDate = term.getString("start_date")?.let { Date.fromY_m_d(it) } ?: continue
|
||||||
val finishDate = term.getString("finish_date")?.let { Date.fromY_m_d(it) }
|
val finishDate = term.getString("finish_date")?.let { Date.fromY_m_d(it) } ?: continue
|
||||||
if (startDate != null)
|
if (today in startDate..finishDate) {
|
||||||
dates += startDate
|
profile?.studentSchoolYearStart = startDate.year
|
||||||
if (finishDate != null)
|
profile?.dateSemester1Start = startDate
|
||||||
dates += finishDate
|
profile?.dateSemester2Start = finishDate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val datesSorted = dates.sorted()
|
|
||||||
if (datesSorted.size != 3)
|
|
||||||
return false
|
|
||||||
profile?.studentSchoolYearStart = datesSorted[0].year
|
|
||||||
profile?.dateSemester1Start = datesSorted[0]
|
|
||||||
profile?.dateSemester2Start = datesSorted[1]
|
|
||||||
profile?.dateYearEnd = datesSorted[2]
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user