My API puts in MongoDB
a BsonDateTime. I receive two Dates from this API called startDate and endDate but I can't add an event to Week View with it. When I convert startDate to String, it writes Mon May 14 08:00:00 GMT+01:00 2018
.
This is the content in Postman:
[
{
"Id": "5b51ab5ad09030396092b0cd",
"userId": "5b56f3c714e86f36e0433359",
"company": "Empresa 2",
"year": "2015",
"month": "May",
"day": "15",
"weekDay": "Tuesday",
"shift": "Morning",
"weekDayId": "2",
"shiftId": "1",
"hours": "8",
"startDate": "2018-05-14T07:00:00Z",
"endDate": "2018-05-14T16:00:00Z"
}
]
And this is my code in Android Studio:
public void updateEvents() {
weekView.setMonthChangeListener(new MonthLoader.MonthChangeListener() {
@Override
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
Thread.currentThread().interrupt();
APIInterface apiInterface = APIClient.getClient().create(APIInterface.class);
Call<Schedule[]> call = apiInterface.getScheduleByUserID("5b56f3c714e86f36e0433359");
call.enqueue(new Callback<Schedule[]>() {
@Override
public void onResponse(Call<Schedule[]> call, final Response<Schedule[]> response) {
start = response.body()[0].getStartDate();
end = response.body()[0].getStartDate();
Toast.makeText(DiaHorarioActivity.this, start.toString(), Toast.LENGTH_SHORT).show();
Toast.makeText(DiaHorarioActivity.this, end.toString(), Toast.LENGTH_SHORT).show();
Calendar startTime = new GregorianCalendar();
startTime.setTime(start);
Calendar endTime = (Calendar) startTime.clone();
endTime.setTime(end);
WeekViewEvent event = new WeekViewEvent(1, "test", startTime, endTime);
event.setColor(getResources().getColor(R.color.cardRejeitar));
events.add(event);
}
@Override
public void onFailure(Call<Schedule[]> call, Throwable t) {
Toast.makeText(DiaHorarioActivity.this, t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
});
Thread.currentThread().run();
return events;
}
});
}
The event doesn't appear anywhere. Please help.