daysUpTo method

Iterable<DateTime> daysUpTo(
  1. DateTime end
)

Generates a sequence of DateTime objects representing each day in the range starting from this DateTime (inclusive) up to but not including the end DateTime.

Handles time zone adjustments to ensure accurate day boundaries.

Implementation

Iterable<DateTime> daysUpTo(DateTime end) sync* {
  var current = this;
  var currentOffset = current.timeZoneOffset; // Store initial offset
  while (current.isBefore(end)) {
    yield current;
    current = current.add(const Duration(days: 1));

    // Adjust for potential time zone changes during iteration
    final offsetDifference = current.timeZoneOffset - currentOffset;
    if (offsetDifference.inSeconds != 0) {
      currentOffset = current.timeZoneOffset; // Update offset
      current =
          current.subtract(Duration(seconds: offsetDifference.inSeconds));
    }
  }
}