Skip to content

Commit 153c521

Browse files
billyvgshashjar
authored andcommitted
fix: moment deprecated date formatting (#102413)
This fixes the following console.warn that we are getting in prod: ``` Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info. Arguments: ``` We were passing a deprecated date format to `getDaysSinceDate()`: `moment().utc().toDate().toDateString()`. I have replaced it with an ISO date string.
1 parent 8f80f4c commit 153c521

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

static/app/utils/getDaysSinceDate.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@ describe('getDaysSinceDate', () => {
1414
it('simple test', () => {
1515
expect(getDaysSinceDate('2022-05-11')).toBe(26);
1616
});
17+
it('deprecated date format', () => {
18+
expect(getDaysSinceDate('Thu May 11 2022')).toBe(26);
19+
});
20+
it('iso string', () => {
21+
expect(getDaysSinceDate('2022-05-11T17:19:18.307Z')).toBe(26);
22+
});
23+
it('iso string 23:59', () => {
24+
expect(getDaysSinceDate('2022-05-11T23:59:59.900Z')).toBe(26);
25+
});
26+
it('iso string 00:00', () => {
27+
expect(getDaysSinceDate('2022-05-11T00:00:00.100Z')).toBe(26);
28+
});
1729
});

static/gsApp/components/navBillingStatus.spec.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('PrimaryNavigationQuotaExceeded', () => {
8383
);
8484
localStorage.setItem(
8585
`billing-status-last-shown-date-${organization.id}`,
86-
'Mon Jun 06 2022' // MOCK_TODAY
86+
'2022-06-06T05:09:33.000Z' // MOCK_TODAY
8787
);
8888
});
8989

@@ -97,7 +97,7 @@ describe('PrimaryNavigationQuotaExceeded', () => {
9797
).toBe('errors-replays-spans-profileDuration');
9898
expect(
9999
localStorage.getItem(`billing-status-last-shown-date-${organization.id}`)
100-
).toBe('Mon Jun 06 2022');
100+
).toBe('2022-06-06T05:09:33.000Z');
101101
}
102102

103103
it('should render for multiple categories', async () => {
@@ -399,7 +399,7 @@ describe('PrimaryNavigationQuotaExceeded', () => {
399399
assertLocalStorageStateAfterAutoOpen();
400400
});
401401

402-
it('should auto open the alert when more than a day has passed', async () => {
402+
it('should auto open the alert when more than a day has passed (deprecated date format)', async () => {
403403
localStorage.setItem(
404404
`billing-status-last-shown-date-${organization.id}`,
405405
'Sun Jun 05 2022'
@@ -409,7 +409,7 @@ describe('PrimaryNavigationQuotaExceeded', () => {
409409
assertLocalStorageStateAfterAutoOpen();
410410
});
411411

412-
it('should auto open the alert when the last shown date is before the current usage cycle started', async () => {
412+
it('should auto open the alert when the last shown date is before the current usage cycle started (deprecated date format)', async () => {
413413
localStorage.setItem(
414414
`billing-status-last-shown-date-${organization.id}`,
415415
'Sun May 29 2022'
@@ -418,4 +418,24 @@ describe('PrimaryNavigationQuotaExceeded', () => {
418418
expect(await screen.findByText('Quotas Exceeded')).toBeInTheDocument();
419419
assertLocalStorageStateAfterAutoOpen();
420420
});
421+
422+
it('should auto open the alert when more than a day has passed (ISO date format)', async () => {
423+
localStorage.setItem(
424+
`billing-status-last-shown-date-${organization.id}`,
425+
'2022-06-05T15:00:32.000Z'
426+
); // more than a day, so alert should show even though categories haven't changed
427+
render(<PrimaryNavigationQuotaExceeded organization={organization} />);
428+
expect(await screen.findByText('Quotas Exceeded')).toBeInTheDocument();
429+
assertLocalStorageStateAfterAutoOpen();
430+
});
431+
432+
it('should auto open the alert when the last shown date is before the current usage cycle started (ISO date format))', async () => {
433+
localStorage.setItem(
434+
`billing-status-last-shown-date-${organization.id}`,
435+
'2022-05-29T05:09:33.000Z'
436+
); // last seen before current usage cycle started, so alert should show even though categories haven't changed
437+
render(<PrimaryNavigationQuotaExceeded organization={organization} />);
438+
expect(await screen.findByText('Quotas Exceeded')).toBeInTheDocument();
439+
assertLocalStorageStateAfterAutoOpen();
440+
});
421441
});

static/gsApp/components/navBillingStatus.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ function PrimaryNavigationQuotaExceeded({organization}: {organization: Organizat
210210
organization,
211211
daysToSnooze:
212212
-1 *
213-
getDaysSinceDate(
214-
subscription?.onDemandPeriodEnd ?? moment().utc().toDate().toDateString()
215-
),
213+
getDaysSinceDate(subscription?.onDemandPeriodEnd ?? moment().utc().toISOString()),
216214
isDismissed: isSnoozedForCurrentPeriod,
217215
options: {
218216
enabled: promptsToCheck.length > 0,
@@ -262,7 +260,7 @@ function PrimaryNavigationQuotaExceeded({organization}: {organization: Organizat
262260
);
263261
localStorage.setItem(
264262
`billing-status-last-shown-date-${organization.id}`,
265-
moment().utc().toDate().toDateString()
263+
moment().utc().toISOString()
266264
);
267265
}
268266
}, [

0 commit comments

Comments
 (0)