-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨#296: 마이페이지 필터링 타입 바인딩 및 드랍 시간 표기 작업
- 백엔드 작업 후 좋아요한 뮤직 노출 처리 필요
- Loading branch information
Showing
6 changed files
with
117 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
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
46 changes: 46 additions & 0 deletions
46
StreetDrop/StreetDrop/Util/Extensions/Date+TimeAgoDisplay.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Date+TimeAgoDisplay.swift | ||
// StreetDrop | ||
// | ||
// Created by thoonk on 9/30/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Date { | ||
func timeAgoDisplay(from date: Date) -> String { | ||
let calendar = Calendar.current | ||
let components = calendar.dateComponents([ | ||
.year, | ||
.month, | ||
.weekOfYear, | ||
.day, | ||
.hour, | ||
.minute, | ||
.second | ||
], from: date, to: self) | ||
|
||
if let years = components.year, years > 0 { | ||
return "\(years)년 전" | ||
} | ||
if let months = components.month, months > 0 { | ||
return "\(months)달 전" | ||
} | ||
if let weeks = components.weekOfYear, weeks > 0 { | ||
return "\(weeks)주 전" | ||
} | ||
if let days = components.day, days > 0 { | ||
return "\(days)일 전" | ||
} | ||
if let hours = components.hour, hours > 0 { | ||
return "\(hours)시간 전" | ||
} | ||
if let minutes = components.minute, minutes > 0 { | ||
return "\(minutes)분 전" | ||
} | ||
if let seconds = components.second, seconds > 0 { | ||
return "\(seconds)초 전" | ||
} | ||
return "1초 전" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// String+ToDate.swift | ||
// StreetDrop | ||
// | ||
// Created by thoonk on 9/30/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension String { | ||
func toDate( | ||
format: String = "yyyy-MM-dd HH:mm:ss", | ||
timeZone: TimeZone? = TimeZone(identifier: "Asia/Seoul") | ||
) -> Date? { | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateFormat = format | ||
dateFormatter.timeZone = timeZone | ||
return dateFormatter.date(from: self) | ||
} | ||
} |