Skip to content

Commit debf40e

Browse files
committed
Use ISO timestamp
1 parent 3b4af71 commit debf40e

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/CONST.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ const CONST = {
18061806
XERO_CHECK_CONNECTION: 'xeroCheckConnection',
18071807
XERO_SYNC_TITLE: 'xeroSyncTitle',
18081808
},
1809-
SYNC_STAGE_TIMEOUT: 1_200_000, // 20 minutes (20m * 60s * 1000ms)
1809+
SYNC_STAGE_TIMEOUT_MINUTES: 20,
18101810
},
18111811
ACCESS_VARIANTS: {
18121812
PAID: 'paid',

src/libs/actions/connections/QuickBooksOnline.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function syncConnection(policyID: string) {
2121
value: {
2222
stageInProgress: CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.STARTING_IMPORT,
2323
connectionName: CONST.POLICY.CONNECTIONS.NAME.QBO,
24-
timestamp: Date.now(),
24+
timestamp: new Date().toISOString(),
2525
},
2626
},
2727
];

src/pages/workspace/accounting/PolicyAccountingPage.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type {Policy, PolicyConnectionSyncProgress} from '@src/types/onyx';
3939
import type {PolicyConnectionName} from '@src/types/onyx/Policy';
4040
import {isEmptyObject} from '@src/types/utils/EmptyObject';
4141
import type IconAsset from '@src/types/utils/IconAsset';
42+
import {differenceInMinutes, parseISO, isValid} from "date-fns";
4243

4344
type PolicyAccountingPageOnyxProps = {
4445
connectionSyncProgress: OnyxEntry<PolicyConnectionSyncProgress>;
@@ -112,10 +113,11 @@ function PolicyAccountingPage({policy, connectionSyncProgress, isConnectionDataF
112113
const [isDisconnectModalOpen, setIsDisconnectModalOpen] = useState(false);
113114
const threeDotsMenuContainerRef = useRef<View>(null);
114115

116+
const lastSyncProgressDate = parseISO(connectionSyncProgress?.timestamp ?? '');
115117
const isSyncInProgress =
116118
!!connectionSyncProgress?.stageInProgress &&
117119
connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE &&
118-
Date.now() - (connectionSyncProgress.timestamp ?? 0) < CONST.POLICY.CONNECTIONS.SYNC_STAGE_TIMEOUT;
120+
(isValid(lastSyncProgressDate) && differenceInMinutes(new Date(), lastSyncProgressDate) < CONST.POLICY.CONNECTIONS.SYNC_STAGE_TIMEOUT_MINUTES);
119121

120122
const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME).filter((name) => !(name === CONST.POLICY.CONNECTIONS.NAME.XERO && !canUseXeroIntegration));
121123
const connectedIntegration = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]) ?? connectionSyncProgress?.connectionName;

src/types/onyx/Policy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ type PolicyConnectionName = ValueOf<typeof CONST.POLICY.CONNECTIONS.NAME>;
545545
type PolicyConnectionSyncProgress = {
546546
stageInProgress: PolicyConnectionSyncStage;
547547
connectionName: PolicyConnectionName;
548-
timestamp: number;
548+
timestamp: string;
549549
};
550550

551551
export default Policy;

0 commit comments

Comments
 (0)