feat(home): 인기 커뮤니티 섹션을 연결한다
This commit is contained in:
@@ -15,6 +15,38 @@ enum DateParser {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
static func relativeTimeText(fromUTC text: String, fallback: String, now: Date = Date()) -> String {
|
||||
guard let date = parse(text) else {
|
||||
return fallback
|
||||
}
|
||||
|
||||
let interval = max(0, now.timeIntervalSince(date))
|
||||
let calendar = Calendar.current
|
||||
let yearMonth = calendar.dateComponents([.year, .month], from: date, to: now)
|
||||
|
||||
if let years = yearMonth.year, years >= 1 {
|
||||
return I18n.Time.yearsAgo(years)
|
||||
}
|
||||
|
||||
if let months = yearMonth.month, months >= 1 {
|
||||
return I18n.Time.monthsAgo(months)
|
||||
}
|
||||
|
||||
if interval < 60 {
|
||||
return I18n.Time.justNow
|
||||
}
|
||||
|
||||
if interval < 3600 {
|
||||
return I18n.Time.minutesAgo(max(1, Int(interval / 60)))
|
||||
}
|
||||
|
||||
if interval < 86_400 {
|
||||
return I18n.Time.hoursAgo(max(1, Int(interval / 3600)))
|
||||
}
|
||||
|
||||
return I18n.Time.daysAgo(max(1, Int(interval / 86_400)))
|
||||
}
|
||||
|
||||
// 시도 순서: ISO8601(소수초 포함) → ISO8601 → RFC3339 유사 → 공백 구분 기본
|
||||
private static let parsers: [(String) -> Date?] = [
|
||||
|
||||
Reference in New Issue
Block a user