Periods Calculation Algorithm
When calculating the duration of a period such values as period start and end dates, number of days in the month when subscription was purchased, as well as some intermediate calculated values based on the initial data, are taken into account.
The following variables are used for calculations:
-
BaseDate
Subscription ordering date; the value will be used in further calculations.
-
BaseMonth
BaseDate is the day of BaseMonth month. The number of days in the BaseMonth is important for further calculations. Note that in Billing starting from version 5.5 the alternative number of days can be used for calculations, such as:
- fixed (30) days;
- actual number of days in current month.
For details refer to corresponding KB article.
-
FromDate
-
ToDate
End date of the period we calculate. In case of refunds the date up to which the subscription was paid is used as a value.
- If the Charge Before Billing Period billing model is used - this is the next Billing date.
- If the Charge Before Subscription Period billing model is used - this is the subscription Expiration date.
For details about billing dates refer to
Provider's Guide, sections Billing Models and Basic Billing Models. -
DateDiffInMonths
The interval in months between FromDate date and ToDate date. For the dates in the DD.MM.YY format, only months of the dates are taken into account, i.e., MM. For example, for May 30, 2011 and June 02, 2011 dates the difference in months would be 1 month.
-
IntermediateDate
Intermediate date used later. Calculated as a sum FromDate + DateDiffInMonths.
Examples:
- 02.01.12 + 1 month = 02.02.12
- 05.01.12 + 1 month = 05.02.12
- 06.01.12 + 2 months = 06.03.12
- 29.01.12 + 1 month = 29.02.12
- 30.01.12 + 1 month = 29.02.12
- 31.01.12 + 1 month = 29.02.12
- 31.01.13 + 1 month = 28.02.13
-
DaysInMonth
The number of days in the BaseMonth.
- FractMonthDiff
- DiffInMonths
Start date of the period we calculate. In case of refunds, the subscription cancellation or downgrade date is taken as this date.
Difference in months, a fraction. First, the difference between (the day of month taken from ToDate) and (the day of month taken from IntermediateDate) is calculated. Then the result is divided by the DaysInMonth value. The FractMonthDiff value is stored as a simple fraction such as x/y; it may also possess a negative value. If the day of a subscription purchase (DD) is greater than the day (DD) of subscription cancelation, the value of FractMonthDiff will be a positive value.
The target value, i.e., the duration of the period we calculate. The DiffInMonths value is calculated as a sum of DateDiffInMonth + FractMonthDiff. For example, 1 + (-2/31) = 29/31. The resulting value is rounded upward with an accuracy to two decimal places according to the mathematical rules. Then this rounded value is used for further calculation of amounts. In the example above (29 days of the 31 calendar days) the result is 0.93548387... After rounding, the target value will be 0.94.
Below are several examples of the refund period calculation.
Example 1
- Scenario: A customer purchases a 1-year subscription on May 14, 2012 and cancels it on January 31, 2013.
- Question: What is the refund period?
Calculation is made under the following conditions:
- Billing period type = Monthly on Statement Day, with the billing date on the 1st of the month.
- Subscription is billed for = Before Billing Period.
Calculation:
- BaseDate - subscription purchase date: May14, 2012
- BaseMonth - base month: May
- FromDate - subscription cancellation date: January 31, 2013
- ToDate - next billing day: February 1, 2013
- DateDiffInMonths - difference in months: (February - January) = (2 - 1) = 1 month.
- IntermediateDate - intermediate date: January 31, 2013 + 1 month = February 28, 2013.
- DaysInMonths - number of days in the base month: since May is the base month, the value is 31 days.
-
FractMonthDiff - difference in months, fraction: (day of month from ToDate - day of month from IntermediateDate) / DaysInMonth:
(1 - 28)/31 = -27/31
-
DiffInMonths - duration of the period we calculate: the sum DateDiffInMonth + FractMonthDiff:
1 + (-27/31) = 4/31 = 0.1290325..., or 0.13 after rounding.
Result:
The customer must be refunded for the period of 0.13 months.
Example 2
- Scenario: A customer purchases 1-year subscription on May 14, 2012 and cancels it on January 31, 2013.
- Question: What is the refund period?
Calculation is made under the following conditions:
- Billing period type = Monthly on Statement Day, with the billing date on the 1st of the month.
- Subscription is billed for = Before Subscription Period.
Calculation:
- BaseDate - subscription purchase date: May 14, 2012
- BaseMonth - base month: May
- FromDate - subscription cancellation date: January 31, 2013
- ToDate - subscription expiration date: May 14, 2013
- DateDiffInMonths - difference in months: (May - January) = (5 - 1) = 4 months.
- IntermediateDate - intermediate date: January 31, 2013 + 4 months = May 31, 2013.
- DaysInMonths - number of days in the base month: since May is the base month, the value is 31 days.
- FractMonthDiff - difference in months, fraction.
(day of month from ToDate - day of month from IntermediateDate) / DaysInMonth:
(14 - 31)/31 = -17/31
-
DiffInMonths - duration of the period we calculate: the sum DateDiffInMonth + FractMonthDiff:
4 + (-17/31) = 107/31 = 3.4516129..., or 3.45 after rounding.
Result:
The customer must be refunded for the period of 3.45 months.
Example 3
- Scenario: A customer purchases 1-year subscription on May 14, 2012 and cancels it on February 3, 2013.
- Question: What is the refund period?
Calculation is made under the following conditions:
- Billing period type = Monthly on Statement Day, with the billing date on the 1st of the month.
- Subscription is billed for = Before Subscription Period.
Calculation:
- BaseDate - subscription purchase date: May 14, 2012
- BaseMonth - base month: May
- FromDate - subscription cancellation date: February 3, 2013
- ToDate - subscription expiration date: May 14, 2013
- DateDiffInMonths - difference in months: (May - February ) = (5 - 2) = 3 months.
- IntermediateDate - intermediate date: February 3, 2013 + 3 months = May 3, 2013.
- DaysInMonths - number of days in the base month: since May is the base month, the value is 31 days.
- FractMonthDiff - difference in months, fraction.
-
(day of month from ToDate - day of month from IntermediateDate) / DaysInMonth:
(14 - 3)/31 = 11/31
-
DiffInMonths - duration of the period we calculate: the sum DateDiffInMonth + FractMonthDiff:
3 + (11/31) = 104/31 = 3.3548387..., or 3.35 after rounding.
Result:
The customer must be refunded for the period of 3.35 months.
Example 4
- Scenario: A customer purchases a 1-year subscription on January 28, 2022 and cancels it on January 30, 2022.
- Question: What is the refund period?
Calculation is made under the following conditions:
- Billing period type = Monthly.
- Subscription is billed for = Before Billing Period.
Calculation:
- BaseDate - subscription purchase date: January 28, 2022
- BaseMonth - base month: January
- FromDate - subscription cancellation date: January 30, 2022
- ToDate - subscription next billing date: February 28, 2022
- DateDiffInMonths - difference in months: (February - January) = (2 - 1) = 1 months.
- IntermediateDate - intermediate date: January 28, 2022 + 1 months = February 28, 2022.
- DaysInMonths - number of days in the base month: since January is the base month, the value is 31 days.
- FractMonthDiff - difference in months, fraction.
(day of month from ToDate - day of month from IntermediateDate) / DaysInMonth:
(28 - 28)/31 = 0/31
-
DiffInMonths - duration of the period we calculate: the sum DateDiffInMonth + FractMonthDiff:
1 + 0 = 1.0
Result:
The customer must be refunded for the period of 1.0 months.