From 5d756b0a5bd3024c2ef7570003b533c5dec2397d Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 30 Apr 2024 14:33:19 +0800 Subject: [PATCH 1/4] GachaItemMO // Add nullable CoreData field "timeRawValue". --- .../HSRPizzaHelper.xcdatamodel/contents | 1 + Features/Gacha/Model/GachaItemMO+CoreDataProperties.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Common/Model/CoreData/HSRPizzaHelper.xcdatamodeld/HSRPizzaHelper.xcdatamodel/contents b/Common/Model/CoreData/HSRPizzaHelper.xcdatamodeld/HSRPizzaHelper.xcdatamodel/contents index 45342027..792ffd9f 100644 --- a/Common/Model/CoreData/HSRPizzaHelper.xcdatamodeld/HSRPizzaHelper.xcdatamodel/contents +++ b/Common/Model/CoreData/HSRPizzaHelper.xcdatamodeld/HSRPizzaHelper.xcdatamodel/contents @@ -21,6 +21,7 @@ + \ No newline at end of file diff --git a/Features/Gacha/Model/GachaItemMO+CoreDataProperties.swift b/Features/Gacha/Model/GachaItemMO+CoreDataProperties.swift index 12be44ca..0fb12473 100644 --- a/Features/Gacha/Model/GachaItemMO+CoreDataProperties.swift +++ b/Features/Gacha/Model/GachaItemMO+CoreDataProperties.swift @@ -28,6 +28,7 @@ extension GachaItemMO { @NSManaged public var name: String! @NSManaged public var rankRawValue: String! @NSManaged public var time: Date! + @NSManaged public var timeRawValue: String? @NSManaged public var uid: String! var gachaType: GachaType { From 15bd581005446a837eaf5e9e5de82cdca62fa278 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 30 Apr 2024 15:20:48 +0800 Subject: [PATCH 2/4] SRGFv1 // Add support for timeRawValue. - This is to keep the fidelity of the time data per each gacha entry. --- Features/Gacha/Model/GachaItemMO+CoreDataClass.swift | 3 +++ Packages/SRGFKit/Sources/SRGFKit/GachaEntry.swift | 3 +++ Packages/SRGFKit/Sources/SRGFKit/SRGFv1.swift | 7 ++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Features/Gacha/Model/GachaItemMO+CoreDataClass.swift b/Features/Gacha/Model/GachaItemMO+CoreDataClass.swift index 4e6acec7..c8bed90d 100644 --- a/Features/Gacha/Model/GachaItemMO+CoreDataClass.swift +++ b/Features/Gacha/Model/GachaItemMO+CoreDataClass.swift @@ -24,6 +24,7 @@ extension GachaEntry { result.name = name result.rankRawValue = rankRawValue result.time = time + result.timeRawValue = timeRawValue result.uid = uid return result } @@ -40,6 +41,7 @@ extension GachaEntry { result.name = name result.rankRawValue = rankRawValue result.time = time + result.timeRawValue = timeRawValue result.uid = uid return result } @@ -58,6 +60,7 @@ extension GachaItemMO { name: name, rankRawValue: rankRawValue, time: time, + timeRawValue: timeRawValue, uid: uid ) } diff --git a/Packages/SRGFKit/Sources/SRGFKit/GachaEntry.swift b/Packages/SRGFKit/Sources/SRGFKit/GachaEntry.swift index 46faa8ef..ab1338a8 100644 --- a/Packages/SRGFKit/Sources/SRGFKit/GachaEntry.swift +++ b/Packages/SRGFKit/Sources/SRGFKit/GachaEntry.swift @@ -22,6 +22,7 @@ public struct GachaEntry: Codable, Sendable, Hashable, Identifiable { name: String, rankRawValue: String, time: Date, + timeRawValue: String?, uid: String ) { self.count = count @@ -34,6 +35,7 @@ public struct GachaEntry: Codable, Sendable, Hashable, Identifiable { self.name = name self.rankRawValue = rankRawValue self.time = time + self.timeRawValue = timeRawValue self.uid = uid } @@ -49,5 +51,6 @@ public struct GachaEntry: Codable, Sendable, Hashable, Identifiable { public var name: String public var rankRawValue: String public var time: Date + public var timeRawValue: String? public var uid: String } diff --git a/Packages/SRGFKit/Sources/SRGFKit/SRGFv1.swift b/Packages/SRGFKit/Sources/SRGFKit/SRGFv1.swift index c025b989..ff52f9e8 100644 --- a/Packages/SRGFKit/Sources/SRGFKit/SRGFv1.swift +++ b/Packages/SRGFKit/Sources/SRGFKit/SRGFv1.swift @@ -202,7 +202,7 @@ extension SRGFv1.DataEntry { langOverride: lang ) ?? name } - + let timeTyped: Date? = DateFormatter.forSRGFEntry(timeZoneDelta: timeZoneDelta).date(from: time) return .init( count: Int32(count ?? "1") ?? 1, // Default is 1. gachaID: gachaID, @@ -213,7 +213,8 @@ extension SRGFv1.DataEntry { langRawValue: lang.rawValue, name: name ?? "#NAME:\(id)#", rankRawValue: rankType ?? "3", - time: DateFormatter.forSRGFEntry(timeZoneDelta: timeZoneDelta).date(from: time) ?? Date(), + time: timeTyped ?? Date(), + timeRawValue: time, uid: uid ) } @@ -233,7 +234,7 @@ extension GachaEntry { return .init( gachaID: gachaID, itemID: itemID, - time: time.asSRGFDate(timeZoneDelta: timeZoneDelta), + time: timeRawValue ?? time.asSRGFDate(timeZoneDelta: timeZoneDelta), id: id, gachaType: .init(rawValue: gachaTypeRawValue) ?? .departureWarp, name: name, From da80553212a74f5986d2d894864baace61961a92 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 30 Apr 2024 15:32:40 +0800 Subject: [PATCH 3/4] HBMihoyoAPI // Keep the timeRawValue captured and intact. --- .../Sources/HBMihoyoAPI/GachaAPI/GachaModel.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Packages/HBMihoyoAPI/Sources/HBMihoyoAPI/GachaAPI/GachaModel.swift b/Packages/HBMihoyoAPI/Sources/HBMihoyoAPI/GachaAPI/GachaModel.swift index 9d15cf7c..c5ff523e 100644 --- a/Packages/HBMihoyoAPI/Sources/HBMihoyoAPI/GachaAPI/GachaModel.swift +++ b/Packages/HBMihoyoAPI/Sources/HBMihoyoAPI/GachaAPI/GachaModel.swift @@ -92,13 +92,13 @@ public struct GachaItem: Codable { public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.uid = try container.decode(String.self, forKey: .uid) - let timeString = try container.decode(String.self, forKey: .time) + self.timeRawValue = try container.decode(String.self, forKey: .time) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" dateFormatter.locale = Locale(identifier: "en_US_POSIX") // 抽卡记录的网页固定显示伺服器时间。 dateFormatter.timeZone = .init(secondsFromGMT: Self.getServerTimeZoneDelta(uid) * 3600) - if let time = dateFormatter.date(from: timeString) { + if let time = dateFormatter.date(from: timeRawValue) { self.time = time } else { throw DecodingError.typeMismatch( @@ -159,6 +159,7 @@ public struct GachaItem: Codable { public let uid: String public let time: Date + public let timeRawValue: String public let gachaID: String public let gachaType: GachaType public let itemID: String From a2653ea07ec3192f85335861282f8144250eff97 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 30 Apr 2024 15:35:55 +0800 Subject: [PATCH 4/4] VmGetGachaView // Save the captured timeRawValue data together. --- Features/Gacha/View/GetGacha/GetGachaViewModel.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Features/Gacha/View/GetGacha/GetGachaViewModel.swift b/Features/Gacha/View/GetGacha/GetGachaViewModel.swift index ce5c89a7..005eeb7a 100644 --- a/Features/Gacha/View/GetGacha/GetGachaViewModel.swift +++ b/Features/Gacha/View/GetGacha/GetGachaViewModel.swift @@ -168,6 +168,7 @@ class GetGachaViewModel: ObservableObject { persistedItem.name = gachaItem.name persistedItem.rank = gachaItem.rank persistedItem.time = gachaItem.time + persistedItem.timeRawValue = gachaItem.timeRawValue persistedItem.uid = gachaItem.uid withAnimation { savedTypeFetchedCount[gachaItem.gachaType]! += 1