Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ import type {OnyxCollection, OnyxCollectionInputValue, OnyxEntry, OnyxUpdate} fr
import type {TupleToUnion, ValueOf} from 'type-fest';

/* eslint-disable max-lines */
import {formatInTimeZone} from 'date-fns-tz';
import {addDays} from 'date-fns/addDays';
import {formatDate} from 'date-fns/format';
import {subMinutes} from 'date-fns/subMinutes';
import {PUBLIC_DOMAINS_SET, Str} from 'expensify-common';
import Onyx from 'react-native-onyx';
Expand Down Expand Up @@ -5888,8 +5888,9 @@ function upgradeSubmit(
type UpgradeSubmitOnyxKey = typeof ONYXKEYS.COLLECTION.POLICY | typeof ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL | typeof ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL;

const now = new Date();
const optimisticFirstDayFreeTrial = formatDate(subMinutes(now, 1), CONST.DATE.FNS_DATE_TIME_FORMAT_STRING);
const optimisticLastDayFreeTrial = formatDate(addDays(now, 30), CONST.DATE.FNS_DATE_TIME_FORMAT_STRING);
// Match the backend's UTC DB timestamp format for optimistic trial dates.
const optimisticFirstDayFreeTrial = formatInTimeZone(subMinutes(now, 1), 'UTC', CONST.DATE.FNS_DATE_TIME_FORMAT_STRING);
const optimisticLastDayFreeTrial = formatInTimeZone(addDays(now, 30), 'UTC', CONST.DATE.FNS_DATE_TIME_FORMAT_STRING);

const policyID = policy?.id ?? CONST.POLICY.ID_FAKE;
const currentUserLogin = currentUserEmail ?? '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import CONST from '@src/CONST';

import {fromZonedTime} from 'date-fns-tz';

const SIXTY_DAYS_MS = 60 * CONST.DATE.SECONDS_PER_DAY * CONST.MILLISECONDS_PER_SECOND;

/**
Expand All @@ -11,7 +13,12 @@ function isWithinGettingStartedPeriod(firstDayFreeTrial: string | undefined): bo
return false;
}

const trialStartMs = new Date(firstDayFreeTrial).getTime();
// Trial dates are UTC DB timestamps without a timezone suffix, so parse them as UTC.
const trialStartMs = fromZonedTime(firstDayFreeTrial, 'UTC').getTime();
Comment thread
inimaga marked this conversation as resolved.
if (Number.isNaN(trialStartMs)) {
return false;
}

const elapsed = Date.now() - trialStartMs;
return elapsed >= 0 && elapsed <= SIXTY_DAYS_MS;
}
Expand Down
Loading