Skip to content

Commit a3ab3e7

Browse files
committed
[Feat] Presentation 시간 표시용 extension 추가
1 parent 8eba6af commit a3ab3e7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

TnT/Projects/Presentation/Sources/Extension/Date+.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,23 @@
77
//
88

99
import Foundation
10+
11+
import Domain
12+
13+
extension Date {
14+
func timeAgoDisplay() -> String {
15+
let now = Date()
16+
let calendar = Calendar.current
17+
let components = calendar.dateComponents([.second, .minute, .hour, .day], from: self, to: now)
18+
19+
if let day = components.day, day >= 1 {
20+
return TDateFormatUtility.formatter(for: .M월_d일).string(from: self)
21+
} else if let hour = components.hour, hour >= 1 {
22+
return "\(hour)시간 전"
23+
} else if let minute = components.minute, minute >= 1 {
24+
return "\(minute)분 전"
25+
} else {
26+
return "방금"
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)