BillingPeriod
Parsed view over an ISO-8601 duration string as used by Google Play billing periods ("P7D", "P1W", "P1M", "P3M", "P6M", "P1Y").
Play returns raw ISO-8601 strings from com.android.billingclient.api.ProductDetails.PricingPhase.getBillingPeriod, which are not directly presentable to users and are awkward to compare. This class turns them into:
a single dominant unit + count pair, which is what you want for localized plurals (
getQuantityString(R.plurals.days, count, count));normalized totalMonths / totalDays, for price-per-month comparisons.
Obtain instances via parse. Comparisons and normalization use the average Gregorian month (30.436875 days) and year (365.2425 days), so P1Y normalizes to exactly 12.0 months and P12M does too.
val period = BillingPeriod.parse("P1Y") // years=1
period.unit // Unit.YEAR
period.count // 1
period.totalMonths // 12.0
period.format() // "1 year"Since
4.4.0
Constructors
Types
Properties
The whole duration expressed in months, using the average Gregorian month. P1Y → 12.0, P1M → 1.0, P1W → ≈0.23, P7D → ≈0.23.
The whole duration expressed in weeks, using the average Gregorian month.
The dominant unit of this period — the largest non-zero component. A period of "P1M15D" reports Unit.MONTH; "P0D" reports Unit.DAY.