Calculating StartDate and endDate of a day based on todays date. Swift 2
<p>I have the following function which i am using to calculate a start and end of todays date. It was working perfectly last week, i think it may have something to do with the clocks going forwards?</p>

<pre><code>func rangeOfPeriod(period: NSCalendarUnit, date: NSDate) -&gt; (NSDate, NSDate) {
        let calendar = NSCalendar.currentCalendar()
        var startDate: NSDate? = nil
        var duration: NSTimeInterval = 0

        calendar.rangeOfUnit(period, startDate: &amp;startDate, interval: &amp;duration, forDate: date)

        let endDate = startDate!.dateByAddingTimeInterval(duration - 1)

        return (startDate!, endDate)
}
</code></pre>

<p>When I try and calculate the start and end of a day using:</p>

<pre><code>print("Start of Day = \(rangeOfPeriod(.Day, date: NSDate()).0), End of Day = \(rangeOfPeriod(.Day, date: NSDate()).1)")
</code></pre>

<p>I get the following, where the start and end date is 1hour behind what is expected:</p>

<pre><code>Start of Day = 2016-03-27 23:00:00 +0000, End of Day = 2016-03-28 22:59:59 +0000
</code></pre>

<p>when i would expect:</p>

<pre><code>Start of Day = 2016-03-28 00:00:00 +0000, End of Day = 2016-03-28 23:59:59 +0000
</code></pre>

<p>Any help would be appreciated </p>