SwiftyDate icon indicating copy to clipboard operation
SwiftyDate copied to clipboard

The easiest way to generate relative dates in Swift.

SwiftyDate

SwiftyDate allows you to easily create relative NSDates in Swift.

It extends the Swift number types to allow you to create expressions like this:

let pastDate = 12.days.ago()
let futureDate = 7.weeks.fromNow()
let beforeDate = 5.minutes.before(anotherDate)
let afterDate = 15.hours.after(anotherDate)

Includes extensions for NSTimeInterval, Double, Int, Float, CGFloat, and NSNumber.

Time interval types:

  • seconds
  • minutes
  • hours
  • days
  • weeks

Functions to generate dates:

  • fromNow()
  • ago()
  • after(date: NSDate)
  • before(date: NSDate)

Installation

CocoaPods

pod 'SwiftyDate'

Usage

import SwiftyDate


Original idea by my friend Joe.