Skip to content

Commit

Permalink
fix: Remove trial logic using moment-timezone in B2C Subs Programs (#…
Browse files Browse the repository at this point in the history
…34939)

REV-4067
  • Loading branch information
julianajlk committed Jun 12, 2024
1 parent 5a9c383 commit 66fa388
Showing 1 changed file with 5 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ class ProgramSubscriptionModel extends Backbone.Model {
} = context;

const priceInUSD = subscription_prices?.find(({ currency }) => currency === 'USD');
const trialMoment = DateUtils.localizeTime(
DateUtils.stringToMoment(data.trial_end),
'UTC'
);

const subscriptionState = data.subscription_state?.toLowerCase() ?? '';
const subscriptionPrice = StringUtils.interpolate(
Expand All @@ -38,24 +34,15 @@ class ProgramSubscriptionModel extends Backbone.Model {
? urls.manage_subscription_url
: urls.buy_subscription_url;

const hasActiveTrial =
subscriptionState === 'active' && data.trial_end
? trialMoment.isAfter(moment.utc())
: false;
const hasActiveTrial = false;

const remainingDays = ProgramSubscriptionModel.getRemainingDays(
data.trial_end,
userPreferences
);
const remainingDays = 0;

const [currentPeriodEnd] = ProgramSubscriptionModel.formatDate(
data.current_period_end,
userPreferences
);
const [trialEndDate, trialEndTime] = ProgramSubscriptionModel.formatDate(
data.trial_end,
userPreferences
);
const [trialEndDate, trialEndTime] = ['', ''];

super(
{
Expand All @@ -79,7 +66,7 @@ class ProgramSubscriptionModel extends Backbone.Model {
}

const userTimezone = (
userPreferences.time_zone || moment.tz.guess() || 'UTC'
userPreferences.time_zone || moment?.tz?.guess?.() || 'UTC'
);
const userLanguage = userPreferences['pref-lang'] || 'en';
const context = {
Expand All @@ -90,37 +77,10 @@ class ProgramSubscriptionModel extends Backbone.Model {
};

const localDate = DateUtils.localize(context);
const localTime = DateUtils.localizeTime(
DateUtils.stringToMoment(date),
userTimezone
).format('HH:mm (z)');
const localTime = '';

return [localDate, localTime];
}

static getRemainingDays(trialEndDate, userPreferences) {
if (!trialEndDate) {
return 0;
}

const userTimezone = (
userPreferences.time_zone || moment.tz.guess() || 'UTC'
);
const trialEndTime = DateUtils.localizeTime(
DateUtils.stringToMoment(trialEndDate),
userTimezone
);
const currentTime = DateUtils.localizeTime(
moment.utc(),
userTimezone
);

return trialEndTime.diff(currentTime, 'days') < 1
? // 0 if trial end time is less than 24 hrs
0
: // else return actual difference in days
trialEndTime.startOf('day').diff(currentTime.startOf('day'), 'days');
}
}

export default ProgramSubscriptionModel;

0 comments on commit 66fa388

Please sign in to comment.