fix week number calculation

This commit is contained in:
Anton Romanov 2019-05-24 13:26:02 +04:00
parent 6258e7b6bf
commit 308da4113d

View File

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