-
Notifications
You must be signed in to change notification settings - Fork 0
/
Contents.swift
29 lines (23 loc) · 830 Bytes
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import UIKit
let currentDate = Date()
let pasteDate = Date(timeIntervalSinceNow: -60 * 60 * 24 * 7)
extension Date {
func displayTimeInSocialMediaStyle() -> String {
let secondsAgo = Int(Date().timeIntervalSince(self))
let minute = 60
let hour = 60 * minute
let day = 24 * hour
let week = 7 * day
if secondsAgo < minute {
return "\(secondsAgo) second ago"
} else if secondsAgo < hour {
return "\(secondsAgo / minute) minutes ago"
} else if secondsAgo < day {
return "\(secondsAgo / hour) hours ago"
} else if secondsAgo < week {
return "\(secondsAgo / day) days ago"
}
return "\(secondsAgo / week) weeks ago"
}
}
pasteDate.displayTimeInSocialMediaStyle()