fix week number calculation

environments/staging/deployments/74
Anton Romanov 5 years ago
parent 6258e7b6bf
commit 308da4113d

@ -3,6 +3,7 @@ package ru.ulstu.utils.timetable;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import ru.ulstu.core.util.DateUtils;
import ru.ulstu.utils.timetable.errors.TimetableClientException;
import ru.ulstu.utils.timetable.model.Lesson;
import ru.ulstu.utils.timetable.model.TimetableResponse;
@ -50,9 +51,15 @@ public class TimetableService {
}
private int getCurrentWeek() {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
return (cal.get(Calendar.WEEK_OF_YEAR) + 1) % 2;
Date currentDate = Calendar.getInstance().getTime();
currentDate = DateUtils.clearTime(currentDate);
Calendar firstJan = Calendar.getInstance();
firstJan.set(Calendar.MONTH, 0);
firstJan.set(Calendar.DAY_OF_MONTH, 1);
return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000)
+ DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2));
}
private TimetableResponse getTimetableForUser(String userFIO) throws RestClientException {

Loading…
Cancel
Save