Find date function in swift

public func timeAgoSince(_ date: Date) -> String {
    let suffix = "Ago"
    let calendar = Calendar.current
    let now = Date()
    let unitFlags: NSCalendar.Unit = [.second, .minute, .hour, .day, .weekOfYear, .month, .year]
    let components = (calendar as NSCalendar).components(unitFlags, from: date, to: now, options: [])
    
    if let second = components.second, second < 60 {
        return "\(second)" + " Seconds " + suffix;
    }
    if let minute = components.minute, minute < 60{
        return "\(minute)" + " Minutes " + suffix;
    }
    if let hour = components.hour, hour < 24{
        return getStringFromDate(date: date, format: "dd MMM yyyy, hh:mm aa")
    }
    if let day = components.day, day >= 7{
        if (day > 30) {
            return getStringFromDate(date: date, format: "dd MMM, hh:mm aa")
        } else if (day > 360) {
            return getStringFromDate(date: date, format: "dd MMM yyyy, hh:mm aa")
        } else {
            return getStringFromDate(date: date, format: "dd MMM, hh:mm aa")
        }
    }
    return "Just now"
}