Skip to content

Commit

Permalink
fix(calendar): Fixed calculation of multi-day events #87
Browse files Browse the repository at this point in the history
Fixes #87
  • Loading branch information
agfeo-rw committed Sep 4, 2024
1 parent 85b03f5 commit 135d718
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.4.14] - 2024-09-04
* Issue #87: Fixed calculation of multiday events

## [0.4.13] - 2024-09-03
* Some more null checks in reaction to an app crash log possibly related to this package

Expand Down
9 changes: 8 additions & 1 deletion lib/flutter_neat_and_clean_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,14 @@ class _CalendarState extends State<Calendar> {
eventsMap != null &&
eventsMap!.isEmpty) {
widget.eventsList!.forEach((event) {
final int range = event.endTime.difference(event.startTime).inDays;
int range = event.endTime.difference(event.startTime).inDays;

// Check if the end time is before the start time and adjust the calculation.
if (event.endTime.hour < event.startTime.hour ||
(event.endTime.hour == event.startTime.hour &&
event.endTime.minute < event.startTime.minute)) {
range += 1; // Add one day because the end time is earlier.
}
// Event starts and ends on the same day.
if (range == 0) {
List<NeatCleanCalendarEvent> dateList = eventsMap![DateTime(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: >-
Simple and clean flutter calendar with ability to slide up/down to show
weekly/monthly calendar. Fork of
https://pub.dev/packages/flutter_clean_calendar
version: 0.4.13
version: 0.4.14
homepage: https://github.com/rwbr/flutter_neat_and_clean_calendar

environment:
Expand Down

0 comments on commit 135d718

Please sign in to comment.