diff --git a/Sources/VRCKit/Extensions/DateFormatter+iso8601Full.swift b/Sources/VRCKit/Extensions/DateFormatter+iso8601Full.swift index b0086bc..12d4772 100644 --- a/Sources/VRCKit/Extensions/DateFormatter+iso8601Full.swift +++ b/Sources/VRCKit/Extensions/DateFormatter+iso8601Full.swift @@ -16,4 +16,12 @@ public extension DateFormatter { formatter.locale = Locale(identifier: "en_US_POSIX") return formatter }() + + static let dateStringFormat: DateFormatter = { + let formatter = DateFormatter() + formatter.dateFormat = "yyy-MM-dd" + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.locale = Locale(identifier: "en_US_POSIX") + return formatter + }() } diff --git a/Sources/VRCKit/Models/UserDetailModel.swift b/Sources/VRCKit/Models/UserDetailModel.swift index 863346c..6a3f70f 100644 --- a/Sources/VRCKit/Models/UserDetailModel.swift +++ b/Sources/VRCKit/Models/UserDetailModel.swift @@ -25,7 +25,7 @@ public struct UserDetail: ProfileDetailRepresentable, LocationRepresentable { public let userIcon: URL? public let location: String public let friendKey: String - public let dateJoined: String + public let dateJoined: Date? public var note: String public let lastActivity: Date } @@ -50,7 +50,8 @@ extension UserDetail: Codable { userIcon = try? container.decodeIfPresent(URL.self, forKey: .userIcon) location = try container.decode(String.self, forKey: .location) friendKey = try container.decode(String.self, forKey: .friendKey) - dateJoined = try container.decode(String.self, forKey: .dateJoined) + let dateJoinedString = try container.decode(String.self, forKey: .dateJoined) + dateJoined = DateFormatter.dateStringFormat.date(from: dateJoinedString) note = try container.decode(String.self, forKey: .note) lastActivity = try container.decode(Date.self, forKey: .lastActivity) } diff --git a/Sources/VRCKit/Models/UserModel.swift b/Sources/VRCKit/Models/UserModel.swift index 73be3e2..9b6b066 100644 --- a/Sources/VRCKit/Models/UserModel.swift +++ b/Sources/VRCKit/Models/UserModel.swift @@ -15,7 +15,7 @@ public struct User: ProfileDetailRepresentable { public let currentAvatar: String public let avatarImageUrl: URL? public let avatarThumbnailUrl: URL? - public let dateJoined: String + public let dateJoined: Date? public let displayName: String public let friendKey: String public let friends: [String] @@ -63,7 +63,8 @@ extension User: Codable { currentAvatar = try container.decode(String.self, forKey: .currentAvatar) avatarImageUrl = try? container.decodeIfPresent(URL.self, forKey: .avatarImageUrl) avatarThumbnailUrl = try? container.decodeIfPresent(URL.self, forKey: .avatarThumbnailUrl) - dateJoined = try container.decode(String.self, forKey: .dateJoined) + let dateJoinedString = try container.decode(String.self, forKey: .dateJoined) + dateJoined = DateFormatter.dateStringFormat.date(from: dateJoinedString) displayName = try container.decode(String.self, forKey: .displayName) friendKey = try container.decode(String.self, forKey: .friendKey) friends = try container.decode([String].self, forKey: .friends) diff --git a/Sources/VRCKit/PreviewServices/PreviewDataProvider.swift b/Sources/VRCKit/PreviewServices/PreviewDataProvider.swift index 58d6f79..9a2c32d 100644 --- a/Sources/VRCKit/PreviewServices/PreviewDataProvider.swift +++ b/Sources/VRCKit/PreviewServices/PreviewDataProvider.swift @@ -67,7 +67,7 @@ final class PreviewDataProvider { currentAvatar: "", avatarImageUrl: nil, avatarThumbnailUrl: nil, - dateJoined: "2024/07/01", + dateJoined: Date(), displayName: "usr_\(previewUserId.uuidString.prefix(8))", friendKey: "", friends: friends.map(\.id), @@ -162,7 +162,7 @@ final class PreviewDataProvider { userIcon: URL(string: "https://ul.h3z.jp/9gGIcerr.png"), location: location, friendKey: "", - dateJoined: "", + dateJoined: Date(), note: "", lastActivity: Date() ) diff --git a/Sources/VRCKit/Protocols/ProfileProtocols.swift b/Sources/VRCKit/Protocols/ProfileProtocols.swift index d799c19..d3be836 100644 --- a/Sources/VRCKit/Protocols/ProfileProtocols.swift +++ b/Sources/VRCKit/Protocols/ProfileProtocols.swift @@ -30,7 +30,7 @@ public protocol ProfileElementRepresentable: Hashable, Identifiable { /// A protocol representing detailed profile properties for users. /// This protocol extends ProfileElementRepresentable and can be adopted by structures like User and UserDetail. public protocol ProfileDetailRepresentable: ProfileElementRepresentable { - var dateJoined: String { get } + var dateJoined: Date? { get } var lastActivity: Date { get } var state: User.State { get } }