-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: moment deprecated date formatting #102413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
|
@sentry review |
| organization, | ||
| daysToSnooze: | ||
| -1 * | ||
| getDaysSinceDate( | ||
| subscription?.onDemandPeriodEnd ?? moment().utc().toDate().toDateString() | ||
| ), | ||
| getDaysSinceDate(subscription?.onDemandPeriodEnd ?? moment().utc().toISOString()), | ||
| isDismissed: isSnoozedForCurrentPeriod, | ||
| options: { | ||
| enabled: promptsToCheck.length > 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: localStorage.setItem at navBillingStatus.tsx:289 writes a deprecated date format, causing getDaysSinceDate to receive an invalid input.
Severity: HIGH | Confidence: 1.00
🔍 Detailed Analysis
The code at navBillingStatus.tsx:289 stores a date in localStorage using moment().utc().toDate().toDateString(), which generates a deprecated date format. This value is subsequently retrieved and passed to getDaysSinceDate() at line 277. Despite a fix for another instance, this specific localStorage write was not updated, causing getDaysSinceDate() to consistently receive the deprecated format and trigger deprecation warnings.
💡 Suggested Fix
Update the localStorage.setItem call at navBillingStatus.tsx:289 to store the date in ISO format using moment().utc().toISOString().
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: static/gsApp/components/navBillingStatus.tsx#L210-L216
Potential issue: The code at `navBillingStatus.tsx:289` stores a date in `localStorage`
using `moment().utc().toDate().toDateString()`, which generates a deprecated date
format. This value is subsequently retrieved and passed to `getDaysSinceDate()` at line
277. Despite a fix for another instance, this specific `localStorage` write was not
updated, causing `getDaysSinceDate()` to consistently receive the deprecated format and
trigger deprecation warnings.
Did we get this right? 👍 / 👎 to inform future reviews.
| getDaysSinceDate(subscription?.onDemandPeriodEnd ?? moment().utc().toISOString()), | ||
| isDismissed: isSnoozedForCurrentPeriod, | ||
| options: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback parameter passed to getDaysSinceDate has been changed to use ISO format (toISOString()), which is good practice and is now tested. However, there is an inconsistency: on line 245, the date is still being stored in localStorage using the deprecated toDateString() format ('Mon Jun 06 2022'). This means when lastShownDate is retrieved from localStorage and passed to getDaysSinceDate() on line 231, it will be in the old format. While getDaysSinceDate() appears to support both formats (as verified by the new tests), it would be more consistent and future-proof to also update line 245 to store dates in ISO format using moment().utc().toISOString() instead of moment().utc().toDate().toDateString().
Severity: MEDIUM
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: static/gsApp/components/navBillingStatus.tsx#L213-L215
Potential issue: The fallback parameter passed to getDaysSinceDate has been changed to
use ISO format (toISOString()), which is good practice and is now tested. However, there
is an inconsistency: on line 245, the date is still being stored in localStorage using
the deprecated toDateString() format ('Mon Jun 06 2022'). This means when lastShownDate
is retrieved from localStorage and passed to getDaysSinceDate() on line 231, it will be
in the old format. While getDaysSinceDate() appears to support both formats (as verified
by the new tests), it would be more consistent and future-proof to also update line 245
to store dates in ISO format using moment().utc().toISOString() instead of
moment().utc().toDate().toDateString().
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the localStorage to use ISO string as well. When reading from local storage, we parse the date with moment(), so it will remain compatible with both formats.
❌ 4 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
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.
This fixes the following console.warn that we are getting in prod:
We were passing a deprecated date format to
getDaysSinceDate():moment().utc().toDate().toDateString(). I have replaced it with an ISO date string.