Skip to content

Commit 3235992

Browse files
committed
Recursively normalize subscription periods
1 parent ac30e4e commit 3235992

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

superwall/src/main/java/com/superwall/sdk/store/abstractions/product/SubscriptionPeriod.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,21 @@ data class SubscriptionPeriod(
2626

2727
fun normalized(): SubscriptionPeriod =
2828
when (unit) {
29-
Unit.day -> if (value % 7 == 0) copy(value = value / 7, unit = Unit.week) else this
29+
Unit.day ->
30+
if (value % 30 == 0) {
31+
copy(value = value / 30, unit = Unit.month).normalized()
32+
} else {
33+
if (value % 7 == 0) {
34+
copy(value = value / 7, unit = Unit.week).normalized()
35+
} else {
36+
if (value % 360 == 0) {
37+
copy(value = value / 360, unit = Unit.year)
38+
} else {
39+
this
40+
}
41+
}
42+
}
43+
3044
Unit.month -> if (value % 12 == 0) copy(value = value / 12, unit = Unit.year) else this
3145
else -> this
3246
}

0 commit comments

Comments
 (0)