Skip to content

Commit

Permalink
Merge pull request Expensify#45798 from Expensify/chirag-freetrial-ti…
Browse files Browse the repository at this point in the history
…me-fix

Freetrial time fix
  • Loading branch information
tgolen authored Jul 22, 2024
2 parents 49a6870 + 1125d74 commit 50bccec
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/libs/SubscriptionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ function calculateRemainingFreeTrialDays(): number {
}

const currentDate = new Date();
const diffInSeconds = differenceInSeconds(parseDate(lastDayFreeTrial, CONST.DATE.FNS_DATE_TIME_FORMAT_STRING, currentDate), currentDate);
const lastDayFreeTrialDate = new Date(`${lastDayFreeTrial}Z`);
const diffInSeconds = differenceInSeconds(lastDayFreeTrialDate, currentDate);
const diffInDays = Math.ceil(diffInSeconds / 86400);

return diffInDays < 0 ? 0 : diffInDays;
Expand All @@ -378,8 +379,10 @@ function isUserOnFreeTrial(): boolean {
}

const currentDate = new Date();
const firstDayFreeTrialDate = parseDate(firstDayFreeTrial, CONST.DATE.FNS_DATE_TIME_FORMAT_STRING, currentDate);
const lastDayFreeTrialDate = parseDate(lastDayFreeTrial, CONST.DATE.FNS_DATE_TIME_FORMAT_STRING, currentDate);

// Free Trials are stored in UTC so the below code will convert the provided UTC datetime to local time
const firstDayFreeTrialDate = new Date(`${firstDayFreeTrial}Z`);
const lastDayFreeTrialDate = new Date(`${lastDayFreeTrial}Z`);

return isAfter(currentDate, firstDayFreeTrialDate) && isBefore(currentDate, lastDayFreeTrialDate);
}
Expand Down

0 comments on commit 50bccec

Please sign in to comment.