Skip to content

Commit

Permalink
feat(friends): show relate joined date
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed Jul 21, 2021
1 parent 31d5e02 commit 418c9aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions firstfm/Models/LastFM/Friend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ struct Registered: Codable {
case unixtime
case text = "#text"
}

func getRelative() -> String {
let unixTimestamp = Double(self.unixtime)!
let date = Date(timeIntervalSince1970: unixTimestamp)
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
let relativeDate = formatter.localizedString(for: date, relativeTo: Date())
return relativeDate
}
}
4 changes: 2 additions & 2 deletions firstfm/Views/Profile/FriendRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct FriendRow: View {
var body: some View {
HStack {
if friend.image[2].url == "" {
Image(systemName: "person.crop.circle")
Image(systemName: "person.crop.circle").scaleEffect(2)
} else {
KFImage.url(URL(string: friend.image[0].url )!)
.resizable()
Expand All @@ -28,7 +28,7 @@ struct FriendRow: View {
Text(friend.name).font(.headline)
.lineLimit(1)
Spacer()
Text("Joined \(friend.registered.text)")
Text("Joined \(friend.registered.getRelative())")
.font(.subheadline)
.foregroundColor(.gray)
}
Expand Down

0 comments on commit 418c9aa

Please sign in to comment.