Skip to content

Instantly share code, notes, and snippets.

@StewartLynch
Created January 6, 2026 00:02
Show Gist options
  • Select an option

  • Save StewartLynch/9ef8d017e83b5876d3b18374b9b02a63 to your computer and use it in GitHub Desktop.

Select an option

Save StewartLynch/9ef8d017e83b5876d3b18374b9b02a63 to your computer and use it in GitHub Desktop.
Date Offset Extension
import Foundation
extension Date {
/// Returns a date that is `offset` days from this date.
/// - Parameter offset: The number of days to add or subtract from `self`.
/// - Returns: A new `Date` `offset` days days before or after `self`.
func offset(_ offset: Int) -> Date {
Calendar.current.date(byAdding: .day, value: offset, to: self)!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment