Skip to content

Commit ccdd471

Browse files
fixing range problem with summer winter time
1 parent d74129c commit ccdd471

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

lib/src/controllers.dart

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class RangePickerController {
9292
return one.year == two.year && one.month == two.month && one.day == two.day;
9393
}
9494

95+
/// Returns whether the [date] is selectable or not. (i.e. if it is between the [minDate] and the [maxDate])
9596
/// Returns whether the [date] is selectable or not. (i.e. if it is between the [minDate] and the [maxDate])
9697
bool dateIsSelectable(DateTime date) {
9798
for (final DateTime disabledDay in disabledDates) {
@@ -100,8 +101,23 @@ class RangePickerController {
100101
}
101102
}
102103

103-
if (startDate != null && endDate == null) {
104-
var dateDifference = date.difference(startDate!).inDays;
104+
DateTime tmpDate = date.toUtc();
105+
tmpDate = tmpDate.add(date.timeZoneOffset);
106+
107+
DateTime? tmpStartDate;
108+
DateTime? tmpEndDate;
109+
110+
if (startDate != null) {
111+
tmpStartDate = startDate!.toUtc();
112+
tmpStartDate = tmpStartDate.add(startDate!.timeZoneOffset);
113+
}
114+
if (endDate != null) {
115+
tmpEndDate = endDate!.toUtc();
116+
tmpEndDate = tmpEndDate.add(endDate!.timeZoneOffset);
117+
}
118+
119+
if (tmpStartDate != null && tmpEndDate == null) {
120+
var dateDifference = tmpDate.difference(tmpStartDate).inDays;
105121
if (maximumDateRangeLength != null &&
106122
dateDifference + 1 > maximumDateRangeLength!) {
107123
return false;
@@ -114,10 +130,10 @@ class RangePickerController {
114130
}
115131
}
116132

117-
if (minDate != null && date.isBefore(minDate!)) {
133+
if (minDate != null && tmpDate.isBefore(minDate!)) {
118134
return false;
119135
}
120-
if (maxDate != null && date.isAfter(maxDate!)) {
136+
if (maxDate != null && tmpDate.isAfter(maxDate!)) {
121137
return false;
122138
}
123139
return true;

0 commit comments

Comments
 (0)