mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix(subscriptions): better next-hourglass logic
This commit is contained in:
@@ -8,6 +8,7 @@ import defaults from 'lodash/defaults';
|
|||||||
import invert from 'lodash/invert';
|
import invert from 'lodash/invert';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import 'moment-recur';
|
import 'moment-recur';
|
||||||
|
import subscriptionBlocks from './content/subscriptionBlocks';
|
||||||
|
|
||||||
export const DAY_MAPPING = {
|
export const DAY_MAPPING = {
|
||||||
0: 'su',
|
0: 'su',
|
||||||
@@ -286,7 +287,13 @@ export function getPlanContext (user, now) {
|
|||||||
const dateUpdatedMoment = moment(plan.dateUpdated).startOf('month');
|
const dateUpdatedMoment = moment(plan.dateUpdated).startOf('month');
|
||||||
const elapsedMonths = moment(subscriptionEndDate).diff(dateUpdatedMoment, 'months');
|
const elapsedMonths = moment(subscriptionEndDate).diff(dateUpdatedMoment, 'months');
|
||||||
|
|
||||||
const monthsTillNextHourglass = plan.consecutive.offset || (3 - (plan.consecutive.count % 3));
|
const planMonths = subscriptionBlocks[plan.planId].months || 1;
|
||||||
|
let monthsTillNextHourglass;
|
||||||
|
if (planMonths > 1) {
|
||||||
|
monthsTillNextHourglass = plan.consecutive.offset + 1;
|
||||||
|
} else {
|
||||||
|
monthsTillNextHourglass = 3 - (plan.consecutive.count % 3);
|
||||||
|
}
|
||||||
|
|
||||||
const possibleNextHourglassDate = moment(plan.dateUpdated)
|
const possibleNextHourglassDate = moment(plan.dateUpdated)
|
||||||
.add(monthsTillNextHourglass, 'months');
|
.add(monthsTillNextHourglass, 'months');
|
||||||
|
|||||||
Reference in New Issue
Block a user