Question

How PBA calculates periods in orders using default algorithm (MONTHDIFF_ALG_ORIGINAL)?

Answer

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 values calculated basing on the initial data, are taken into account.

The following variables are used for calculations :

  1. BaseDate

    Subscription ordering date; the value will be used in further calculations.

  2. BaseMonth

    BaseDate is the day of BaseMonth month. The number of days in the BaseMonth is important for further calculations.

  3. FromDate

    Start date of the period we calculate. In case of refunds, the subscription cancelation or downgrade date is taken as this date.

  4. ToDate

    End date of the period we calculate:

    1. In case of refunds the date up to which the subscription was paid is used as a value.
    2. In case of Change/Billing order placing PBA takes one more day for caculations. For example: Detail End Date is May 14, 2013 - PBA will perform calculations as if the day is May 15, 2013 00:00:00h. This is algorithm specific conditions which allow to bill customer for the previous day (May 14). Please refer to Example 4.

    If Before Billing Period billing model is used - this is the next Billing date.

    If Before Subscription Period billing model is used - this is the subscription Expiration date.

  5. 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.

  6. IntermediateDate

    Intermediate date used later. Calculated as a sum FromDate + DateDiffInMonths. It also depends on number of days in BaseDate, if it is greater than number of days in current month and if FromDate equals the end of the month then Intermediate date will be corrected so it is day of Intermediate date is the nearest day possible to day of BaseDate.(This case described in Example 5)

    Examples:

    BaseDate is December, 3:

    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

    29.02.12 + 1 month = 29.03.12

    BaseDate is December, 31:

    29.02.12 + 1 month = 31.03.12

    29.02.12 + 2 month = 30.04.12

    30.04.12 + 1 month = 31.05.12

    02.01.12 + 1 month = 02.02.12

    BaseDate is December, 30:

    02.01.12 + 1 month = 02.02.12

    29.02.12 + 1 month = 30.03.12

    30.04.12 + 1 month = 30.05.12

  7. DaysInMonth

    The number of days in the BaseMonth.

  8. FractMonthDiff

    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.

  9. DiffInMonths

    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 the examples of period calculation under the conditions of different billing period types are provided.

Example 1

  • A customer purchases a 1-year subscription on May 14, 2012 and cancels it on January 31, 2013.
  • How long would be the refund period?

Calculation is made under the following conditions:

  • Billing period type = Monthly on Statement Cycle Date; 1st day of every month.
  • Subscription is charged = 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 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.

So, a customer should be refunded for the period of 0.13 month.

Example 2

  • A customer purchases 1-year subscription on May 14, 2012 and cancels it on January 31, 2013.
  • How long would be the refund period?

Calculation is made under the following conditions:

    • Billing period type = Monthly on Statement Cycle Date; 1st day of every month.
  • Subscription is charged = Before Subscription Period.

Calculation:

BaseDate - subscription purchase date: May 14, 2012

BaseMonth - base month: May

FromDate - subscription cancelation 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 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.

So the customer should be refunded for the period of 3.45 months.

Example 3

  • A customer purchases 1-year subscription on May 14, 2012 and cancels it on February 3, 2013.
  • How long would be the refund period?

Calculation is made under the following conditions:

  • Billing period type = Monthly on Statement Cycle Date; 1st day of every month.
  • Subscription is charged = Before Subscription Period.

Calculation:

BaseDate - subscription purchase date: May 14, 2012

BaseMonth - base month: May

FromDate - subscription cancelation 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 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.

So the customer should be refunded for the period of 3.35 months.

Example 4

  • A customer purchases additional resource for subscription for 1 month on June 1, 2012.
  • How long would be the billing period?

Calculation is made under the following conditions:

  • Billing period type = Monthly on Statement Cycle Date; 1st day of every month.
  • Subscription is charged = Before Subscription Period.

Calculation:

BaseDate - subscription purchase date: May 14, 2012.

BaseMonth - base month: May.

FromDate - resource purchase date: June 1, 2012.

ToDate - resource detail end date: June 30, 2012 (PBA will perform calculatios as July 1, 2012 00:00:00h).

DateDiffInMonths - difference in months: (July - June ) = (7 - 6) = 1 months.

IntermediateDate - intermediate date: June 1, 2012 + 1 months = July 1, 2012.

DaysInMonths - number of days in 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 - 1)/31 = 0/31 =0

DiffInMonths - duration of the period we calculate: the sum DateDiffInMonth + FractMonthDiff:

1 + 0 = 1

So the customer should be billed for the period of 1 month.

Example 5

  • A customer purchases additional resource for subscription for the pperiod on February 28 (end of month) for 1 month.
  • How long would be the billing period?

Calculation is made under the following conditions:

  • Billing period type = Monthly on Statement Cycle Date; 1st day of every month.
  • Subscription is charged = Before Subscription Period.

Calculation:

BaseDate - subscription purchase date: September 29, 2012.

BaseMonth - base month: September.

FromDate - resource purchase date: February 28, 2012.

ToDate - resource detail end date: March 28, 2012 (PBA will take calculations as March 29, 2012 00:00:00h).

DateDiffInMonths - difference in months: (March - February) = (3 - 2) = 1 months.

IntermediateDate - intermediate date: February 28, 2012 + 1 months = March 28, 2012. But according to PBA logic described above ( It also depends on number of days in BaseDate, if it is greater than number of days in current month and if FromDate equals the end of the month then Intermediate date will be corrected so it is day of Intermediate date is the nearest day possible to day of BaseDate.) in this case it will be 29th of March since it is the closest date to the 28th day of month. So intermediate date = March 29, 2012.

DaysInMonths - number of days in base month: since September is the base month, the value is 30 days.

FractMonthDiff - difference in months, fraction.

(day of month from ToDate - day of month from IntermediateDate) / DaysInMonth

(29 - 29)/30 = 0/30 =0

DiffInMonths - duration of the period we calculate: the sum DateDiffInMonth + FractMonthDiff:

1 + 0 = 1

So the customer should be billed for the period of 1 month.

Additional information

The MONTHDIFF_ALG_ORIGINAL algorithm is just one of the algorithms a provider can choose to calculate the number of days to be used for proration. To learn about other algorithms and how to switch between them please refer to https://kb.cloudblue.com/en/116095.

Internal content