mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-02-08 09:04:36 +01:00
[API/Usos] Fix year end date on new school year
This commit is contained in:
parent
1e7dbba995
commit
c35222cdfd
@ -35,24 +35,38 @@ class UsosApiTerms(
|
|||||||
return@apiRequest
|
return@apiRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_USOS_API_TERMS, 7 * DAY)
|
data.setSyncNext(ENDPOINT_USOS_API_TERMS, 2 * DAY)
|
||||||
onSuccess(ENDPOINT_USOS_API_TERMS)
|
onSuccess(ENDPOINT_USOS_API_TERMS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processResponse(json: JsonArray): Boolean {
|
private fun processResponse(json: JsonArray): Boolean {
|
||||||
|
val profile = profile ?: return false
|
||||||
val today = Date.getToday()
|
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) } ?: continue
|
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) } ?: continue
|
val finishDate = term.getString("finish_date")?.let { Date.fromY_m_d(it) } ?: continue
|
||||||
if (today in startDate..finishDate) {
|
if (today !in startDate..finishDate)
|
||||||
profile?.studentSchoolYearStart = startDate.year
|
continue
|
||||||
profile?.dateSemester1Start = startDate
|
|
||||||
profile?.dateSemester2Start = finishDate
|
if (startDate.month >= 8)
|
||||||
}
|
profile.dateSemester1Start = startDate
|
||||||
|
else
|
||||||
|
profile.dateSemester2Start = startDate
|
||||||
|
|
||||||
|
if (finishDate.month >= 8)
|
||||||
|
profile.dateYearEnd = finishDate
|
||||||
|
else
|
||||||
|
profile.dateSemester2Start = finishDate
|
||||||
}
|
}
|
||||||
|
// update school year start
|
||||||
|
profile.studentSchoolYearStart = profile.dateSemester1Start.year
|
||||||
|
// update year end date if there is a new year
|
||||||
|
if (profile.dateYearEnd <= profile.dateSemester1Start)
|
||||||
|
profile.dateYearEnd =
|
||||||
|
profile.dateSemester1Start.clone().setYear(profile.dateSemester1Start.year + 1)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user