From 4f80eda38601794940d1e93351dd2ceac06d7855 Mon Sep 17 00:00:00 2001 From: Toni Rico Date: Tue, 5 Dec 2023 15:41:30 +0100 Subject: [PATCH] Improve pricePerYear price calculation precision (#3492) ### Description Followup to #3480 This slightly improves precision when calculating price per year for weekly subscriptions. --- .../Purchasing/StoreKitAbstractions/SubscriptionPeriod.swift | 2 +- .../StoreKitAbstractions/SubscriptionPeriodTests.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Purchasing/StoreKitAbstractions/SubscriptionPeriod.swift b/Sources/Purchasing/StoreKitAbstractions/SubscriptionPeriod.swift index f98e681b38..eee22f26c0 100644 --- a/Sources/Purchasing/StoreKitAbstractions/SubscriptionPeriod.swift +++ b/Sources/Purchasing/StoreKitAbstractions/SubscriptionPeriod.swift @@ -168,7 +168,7 @@ private extension SubscriptionPeriod { static let daysPerMonth: Decimal = 30 static let daysPerYear: Decimal = 365 static let weeksPerMonth: Decimal = daysPerYear / monthsPerYear / daysPerWeek - static let weeksPerYear: Decimal = 52.14 + static let weeksPerYear: Decimal = daysPerYear / daysPerWeek static let monthsPerYear: Decimal = 12 } diff --git a/Tests/UnitTests/Purchasing/StoreKitAbstractions/SubscriptionPeriodTests.swift b/Tests/UnitTests/Purchasing/StoreKitAbstractions/SubscriptionPeriodTests.swift index 3b625057c2..bbb96338d9 100644 --- a/Tests/UnitTests/Purchasing/StoreKitAbstractions/SubscriptionPeriodTests.swift +++ b/Tests/UnitTests/Purchasing/StoreKitAbstractions/SubscriptionPeriodTests.swift @@ -106,8 +106,8 @@ class SubscriptionPeriodTests: TestCase { .init(p(1, .day), 1, 365), .init(p(1, .day), 2, 730), .init(p(15, .day), 5, 121.66), - .init(p(1, .week), 10, 521.4), - .init(p(2, .week), 10, 260.7), + .init(p(1, .week), 10, 521.42), + .init(p(2, .week), 10, 260.71), .init(p(1, .month), 14.99, 179.88), .init(p(1, .month), 5, 60), .init(p(2, .month), 30, 180),