0

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.

eduPeeth
  • 1,840
  • 13
  • 21
Pedro
  • 1
  • FYI, the troublesome old date-time classes such as `java.util.Date`, `java.util.Calendar`, and `java.text.SimpleDateFormat` are now legacy, supplanted by the [*java.time*](https://docs.oracle.com/javase/10/docs/api/java/time/package-summary.html) classes. Much of the *java.time* functionality is back-ported to Java 6 & Java 7 in the [***ThreeTen-Backport***](http://www.threeten.org/threetenbp/) project. Further adapted for earlier Android in the [***ThreeTenABP***](https://github.com/JakeWharton/ThreeTenABP) project. See [*How to use ThreeTenABP…*](http://stackoverflow.com/q/38922754/642706). – Basil Bourque Jul 25 '18 at 18:54
  • Thank you so much! It really helped. – Pedro Jul 26 '18 at 15:58
  • Good. So now you can write an Answer to your own Question showing your solution. – Basil Bourque Jul 26 '18 at 16:09

0 Answers0