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

Allday property resulting in incorrect event #164

Closed
nickrandolph opened this issue Feb 3, 2020 · 19 comments
Closed

Allday property resulting in incorrect event #164

nickrandolph opened this issue Feb 3, 2020 · 19 comments
Assignees
Labels
bug Something isn't working

Comments

@nickrandolph
Copy link
Contributor

Reported issue: 'the property "Event.allDay = true;" doesn't save the event correctly in the calendar.'

Further comments: this appears to be an issue on Android based on the timezone of the event (eg setting an all day event with a start day before 11am AEST results in the event being for the previous day)

@bhl09 bhl09 self-assigned this Feb 3, 2020
@bhl09 bhl09 added the bug Something isn't working label Feb 3, 2020
@bhl09
Copy link
Contributor

bhl09 commented Feb 3, 2020

Adding info from Android Developer's page:

  • If allDay is set to 1 eventTimezone must be Time#TIMEZONE_UTC and the time must correspond to a midnight boundary.

https://developer.android.com/reference/android/provider/CalendarContract.Events#writing-to-events

@Bernhard7
Copy link

But the class "Event" in "device_calendar" has no property "timezone".

@bhl09
Copy link
Contributor

bhl09 commented Feb 3, 2020

@Bernhard7, this issue is only for Android so I'll need to do a fix on Android native code, not Flutter.

@Bernhard7
Copy link

Thanks for updating device_calendar to ^3.0.0+3. Now it works.

@kinex
Copy link

kinex commented Mar 10, 2020

I think retrieveEvents still returns events with invalid start/end times (testing in master). Few related observations: https://github.com/builttoroam/flutter_plugins/blob/develop/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/CalendarDelegate.kt#L511
=> Should you handle EVENT_TIMEZONE and EVENT_END_TIMEZONE in that code? https://developer.android.com/reference/android/provider/CalendarContract.EventsColumns#EVENT_TIMEZONE

I was also wondering if this code works as expected:
https://github.com/builttoroam/flutter_plugins/blob/develop/device_calendar/lib/src/models/event.dart#L64
Have you noticed that DateTime.fromMillisecondsSinceEpoch has a parameter isUtc which is false by default. I would bet it should be set to true, assuming the dates returned from plugin are meant to be UTC time.

@bhl09
Copy link
Contributor

bhl09 commented Mar 11, 2020

@kinex I've already found a solution for this and will be fixed in next release

@kinex
Copy link

kinex commented Mar 11, 2020

@Brett09 Ok, great. And hopefully you noticed that my previous comment is probably related to a different issue than originally reported in this issue (sorry my bad, I should have created a new issue). In my opinion this is the most annoying issue at the moment what I have seen in this plugin, as for example all events retrieved from holiday calendars have invalid timestamps. Waiting for the fixes, thanks!

@bhl09
Copy link
Contributor

bhl09 commented Mar 25, 2020

This has been fixed in v3.1.0. You will be able to set all day events without any time issues in Android

@bhl09 bhl09 closed this as completed Mar 25, 2020
@kinex
Copy link

kinex commented Mar 31, 2020

@Brett09 I don't think this has been fixed. I am still receiving events from a holiday calendar with invalid offsets. For example "New Year Day" starts 2am in local time. It should start at 0:00,

Did you check my comments above? I think there are clear related issues in the code. Please test this using some holiday calendar which has events with different timezone than your test device. If you just add your own events you won't see the issue.

@bhl09
Copy link
Contributor

bhl09 commented Apr 1, 2020

@kinex the reason it's not showing the time as 0:00 is because the example app is not using toUtc().

The all day event functionality has been fixed however, if you'd like to view the all day events as 0:00, then I recommend for you to add toUtc() in your app.

@kinex
Copy link

kinex commented Apr 1, 2020

@Brett09 The start time should 0:00 in local time. In UTC time it should be 22:00 (previous day, if my timezone is GMT+2). In other words holidays in a local holiday calendar should always start at 0:00 in local time. For example in a German holiday calendar a holiday (all day event) should start at 0:00 in German time (=local time). Any other start time would not make any sense.

@mcavazotti
Copy link

I am facing something similar to @kinex 's problem: my app receives a list of events from the server in local time (the same timezone of the device), and it has to save them as allday events.
I know that the start time will be set to 00:00, but because the DateTime is in UTC, the events are shown on the wrong date in the device's calendar.

@kinex
Copy link

kinex commented Jun 18, 2020

Issue is probably related to code starting from here https://github.com/builttoroam/device_calendar/blob/develop/android/src/main/kotlin/com/builttoroam/devicecalendar/CalendarDelegate.kt#L424. I don't even understand what is it trying to do but you cannot just reset event time to 00:00 and then set timezone to UTC.

Based on my quick code reviews earlier I can say that this plugin has a lot of timezone related issues and hazards (few of them mentioned in my comments above). It works only with good luck and if you happen to live in the "correct" timezone. My own project is currently paused so I haven't had time to investigate these issues further. Someone should really review, understand and fix all timezone related code in this plugin.

@hyouuu
Copy link

hyouuu commented Mar 23, 2021

@kinex have you restarted your project and if so, did you find a better calendar plugin? This repo seems to have stopped progressing

@kinex
Copy link

kinex commented Mar 23, 2021

@hyouuu I will continue my calendar project later, few other apps in queue.... I have not searched other calendar plugins yet.

@nickrandolph
Copy link
Contributor Author

Hi all,

Apologies for this repo being dormant for so long - the last year has had other priorities as you can only imagine I guess.
Pre-covid I did start a branch that reworks the timezone support. I will see whether I can get to it in the coming weeks.
Thanks for the nudge and sorry again for the delay in fixing these issues

@nickrandolph nickrandolph reopened this Mar 24, 2021
@hyouuu
Copy link

hyouuu commented Mar 24, 2021

@nickrandolph thank you very much for providing this package and helping improve it!! Timezone & all day events are annoying problems that's hard to get right - thanks for putting effort in it. I might be able to help after a couple of weeks - let me know if you find some part of the problem worth separating. Looking forward to the improvements :D

@kinex
Copy link

kinex commented Mar 24, 2021

I want to fix one of my earlier comment above regarding DateTime.fromMillisecondsSinceEpoch. I think the method documentation is slightly confusing. So the parameter microsecondsSinceEpoch is always "utc microseconds". The other parameter isUtc only determines if the created DateTime instance is in local or UTC time zone. The created DateTime represents the exactly same date/time no matter if isUtc if true or false. Unit test to verify this:

    test('DateTime', () {
      final now = DateTime.now();

      expect(now.microsecondsSinceEpoch == now.toUtc().microsecondsSinceEpoch,
          isTrue);

      final utcNow = DateTime.now().toUtc();
      expect(
          utcNow.microsecondsSinceEpoch ==
              utcNow.toLocal().microsecondsSinceEpoch,
          isTrue);

      expect(
          DateTime.fromMicrosecondsSinceEpoch(1000, isUtc: false)
              .isAtSameMomentAs(
                  DateTime.fromMicrosecondsSinceEpoch(1000, isUtc: true)),
          isTrue);
    });

@andzejsw
Copy link
Contributor

Can be closed after #297 publishing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants