Unverified Commit 812c189d authored by Darren Austin's avatar Darren Austin Committed by GitHub

Fixed a problem with date calculations that caused a test to fail in a non-US time zone. (#60396)

parent c0902d60
...@@ -668,14 +668,14 @@ class _MonthPickerState extends State<_MonthPicker> { ...@@ -668,14 +668,14 @@ class _MonthPickerState extends State<_MonthPicker> {
}); });
} }
static const Map<TraversalDirection, Duration> _directionOffset = <TraversalDirection, Duration>{ static const Map<TraversalDirection, int> _directionOffset = <TraversalDirection, int>{
TraversalDirection.up: Duration(days: -DateTime.daysPerWeek), TraversalDirection.up: -DateTime.daysPerWeek,
TraversalDirection.right: Duration(days: 1), TraversalDirection.right: 1,
TraversalDirection.down: Duration(days: DateTime.daysPerWeek), TraversalDirection.down: DateTime.daysPerWeek,
TraversalDirection.left: Duration(days: -1), TraversalDirection.left: -1,
}; };
Duration _dayDirectionOffset(TraversalDirection traversalDirection, TextDirection textDirection) { int _dayDirectionOffset(TraversalDirection traversalDirection, TextDirection textDirection) {
// Swap left and right if the text direction if RTL // Swap left and right if the text direction if RTL
if (textDirection == TextDirection.rtl) { if (textDirection == TextDirection.rtl) {
if (traversalDirection == TraversalDirection.left) if (traversalDirection == TraversalDirection.left)
...@@ -688,12 +688,12 @@ class _MonthPickerState extends State<_MonthPicker> { ...@@ -688,12 +688,12 @@ class _MonthPickerState extends State<_MonthPicker> {
DateTime _nextDateInDirection(DateTime date, TraversalDirection direction) { DateTime _nextDateInDirection(DateTime date, TraversalDirection direction) {
final TextDirection textDirection = Directionality.of(context); final TextDirection textDirection = Directionality.of(context);
DateTime nextDate = date.toUtc().add(_dayDirectionOffset(direction, textDirection)); DateTime nextDate = utils.addDaysToDate(date, _dayDirectionOffset(direction, textDirection));
while (!nextDate.isBefore(widget.firstDate) && !nextDate.isAfter(widget.lastDate)) { while (!nextDate.isBefore(widget.firstDate) && !nextDate.isAfter(widget.lastDate)) {
if (_isSelectable(nextDate)) { if (_isSelectable(nextDate)) {
return nextDate; return nextDate;
} }
nextDate = nextDate.add(_dayDirectionOffset(direction, textDirection)); nextDate = utils.addDaysToDate(nextDate, _dayDirectionOffset(direction, textDirection));
} }
return null; return null;
} }
......
...@@ -72,6 +72,11 @@ DateTime addMonthsToMonthDate(DateTime monthDate, int monthsToAdd) { ...@@ -72,6 +72,11 @@ DateTime addMonthsToMonthDate(DateTime monthDate, int monthsToAdd) {
return DateTime(monthDate.year, monthDate.month + monthsToAdd); return DateTime(monthDate.year, monthDate.month + monthsToAdd);
} }
/// Returns a [DateTime] with the added number of days and no time set.
DateTime addDaysToDate(DateTime date, int days) {
return DateTime(date.year, date.month, date.day + days);
}
/// Computes the offset from the first day of the week that the first day of /// Computes the offset from the first day of the week that the first day of
/// the [month] falls on. /// the [month] falls on.
/// ///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment