syncfusion / flutter-examples

This repository contains the Syncfusion Flutter UI widgets examples and the guide to use them.
Other
1.98k stars 775 forks source link

[SfCalendar] Weird behaviour with all timezones UTC #831

Closed jonasbadstuebner closed 1 year ago

jonasbadstuebner commented 1 year ago

Hey there, I wanted to implement my calendar and all its appointments in UTC to make time shifting in my backend easier. Unfortunately, if I set

SfCalendar(
  [...]
  timeZone: 'UTC',
  [...]
)

and on the appointments/datasource

  @override
  String? getStartTimeZone(int index) => 'UTC';

  @override
  String? getEndTimeZone(int index) => 'UTC';

I get a start time where appointment.startTime.timeZoneName == 'CET' and appointment.startTimeZone == 'UTC'

Could someone look into this and track my error down please? Or tell me a workaround? I tried to find the error in the code of SfCalendar, but it is huge and I thought someone with more experience with this library could help me. Thank you in advance!

jonasbadstuebner commented 1 year ago

Maybe it is helpful to know the following: I set

@override
DateTime getStartTime(int index) {
  return DateTime.fromMillisecondsSinceEpoch(1700000000000, isUtc: true);
}
SfCalendar(
  [...]
  timeZone: 'UTC',
  [...]
)

with

  @override
  String? getStartTimeZone(int index) => 'Australia/Perth';

  @override
  String? getEndTimeZone(int index) => 'Australia/Perth';

(Australia/Perth is just a random test with big time shift to see an effect) This gives appointment.startTime.timeZoneName == CET appointment.startTime == 2023-11-14 14:13:20.000 appointment.startTimeZone == Australia/Perth appoinment.startTime is shifted by 8 hours into the past - which is correct (I think).


SfCalendar(
  [...]
  timeZone: 'Australia/Perth',
  [...]
)

with

  @override
  String? getStartTimeZone(int index) => 'UTC';

  @override
  String? getEndTimeZone(int index) => 'UTC';

gives appointment.startTime.timeZoneName == CET appointment.startTime == 2023-11-14 07:13:20.000 appointment.startTimeZone == UTC the time is shifted 16 hours into the past. Which is not correct, I think.


SfCalendar(
  [...]
  // timeZone: 'nothing set',
  [...]
)

with

  @override
  String? getStartTimeZone(int index) => 'UTC';

  @override
  String? getEndTimeZone(int index) => 'UTC';

gives me appointment.startTime.timeZoneName == CET appointment.startTime == 2023-11-14 15:13:20.000 appointment.startTimeZone == Australia/Perth


Timezone shifting is a hard topic imho...so I am grateful if someone has an idea and I would be happy to test it out.

jonasbadstuebner commented 1 year ago

Well I guess I should open it in flutter-widget instead