Skip to content

Instantly share code, notes, and snippets.

@malcommac
Created November 30, 2016 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malcommac/14ad049a5acaee53c33e145cccc25f82 to your computer and use it in GitHub Desktop.
Save malcommac/14ad049a5acaee53c33e145cccc25f82 to your computer and use it in GitHub Desktop.
Enumerate Dates in SwiftDate
// using DateInRegion
// create an array of [DateInRegion] instances from fromDate (included) to toDate (30 days ahead) by incrementing each date by 1 day
let fromDate = DateInRegion().startOf(component: .day) // normalize at the start of the day
let toDate = fromDate + 30.days
let dates = DateInRegion.dates(between: fromDate, and: toDate, increment: 1.day)
// using Date
// create an array of [DateInRegion] instances from fromDate (included) to toDate (30 days ahead) by incrementing each date by 1 day,2 hours and 40 minutes
let fromDate = Date().startOf(component: .day) // normalize at the start of the day
let toDate = fromDate + 30.days
let dates = Date.dates(between: fromDate, and: toDate, increment: (1.day && 2.hours && 40.minutes) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment