This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String { | |
let calendar = Calendar.current() | |
let now = NSDate() | |
let earliest = now.earlierDate(date as Date) | |
let latest = (earliest == now) ? date : now | |
let components:NSDateComponents = calendar.components([Calendar.Unit.minute , Calendar.Unit.hour , Calendar.Unit.day , Calendar.Unit.weekOfYear , Calendar.Unit.month , Calendar.Unit.year ,Calendar.Unit.second], from: earliest, to: latest as Date, options: Calendar.Options()) | |
if (components.year >= 2) { | |
return "\(components.year) years ago" |