werner-scholtz / kalender

An elegantly crafted Flutter calendar UI package.
MIT License
108 stars 29 forks source link

Duplicate date 27th October 2024 #93

Closed BaconFist closed 1 month ago

BaconFist commented 1 month ago

There is a duplicate of October 27. 2025. I've verified it at https://werner-scholtz.github.io/kalender/ in Month and Multi Week view.

What i have seen so far:

Exception_list dart multi_day_event_group_layout dart

flutter --version

Flutter 3.24.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 2663184aa7 (5 weeks ago) • 2024-09-11 16:27:48 -0500
Engine • revision 36335019a8
Tools • Dart 3.5.3 • DevTools 2.37.3

pubspec.yaml

name: name
description: "description"
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
  sdk: ^3.5.1

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.8
  provider: ^6.1.2
  path_provider: ^2.1.4
  uuid: ^4.5.1
  datetime_picker_formfield_new: ^2.1.0

  intl: any
  sqflite: ^2.4.0
  path: ^1.9.0
  share_plus: ^10.0.2
  flutter_archive: ^6.0.3
  file_picker: ^8.1.2
  open_file: ^3.5.8
  awesome_notifications: ^0.9.3+1
  flutter_localizations:
    sdk: flutter
  #flutter_carousel_widget: ^3.0.1
  url_launcher: ^6.3.1
  mime: ^1.0.6
  io: ^1.0.4
  image_picker: ^1.1.2
  flutter_colorpicker: ^1.1.0
  flutter_oss_licenses: ^3.0.2
  photo_view: ^0.15.0
  package_info: ^2.0.2
  kalender: ^0.4.1

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^5.0.0

flutter:
  generate: true
  uses-material-design: true
BaconFist commented 1 month ago

The cause seems to be in https://github.com/werner-scholtz/kalender/blob/50043322a49ade38194ae9c477c5691bcb697294/lib/src/extensions.dart#L23-L51

I assume there is a problem with DateTime.add over daylight saving time.

Example: extension dart extension dart_watches

BaconFist commented 1 month ago

I think i found the cause and a possible solution.

The cause seems to be that DateTime.add(Duration(days: i)) adds i*secondsPerDay seconds instead of just a day.

Using DateTime(year, month, day+i) incremets the day directly. It also works across months and years. For example DateTime(2024,12,31+1) will result in 2025.01.01.

https://dartpad.dev/?id=2aa8b0fa0e3dda67af02fca9000f2344

void main() {
  DateTime start = DateTime(2024,10,27);
  DateTime end = DateTime(2024,11,2);
  List<DateTime> dates = [];
  int diff = start.difference(end).inDays.abs();
  for(int i=0;i<diff;i++){
    dates.add(DateTime(start.year,start.month,start.day+i));
  }

  print(dates.join('\n'));
}
BaconFist commented 1 month ago

created a pull request to solve this.

https://github.com/werner-scholtz/kalender/pull/95