title: Date range with correct TimeZone in Swift
body: <p>I know there is a lot of questions about time zones and dates but I really having hard time to figure this out.</p>
  <p>My time zone is GMT+3 (That's what my physical device says)</p>
  <p>I'm trying to get the range of the next week starting from Sunday.
  So it need to be Sep 27 ... Oct 3</p>
  <p>Every night at 09:PM the results that I'm getting is from Sep 28 ... Oct 4.
  It's stays that way until 03:AM</p>
  <p>The current time that I'm writing this question is 2:AM and it's shows me this range from Sep 28.</p>
  <p>I made an extension for <code>Date</code> and added this variables (I'm using SwiftDate also).</p>
  <pre><code>var closedRange: ClosedRange&lt;Date&gt; {
          let d = Date() //.timeInterval - Fix the problem until 03:AM
          let calendar = Calendar.autoupdatingCurrent
          let min = calendar.date(byAdding: .day, value: 0, to: d.nextWeekday(.sunday))!
          let max = calendar.date(byAdding: .day, value: 6, to: d.nextWeekday(.sunday))!
          return min...max
      }
  </code></pre>
  <p>If I adding this var to <code>d</code> the date is correct. but after 3:AM it's messed up again.</p>
  <pre><code>var timeInterval: Date{
          var date = self
          date.addTimeInterval(TimeInterval(TimeZone.current.secondsFromGMT(for: self)))
          return date
      }
  </code></pre>
  <p>Later in view:</p>
  <pre><code>let range = Date().closedRange
      
  DatePicker(LocalizedStringKey(&quot;Choose day:&quot;), selection: $shift.date, in: range, displayedComponents: .date)
  </code></pre>
  <p>The problem also happens when I get the next week as String or Int.
  It starts from Sep 28 instead Sep 27 (again depends on my location time)</p>
  <pre><code>var nextWeek: [String]{
          
          let d = Date()
          var daysArr = [String]()
          let dateFormat = DateFormatter()
          let calendar = Calendar.autoupdatingCurrent
          let dayOfWeek = calendar.component(.weekday, from: d.nextWeekday(.sunday))
          let weekdays = calendar.range(of: .weekday, in: .weekOfYear, for: d.nextWeekday(.sunday))!
          let days = (weekdays.lowerBound ..&lt; weekdays.upperBound).compactMap { calendar.date(byAdding: .day, value: $0 - dayOfWeek, to: d.nextWeekday(.sunday)) }
          
          dateFormat.dateFormat = DateFormats.format11.rawValue
          
          for d in days{
              daysArr.append(dateFormat.string(from: d))
          }
          
          return daysArr
          
      }
  </code></pre>
  <p>The same problem happens with this array of dates.</p>
  <pre><code>var nextWeekAsDates: [Date]{
          
          let d = Date()
          var daysArr = [Date]()
          let calendar = Calendar.autoupdatingCurrent
          let dayOfWeek = calendar.component(.weekday, from: d.nextWeekday(.sunday))
          let weekdays = calendar.range(of: .weekday, in: .weekOfYear, for: d.nextWeekday(.sunday))!
          let days = (weekdays.lowerBound ..&lt; weekdays.upperBound).compactMap { calendar.date(byAdding: .day, value: $0 - dayOfWeek, to: d.nextWeekday(.sunday)) }
                  
          for d in days{
              daysArr.append(d)
          }
          
          return daysArr
          
      }
  </code></pre>