0
votes

I have a function that is supposed to get event from the Parse DB that matches a user selected date. The two involved classes looks like this: SHOW-CLASS & SHOWTIME-CLASS Description: Showtimeclass only has one attribute and that is a date attribute. The Showtimeclass har an array of objectId pointing to Showtimeclass objects. So my mission is to find the Showtimes that matches the selected date, then match the resulting array of showtimes against the Showclass. I was trying to match the Showclass array against my resulting array, but without success. No errors in logcat. My code looks like the following:

Main query code:

        temps = new ArrayList<>();
        tempTimes = new ArrayList<>();
        result = new ArrayList<>();

        tempTimes = getTimes();

        Log.e("SKG: temptimes", String.valueOf(tempTimes.size()));

        final ParseQuery<ParseObject> showQuery = ParseQuery.getQuery("Show");

        showQuery.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> likeList, ParseException e) {
                if (e == null) {
                    for (ParseObject likeItem : likeList) {
                        temps = likeItem.getList("showtimes");
                        Log.e("SKG: temps", String.valueOf(temps.size()));
                        for (String emp : tempTimes) {
                            if (temps.contains(emp)) {
                                result.add(likeItem);
                                Log.e("SKG: event", String.valueOf(result.size()));
                            }
                        }
                    }
                }
            }
        });

GetTimes function:

private ArrayList<String> getTimes() {
    final ArrayList<String> t1 = new ArrayList<>();

    final ParseQuery<ParseObject> showtimeQuery = ParseQuery.getQuery("Showtime");

    Date de = getDateFromDatePicket(dialog.getDatePicker());
    Date ds = getDateFromDatePicketStart(dialog.getDatePicker());

    showtimeQuery.whereLessThanOrEqualTo("date", de);
    showtimeQuery.whereGreaterThanOrEqualTo("date", ds);
    showtimeQuery.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> likeList, ParseException e) {
            if (e == null) {
                for (ParseObject likeItem : likeList) {
                    t1.add(likeItem.getObjectId());
                }
            }
        }
    });

    Log.e("SKG: event", String.valueOf(t1 .size()));
    return t1;
}

So, my question to you is: how can i get the objectId's of objects in the Showclass that matches the selected dates from the Showtimeclass?

1

1 Answers

0
votes

parse saves its time in UTC make sure you are converting it to UTC and try the query, your existing date can be converted to utc like this

SimpleDateFormat lv_formatter = new SimpleDateFormat(); 
lv_formatter.setTimeZone(TimeZone.getTimeZone("UTC"));  
lv_dateFormateInUTC = lv_formatter.format(lv_localDate);