syncfusion / flutter-widgets

Syncfusion Flutter widgets libraries include high quality UI widgets and file-format packages to help you create rich, high-quality applications for iOS, Android, and web from a single code base.
1.55k stars 757 forks source link

Calendar day view shows all day events the day prior when timezone is UTC < 0 #2039

Open Brechard opened 3 weeks ago

Brechard commented 3 weeks ago

Bug description

When using the calendar view on the day CalendarView.day and the phone is on a timezone that is on UTC < 0 (e.g. America) the events that are full day are shown the day before they should (e.g. an event with date: 2024-08-27 00:00:00.000Z is shown the 26th August instead of the 27th).

I have tried every view and the error only happens on the daily one, and it only happens when the timezone is in UTC < 0, all the rest work properly.

Steps to reproduce

  1. Create an event with datetime "2024-08-27 00:00:00.000Z"
  2. Have the phone with timezone anywhere in America
  3. Show it on the calendar with option CalendarView.day
  4. The event is shown the 26th instead of the 27th

Code sample

Code sample ```dart [Add your code here] ```

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Stack Traces

Stack Traces ```dart [Add the Stack Traces here] ```

On which target platforms have you observed this bug?

Android, iOS

Flutter Doctor output

[✓] Flutter (Channel stable, 3.24.1, on macOS 14.5 23F79 darwin-arm64, locale en-US)
    • Flutter version 3.24.1 on channel stable at /Users/brechard/software/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5874a72aa4 (6 days ago), 2024-08-20 16:46:00 -0500
    • Engine revision c9b9d5780d
    • Dart version 3.5.1
    • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/brechard/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)

[✓] VS Code (version 1.90.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.90.0

[✓] Connected device (4 available)
    • iPad (6th generation) (mobile)  • D0C97538-3325-4915-BC2B-46B6822F06BB • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 14.5 23F79 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 14.5 23F79 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 127.0.6533.120

[✓] Network resources
    • All expected network resources are available.
ThilipChandru commented 1 week ago

Hi @Brechard,

We have checked the events with timeZone as UTC<0 and tried to replicate in SfCalendar with version 26.2.12 by enabling the timeZone property. However, we were unable to reproduce it on our end. Please check the attached sample, and if you are still experiencing the issue, we request that you replicate it in the attached sample and provide us with more details regarding the specific scenario in which you are encountering this issue. This will help us to assist you more effectively.

Sample : gh_2039.zip

Regards, S Thilip Chandru.

Brechard commented 1 week ago

Hi @ThilipChandru sorry I was probably not clear enough with the bug. The problem arises when the phone timezone is set to < 0, not the timezone of the event, the event data is in UTC, it is an ALL DAY event, and the phone timezone is set to < 0. To replicate the issue you need one simulated phone with UTC > 0 timezone, and the other simulator with timezone UTC < 0. And here is the code that you execute in both phones:

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SizedBox(
        child: SfCalendar(
          view: CalendarView.day,
          dataSource: _getCalendarDataSource(),
        ),
      ),
    );
  }
}

_AppointmentDataSource _getCalendarDataSource() {
  DateTime t = DateTime.now().toUtc().copyWith(hour: 0, minute: 0, second: 0, millisecond: 0);
  appointments.add(Appointment(
    startTime: t,
    endTime: t,
    isAllDay: true,
    subject: 'Meeting',
    color: Colors.blue,
  ));

  return _AppointmentDataSource(appointments);
}