Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

endDate in findEvents results not always correct #23

Open
ghost opened this issue Jul 19, 2017 · 5 comments
Open

endDate in findEvents results not always correct #23

ghost opened this issue Jul 19, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented Jul 19, 2017

The endDate in results from findEvents is sometimes returned as 1970-01-01T00:00:00.000Z, even if allDay is false. In other cases the date is correct. The events are in a google calendar and were not created via your plugin. This is on Android.

@EddyVerbruggen
Copy link
Owner

Can you share an example event where this is the case?

@ghost
Copy link
Author

ghost commented Jul 19, 2017

Here is the code:

var Observable = require("data/observable").Observable;
var Calendar = require("nativescript-calendar");
var ObservableArray = require("data/observable-array").ObservableArray;
var dialogs = require("ui/dialogs");

function createViewModel() {
var viewModel = new Observable();
viewModel.eventList = new ObservableArray();

var options = {
    startDate: new Date(new Date().getTime() - (2*24*60*60*1000)),
    endDate: new Date(new Date().getTime() + (14*24*60*60*1000))
};

Calendar.findEvents(options).then(
    function(events) {
        var day, dayName, monthName, hh, mm, theTime;
        var days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
        var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

        /*
        dialogs.alert({
            title: "All Events",
            message: JSON.stringify(events),
            okButtonText: "Ok"
        });
        */

        for(var j=0; j<events.length; j++) {
            if(events[j].calendar.name === '[email protected]') {
                if(events[j].allDay) {
                    events[j].timeDisplay = 'All Day';
                }
                else {
                    // From
                    day = events[j].startDate.getDate();
                    dayName = days[events[j].startDate.getDay()];
                    monthName = months[events[j].startDate.getMonth()];

                    hh = events[j].startDate.getHours();
                    mm = events[j].startDate.getMinutes().toString();
                    mm = (mm < 10) ? '0' + mm.toString() : mm.toString();

                    if(hh < 12) {
                        events[j].timeDisplay = dayName + " " + monthName + " " + day.toString() + "  " + hh.toString() + ':' + mm + ' am';
                    }
                    else {
                        events[j].timeDisplay = dayName + " " + monthName + " " + day.toString() + "  " + (hh - 12).toString() + ':' + mm + ' pm';
                    }

                    // To
                    if (events[j].endDate.getFullYear() === 1969 || events[j].endDate.getFullYear() === 1970 ) {
                        // no To time
                    }
                    else {
                        hh = events[j].endDate.getHours();
                        mm = events[j].endDate.getMinutes().toString();
                        mm = (mm < 10) ? '0' + mm.toString() : mm.toString();

                        if(hh < 12) {
                            events[j].timeDisplay += ' - ' + hh.toString() + ':' + mm + ' am';
                        }
                        else {
                            events[j].timeDisplay += ' - ' + (hh - 12).toString() + ':' + mm + ' pm';
                        }
                    }
                }
                viewModel.eventList.push(events[j]);
            }
        }
    },
    function(error) {
        dialogs.alert({
            title: "Error: findEvents",
            message: error,
            okButtonText: "Ok"
        });
    }
);

return viewModel;

}

exports.createViewModel = createViewModel;

@ghost
Copy link
Author

ghost commented Jul 20, 2017

Here is an image showing part of the JSON.stringify of the returned events. Look at the endDate values, some are fine, others have the 1970 date. The ones that are incorrect are repeating events; maybe that helps? These seem to show the startDate of the first repeat and an incorrect endDate.

screenshot_20170719-215432

@bzaruk
Copy link
Contributor

bzaruk commented Oct 29, 2017

Hey @EddyVerbruggen
Also have that issue...There is any update about it?

Also can confirm that it happens only on repeating events.

@EddyVerbruggen
Copy link
Owner

Looks like we need to add a null check on this line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants