title: Dart Lang: Strange result adding 7 days. Sometimes it doesn't compute well
body: <p>Given a date, and let's say it is Monday, I hope that if I add 7 days I will get a new Monday.</p>
  <p>That is so sometimes, in some case it adds a little less and I get a Sunday.
  I can keep adding 7 days and I get Sundays until I get a new Monday back.</p>
  <p>How can I make a precise cycle that returns me the same day of the week.</p>
  <p>Here I leave the code in Dart. Linked to a <a href="https://dartpad.dev/a40ea69cf210733a9dc45ea574795a8a" rel="nofollow noreferrer">dartpad</a></p>
  <pre class="lang-dart prettyprint-override"><code>void main() {
    var date = DateTime(2020, 10, 20);
    var weekday = date.weekday;
    var endDate = DateTime(2021, 4, 8);
    while (endDate.difference(date).inDays &gt; 0) {
      assert(date.weekday == weekday);
      print('$date ${date.weekday} $weekday');
      date = date.add(Duration(days: 7));
    }
    print('end');
  }
  </code></pre>
  <p>The result is</p>
  <pre><code>2020-10-20 00:00:00.000 2 2
  2020-10-26 23:00:00.000 1 2
  2020-11-02 23:00:00.000 1 2
  2020-11-09 23:00:00.000 1 2
  2020-11-16 23:00:00.000 1 2
  2020-11-23 23:00:00.000 1 2
  2020-11-30 23:00:00.000 1 2
  2020-12-07 23:00:00.000 1 2
  2020-12-14 23:00:00.000 1 2
  2020-12-21 23:00:00.000 1 2
  2020-12-28 23:00:00.000 1 2
  2021-01-04 23:00:00.000 1 2
  2021-01-11 23:00:00.000 1 2
  2021-01-18 23:00:00.000 1 2
  2021-01-25 23:00:00.000 1 2
  2021-02-01 23:00:00.000 1 2
  2021-02-08 23:00:00.000 1 2
  2021-02-15 23:00:00.000 1 2
  2021-02-22 23:00:00.000 1 2
  2021-03-01 23:00:00.000 1 2
  2021-03-08 23:00:00.000 1 2
  2021-03-15 23:00:00.000 1 2
  2021-03-22 23:00:00.000 1 2
  2021-03-30 00:00:00.000 2 2
  2021-04-06 00:00:00.000 2 2
  end
  </code></pre>