I have a DateInterval
where I'd like to get dates every 15 seconds between the two dates. For example, from July 15 10:14:00 AM
to July 15 10:16:00 AM
, I'd like to generate the following dates:
July 15 10:14:00 AM
July 15 10:14:15 AM
July 15 10:14:30 AM
July 15 10:14:45 AM
July 15 10:15:00 AM
July 15 10:15:15 AM
July 15 10:15:30 AM
July 15 10:15:45 AM
July 15 10:16:00 AM
It doesn't have to be a DateInterval
, but thought it would be better to encapsulate the range using it. More importantly though, I’d like to use higher order functions and an immutable variable to accomplish this. I've tried a few things but couldn't quite get it:
let dateInterval = DateInterval(start: date1, duration: addingTimeInterval(10 * 60.0))
for var date in date1...date1.addingTimeInterval(10 * 60.0) {
...
}
var intervals = [date1]
while intervals.last <= date1.addingTimeInterval(10 * 60) {
intervals.append(intervals.last.addingTimeInterval(15))
}
Would greatly appreciate any help!